0% found this document useful (0 votes)
153 views11 pages

Lecture 2

The document consists of lecture notes on structured programming using C++ by Dr. Samaher Hussein Ali from the University of Babylon. It covers algorithms, flowcharts, and methods for writing algorithms, including pseudo code and flowchart examples. Additionally, it discusses the importance of comments in code and introduces variable types and initialization.

Uploaded by

samaher hussein
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views11 pages

Lecture 2

The document consists of lecture notes on structured programming using C++ by Dr. Samaher Hussein Ali from the University of Babylon. It covers algorithms, flowcharts, and methods for writing algorithms, including pseudo code and flowchart examples. Additionally, it discusses the importance of comments in code and introduces variable types and initialization.

Uploaded by

samaher hussein
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

DepartmentofSoftware

TheUniversityofBabylon

LECTURENOTESONSTRACTUREPROGRAMMING USINGC++LANGUAGE
By Dr.SamaherHusseinAli
CollegeofInformationTechnology,UniversityofBabylon,Iraq Samaher_hussein@yahoo.com

3December2012

Algorithm and Flowchart


Intheperviouslecture,weexplainedthealgorithm ascollectionofstepsrequireto solveproblemanditmusthavethefollowingconditions:(Keepitsimple,Readthe fascinatingmanual,Makeyourdocumentationshortbutsweet,Everysubprogram shoulddosomethingandhidesomething,ProgramdefensivelyandGoodprogram isaprettyprogram) Inaddition,therearethreetypesofmethodstowriteanyalgorithm,themethods include(setofinstructions(i.e.,PseudoCode),FlowchartandWords)

Algorithm

Setof Instructions (pseudocode)

Flowchart

Words

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

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

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

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( ); }

3December2012

SamaherHusseinAli

NotesofLecture2

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

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

Statements

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

Comments
Commentsarepartsofthesourcecodedisregardedbythecompiler.Theysimplydo nothing.Theirpurposeisonlytoallowtheprogrammertoinsertnotesordescriptions embeddedwithinthesourcecode. C++supportstwowaystoinsertcomments: Thefirstofthem,knownaslinecomment,discardseverythingfromwherethepairof slashsigns(//)isfounduptotheendofthatsameline.Thesecondone,knownas blockcomment,discardseverythingbetweenthe/*charactersandthefirst appearanceofthe*/characters,withthepossibilityofincludingmorethanoneline.

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

Variables

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

Variable Types

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

Variable Types

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

Initialisation

3December2012

Dr.SamaherHusseinAli

NotesofLecture2

You might also like