![Page 1: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/1.jpg)
Programming Fundamentals
Lecture 5
![Page 2: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/2.jpg)
In the Previous Lecture
• Basic structure of C program• Variables and Data types• Operators• ‘cout’ and ‘cin’ for output and input• Braces
![Page 3: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/3.jpg)
Decision
![Page 4: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/4.jpg)
If Statement
If condition is truestatements
If Ali’s height is greater then 6 feetThen
Ali can become a member of the Basket Ball team
![Page 5: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/5.jpg)
If Statement in C
If (condition)statement ;
![Page 6: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/6.jpg)
If Statement in C
If ( condition ){
statement1 ;statement2 ;
:}
![Page 7: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/7.jpg)
If statement in C
![Page 8: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/8.jpg)
Relational Operators
![Page 9: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/9.jpg)
Relational Operators
a != b;
X = 0;X == 0;
![Page 10: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/10.jpg)
Example#include <iostream.h>main ( ) {
int AmirAge, AmaraAge;AmirAge = 0;AmaraAge = 0;
cout<<“Please enter Amir’s age”;cin >> AmirAge;cout<<“Please enter Amara’s age”;cin >> AmaraAge;
if AmirAge > AmaraAge) {
cout << “\n”<< “Amir’s age is greater then Amara’s age” ;}
}
![Page 11: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/11.jpg)
Flow Charting
• There are different techniques that are used to analyse and design a program. We will use the flow chart technique.
• A flow chart is a pictorial representation of a program.
• There are labelled geometrical symbols, together with the arrows connecting one symbol with other.
![Page 12: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/12.jpg)
Flow Chart Symbols
Start or stop
Process
Flow line
Continuation mark
Decision
![Page 13: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/13.jpg)
![Page 14: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/14.jpg)
![Page 15: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/15.jpg)
Example
If the student age is greater than 18 or his height is greater than five feet
then put him on the foot balll teamElse
Put him on the chess team
![Page 16: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/16.jpg)
Logical Operators
AND &&OR ||
![Page 17: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/17.jpg)
Logical OperatorsIf a is greater than b
AND c is greater than d
In Cif(a > b && c> d)if(age > 18 || height > 5)
![Page 18: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/18.jpg)
if-elseif (condition){
statement ;--
}else{
statement ;--
}
![Page 19: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/19.jpg)
Example • Code
• if (AmirAge > AmaraAge) • {• cout<< “Amir is older than Amara” ;• }
• if (AmirAge < AmaraAge) • {• cout<< “Amir is younger than Amara” ;• }
![Page 20: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/20.jpg)
ExampleCode
if AmirAge > AmaraAge) { cout<< “Amir is older than Amara” ;} else { cout<<“Amir is younger than or of the same age as Amara” ;}
![Page 21: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/21.jpg)
![Page 22: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/22.jpg)
![Page 23: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/23.jpg)
![Page 24: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/24.jpg)
Example
If (AmirAge != AmaraAge) cout << “Amir and Amara’s Ages are not equal”;
![Page 25: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/25.jpg)
Unary Not operator !
!true = false !false = true
![Page 26: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/26.jpg)
Exampleif ((interMarks > 45) && (testMarks >= passMarks)){
cout << “ Welcome to Lahore University”;}
![Page 27: Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output](https://reader030.vdocuments.us/reader030/viewer/2022032709/56649ece5503460f94bdaccf/html5/thumbnails/27.jpg)
Nested ifIf (age > 18){
If(height > 5){
:}
}Make a flowchart of this nested if structure…