1a Fop
1a Fop
Lecture 1B
Elements of Structured Programming
❑Control statements
• Flow charts
❑Subroutines- a computer program that is stored only once but can be used
when required at several different points in the program, saves space
❑Blocks- used to enable group of statements to be treated as if they were one
statement
2
Flowcharts
❑A graphical representation of the sequence of operations in an
information system or program
❑Information system flowcharts show how data flows from source
documents through the computer to final distribution to users
❑Program flowcharts show the sequence of instructions
3
Flowcharts
Flowchart shows:
❑shows logic of an algorithm
❑emphasizes individual steps and their interconnections
❑control flow from one action to the next
4
Name Symbol Use in Flowchart
Oval Denotes the beginning or end of the program
Parallelogram Denotes an input operation
5
Example 1
Draw a flowchart to add four subjects marks of a student
Solution:
Marks = Maths, English, Physics, Chemistry
Add = Maths + English + Physics + Chemistry
6
Start
Solution X= E,M,P,C
Add = E+M+P+C
Print Add
End
8
Start
X= E,M,P,C
Avg = (E+M+P+C) / 4
Yes
Print Pass if Avg >=50
No
10
Evolution of C++ Language
❑During 1970 Dennis Ritchie created C programming language to
develop the UNIX operating system at Bell Labs
❑C was first implemented in 1972
❑C++ development started in 1979
❑Bjarne Stroustrup developed C++ during his PhD
❑C++ is derived from C
❑C++ was called C with classes
❑C++ supports Object Oriented approach
11
C++ Standard Library
❑Collection of classes and functions
❑Avoid reinventing the wheel
❑If a premade function exists, use it rather than writing your own
program
12
Basics of C++ Environment
❑Edit- program is written using editor and stored on disk (.cpp file)
❑Preprocessor- pre process the code before compilation
❑Compiler- creates an object code and stores it on disk(.o file)
❑Linker- links the object code with the libraries, creates an
executable file and stores it on disk
❑Load- puts the program in memory (RAM)
❑Execute- CPU takes each instruction and executes it
13
14
C++ Program
15
Explanation of C++ Program
16
Books Used to Create Slides
17