Department of Software

The University of Babylon

LECTURE NOTES ON STRACTURE PROGRAMMING  USING C++ LANGUAGE
By Dr. Samaher Hussein Ali
College of Information Technology, University of Babylon, Iraq Samaher_hussein@yahoo.com

3 December 2012

Algorithm and Flowchart
In the pervious lecture, we explained the algorithm as  collection of steps require to  solve problem and it must have the following conditions:(Keep it simple, Read the  fascinating manual, Make your documentation short but sweet, Every subprogram  should do something and hide something, Program defensively and Good program  is a pretty program)  In addition, there are three types of methods to write any algorithm,  the methods  include(set of instructions(i.e., Pseudo Code), Flowchart and Words)

Algorithm

Set of  Instructions  (pseudo code)

Flowchart

Words

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Algorithm and Flowchart
Example: Write the algorithm to compute the result of the following mathematical expression (R=a*b + c). Let: a and b are two variables from type integer while c is constant (i.e., c=2.1). Solution:  Using the word method
1. 2. 3. 4. 5. 6. 7. Start Read the first number a Read the second number b Assignment value of the third number c Compute the result (i.e., R=a* b +c) Output R End

Using the Flowchart method

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Algorithm and Flowchart
 Using the Pseudo Code (Set of Instructions) Method /* This is the code to calculate the result of mathematical expression */ # include <iostream .h> # include <conio.h> int a; int b; float c; float R; void main( ) { Cout<<“ Input the value of first number a:”<<endl; Cin>>a; Cout<<“ Input the value of second number b:”<<endl; Cin>>b; C=2.1; Cout<<“ what is the result?”<<endl; R=a*b + c; Cout<<“Result=”<<R<<endl; getch( ); }

3 December 2012

Samaher Hussein Ali

Notes of Lecture 2

Example 2: result1=(a*b+c ), result=(result1+2)/d

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Statements

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Comments are parts of the source code disregarded by the compiler. They simply do  nothing. Their purpose is only to allow the programmer to insert notes or descriptions  embedded within the source code. C++ supports two ways to insert comments: The first of them, known as line comment, discards everything from where the pair of  slash signs (//) is found up to the end of that same line. The second one, known as  block comment, discards everything between the /* characters and the first  appearance of the */ characters, with the possibility of including more than one line.

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Variables

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Variable Types

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Variable Types

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2

Initialisation

3 December 2012

Dr. Samaher Hussein Ali

Notes of Lecture 2