1 Programming Basics Ready
-
Upload
naveen-bansal -
Category
Documents
-
view
220 -
download
0
Transcript of 1 Programming Basics Ready
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 1/32
Introducing Programming
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 2/32
Agenda
By the end of this lecture, you should …
Understand the different types ofprogramming languages.
Understand the basic procedures in aprogram as input, processing and output.
Understand the importance of variables.
Understand a basic map of the programdevelopment cycle.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 3/32
Computer Components
CPU Central Processing Unit
RAM (Random Access Memory)
Mass storage devices
Input devices
Output Devices
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 4/32
Storage Units
bit – smallest capacity
nibble = 4 bits
byte = 2 nibbles = 8 bits
storage for one character
1 kilobyte (KB) = 1024 bytes
1 megabyte (MB) = 1024 KB
1 gigabyte (GB) = 1024 MB
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 5/32
Software
Application Software
Word Processors
Database s/w
Spreadsheets
Painting programs
Web browsers, emailprograms
System Software
Operating Systems
Windows
Macintosh OS
Unix
Linux
Drivers
Software is comprised of instructions that get a computer to perform a task.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 6/32
Programming Languages
Programming languages allow programmersto code software.
The three major families of languages are:
Machine languages
Assembly languages
High-Level languages
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 7/32
Machine Languages
Comprised of 1s and 0s
The “native” language of a computer
Difficult to program – one misplaced 1 or 0will cause the program to fail.
Example of code:1110100010101 111010101110
10111010110100 10100011110111
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 8/32
Assembly Languages
Assembly languages are comprised of a setof elemental commands which are tied to aspecific processor.
Assembly language code needs to betranslated to machine language before thecomputer processes it.
Example: ADD 1001010, 1011010
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 9/32
High-Level Languages
High-level languages represent a giant leaptowards easier programming.
The syntax of HL languages is similar to
English.
Historically, we divide HL languages into twogroups:
Procedural languages Object-Oriented languages (OOP)
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 10/32
Procedural Languages
Early high-level languages are typically calledprocedural languages.
Procedural languages are characterized by
sequential sets of linear commands. Thefocus of such languages is on structure .
Examples include C, COBOL, Fortran, LISP,
Perl, HTML, VBScript
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 11/32
Object-Oriented Languages
Most object-oriented languages are high-levellanguages.
The focus of OOP languages is not on
structure, but on modeling data .
Programmers code using “blueprints” of data
models called classes .
Examples of OOP languages include C++,Visual Basic. NET and Java.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 12/32
Compiling
Regardless of the HL Language, all HL programsneed to be translated to machine code so that acomputer can process the program.
Some programs are translated using a compiler.When programs are compiled, they are translated allat once. Compiled programs typically execute morequickly than interpreted programs, but have a slower
translation speed.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 13/32
Interpreting
Some programs are translated using aninterpreter. Such programs are translatedline-by-line instead of all at once (like
compiled programs). Interpreted programsgenerally translate quicker than compiledprograms, but have a slower execution
speed.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 14/32
Programming Example
Simple programming problem: Convert a price from British pounds into Dollars.
PseudocodeInput the price of the item, PoundPrice, in pounds
Compute the price of the item in dollars:
Set DollarPrice = 1.84 * PoundPrice
Write DollarPrice
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 15/32
Programming Example
Translating to Basic:INPUT PoundPrice
LET DollarPrice = 1.62 * PoundPrice
PRINT DollarPrice
END
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 16/32
Input & Variables
Input operations get data into the programs
A user is prompted to enter data:
Write “Enter the price in pounds”
Input PoundPrice
Computer programs store data in named sections ofmemory called variables . In the example above, thevariable is named PoundPrice. The value of a
variable can, and often does, change throughout aprogram.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 17/32
Types of Data
Numeric Data
Integer data, I.e., whole numbers, 10 25 -45 0
Floating point data – have a decimal point 23.0, -
5.0
Character data (alphanumeric)
All the characters you can type at the keyboard
Letters & numbers not used in calculations Boolean data
TRUE/FALSE
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 18/32
Data Processing and Output
Set DollarPrice = 1.62 * PoundPrice
The above statement is a processing statement.Take the value in the variable PoundPrice, multiplyby 1.62, and set the variable DollarPrice to the
result of the multiplication.
Write DollarPrice
Output the value in DollarPrice to the monitor.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 19/32
Hierarchy of Operations Example
Hierarchy of various operations depends upon the operatorprecedence (Priority) and their associatively (direction L to R or R to L).
Example:
3 * (6 + 2) / 12 – (7 – 5) * 3 ( ) first
= 3 * 8 / 12 – 2 * 3 Mult/Div (L to R)
= 24 / 12 –
2* 3 Mult/Div (L to R)= 2 – 6 Add/Subtr (L to R)
= -4
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 20/32
Data Output
Send information from the program to the screen, or
printer, or disk file.
Write DollarPrice
The computer displays the value of the variableDollarPrice to the screen and the cursor goes to
the next line.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 21/32
Data Output
Write “The price in Dollars is”,
DollarPrice
The output looks like this:
The price in Dollars is 162
The text inside the “ ” is output to the user “as is,” and
it is the value in the variable that is output.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 22/32
The Program Development Cycle
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 23/32
Programming as Problem Solving
Problem solvingprinciples:
1. Completely understandthe problem
2. Devise a plan to solve it
3. Carry out the plan
4. Review the results
Developing aProgram:
1. Analyze the problem
2. Design the program
3. Code the program
4. Test the program
5. Maintenance
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 24/32
Modular Programming
Determine the major tasks that the programmust accomplish. Each of these tasks willbe a module.
Some modules will be complex themselves,and they will be broken into sub-modules,and those sub-modules may also be broken
into even smaller modules. This is called top-down design
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 25/32
Mapping Modules
Inputs Processes Outputs
Input Variables:Principal
PercentageRate
Term
Frequency
Rate of Interest:Set Rate =
PercentageRate/100
Display: Write
FinalValue
Final Value:Set FinalValue = Principal *
(1 + Rate / Frequency) ^
(Frequency * Term)
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 26/32
Code Modules
A module is an independent, self-containedsection of code that performs a single task.
The main module is the module that drives
the application. It “controls” all other modules.Typically, the main module calls othermodules in order to have them perform
certain tasks.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 27/32
Program Control & Modules
When the main module calls another module,program control transfers to the calledmodule. Program control get back to the main
module when the called module finishes.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 28/32
Main module
Display program title and brief description of program
Call Input Data Module
Call Perform Calculations module
Call Output Results Module
End Program
Input Data module
Prompt for Principal, PercentageRate, Term, Frequency
Input Principal, PercentageRate, Term, Frequency
End module
Perform Calculations module
Set Rate = PercentageRate / 100
Set FinalValue = Principal * (1 + Rate / Frequency) ^ (Frequency * Term)
End module
Output Results Module
Write Principal, PercentageRate, Term, FrequencyWrite FinalValue
End module
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 29/32
Coding
Coding is done in a specific programminglanguage. In this part of the course, we willuse pseudocode. Later, we’ll adapt our
pseudocode to write in C#. Coding before finishing a solid algorithm is a
lot like putting the cart before the horse and
usually spells disaster. Time well-spent in thedesign phase will head off problems incoding!
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 30/32
Documentation
Internal Documentation
Comments explain to the reader the logic anddecision processes of the programmer.
Comments are ignored by an interpreter orcompiler.
External Documentation
External documentation includes a user’s guide
and, typically, a more technical system administrator’s guide.
8/3/2019 1 Programming Basics Ready
http://slidepdf.com/reader/full/1-programming-basics-ready 31/32
Testing
Most of the work should be done before thephase begins – creating of a testingdocument.
Two types of testing: Testing for errors
Quality/Usability testing
Two phases of testing: Alpha testing (Internal testing)
Beta testing (Testing at the customer site w/ livedata)