Professional Documents
Culture Documents
C++ Program Anatomy
C++ Program Anatomy
C++ Program Anatomy
Program!
1E3!
2 Anatomy of a Program
Objectives!
To understand the role of basic C++
program elements.!
n To provide a skeleton from which to
generate simple programs.!
n To understand how to compile and run
programs.!
!
n Read Chapter 2 of the textbook.!
n
2 Anatomy of a Program
Test on Chapter 1!
Whats secondary storage?!
n Name two input devices.!
n Give an example of a machine language
instruction.!
n A byte is ?!
!
n
2 Anatomy of a Program
D.
An
object
le
A
C++
le
An
assembly
language
le
A
machine
language
le
2 Anatomy of a Program
Programming Environment!
n
n
Terminal utility!
n
make myprog!
n
./myprog!
n
2 Anatomy of a Program
2 Anatomy of a Program
A first program!
n
n
2 Anatomy of a Program
10
2 Anatomy of a Program
11
The computation!
Initialise sum!
For each value of i, from 1!
up to and including n!
adding 1 to i each time!
do this:!
Add the current i
to sum!
2 Anatomy of a Program
12
120
5
0
None
of
these
2 Anatomy of a Program
13
n
n
2 Anatomy of a Program
14
Next!
n
2 Anatomy of a Program
15
2 Anatomy of a Program
Variables!
n
n
n
n
n
17
n
n
n
18
2 Anatomy of a Program
19
n You
20
10
Variable declaration!
n
2 Anatomy of a Program
21
Reading!
n
NB Initialisation!
n
22
11
Assignment!
= is the assignment operator.!
n counter = 0;!
n
n Give
3
7
2 Anatomy of a Program
23
12
Simple problems :!
Read in an amount in pounds and output its
equivalent in euros (1 = 1.27).!
n Read in two numbers, write out their sum, difference
and product.!
n
2 Anatomy of a Program
25
Next !
We cant cover every detail in class.!
n Read Chapter 2 of the textbook.!
n You need to cover, by yourself!
n
n Arithmetic
!
2 Anatomy of a Program
26
13