Professional Documents
Culture Documents
Computer Programming
Lecture #1
Introduction
Programming
LANGUAGE
Language
• What is a language?
• History of C++
– Extension of C
– Early 1980s: Bjarne Stroustrup (Bell Laboratories)
– “Spruces up” C
– Provides capabilities for object-oriented programming
• Objects: reusable software components
– Model items in real world
• Object-oriented programs
– Easy to understand, correct and modify
– Hybrid language
• C-like style
• Object-oriented style
• Both
• C++ programs
– Built from pieces called classes and functions
• C++ standard library
– Rich collections of existing classes and functions
• “Building block approach” to creating programs
– “Software reuse”
Structured Programming
• Objects
– Reusable software components that model real world items
– Meaningful software units
• Date objects, time objects, paycheck objects, invoice objects,
audio objects, video objects, file objects, record objects, etc.
• Any noun can be represented as an object
– More understandable, better organized and easier to maintain
than procedural programming
– Favor modularity
• Software reuse
– Libraries
• MFC (Microsoft Foundation Classes)
• Rogue Wave
Implementation phase
implement the program in some programming
language
N IS Y
GRADE<5
0
PRINT PRINT
“PASS
” “FAIL”
STOP
Pseudo code:
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying
LFT with 30
Print length in cm (LCM)
30 Input
Lft
Step 3: Print Lcm
Lcm Lft x 30
Lcm
STOP
Pseudocode
Input the width (W) and Length (L) of a
rectangle
Calculate the area (A) by multiplying L
with W
Print A
STAR
T
Step Input W,L
1: A L Input
W,
Step x L
2: W
A LxW
Step Print A
3:
Print
A
STOP
Y N
is
A>B
Print Print
A B
If condition then
true alternative
else
false alternative
endif
ALGORITHM
Input
VALUE1,VAL
UE2
Y is
N
VALUE1>VALUE2
MAX MAX
VALUE1 VALUE2
Print
“The largest value is”,
MAX
STOP
2003 Prentice Hall, Inc. All rights reserved.
NESTED
IFS
One of the alternatives within an IF–THEN–
ELSE statement
may involve further IF–THEN–ELSE statement
• C++ systems
– Program-development environment
– Language
– C++ Standard Library
1. Edit
Disk
processes the code.
Compiler creates
Compiler Disk object code and stores
2. Preprocess it on disk.
3. Compile Primary
creates a.out and
stores it on disk
Memory
Loader
4. Link Loader puts program
in memory.
Disk
5. Load ..
..
..
Primary
6. Execute CPU
Memory
• Input/output
– cin
• Standard input stream
• Normally keyboard
– cout
• Standard output stream
• Normally computer screen
– cerr
• Standard error stream
• Display error messages
• C++ language
– Facilitates structured and disciplined approach to computer
program design
• Following several examples
– Illustrate many important features of C++
– Each analyzed one statement at a time
• Structured programming
• Object-oriented programming