week 4 Programming lecture 08asfsfsd.pptx

ZainabNoor83 2 views 21 slides Feb 27, 2025
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

zdfasfsdfasdfsdfsf


Slide Content

Programming Lecture 8 Mr. Danial Haider

Agenda of Lecture Flow chart Nested while

Flow Chart Flow chart symbols Processing Symbol: Decision Symbol:

Flow Chart Symbols

Flowchart for average of 3 numbers

Flowchart for average of 3 numbers

Flowchart for the calculating the area

Flowchart for the calculating the area

Flowchart for if else

Nested while loop 11

Nested while loop int i =1; int j=1; int rows=8; while ( i <= rows) { while (j <= i ) { cout <<j; j++ ; } cout <<"\n"; i ++; j = 1; } 12

The getche () Library function Echoes the character on the screen. Returns each character as soon as it is typed. It takes no arguments. Requires conio.h header file 13

The getche () Library function #include< iostream > using namespace std ; int main() { char ch ; cout <<“Want to continue (Press :(y/n)) : ”; cin >> ch ; return 0; } 14 #include< iostream > #include< conio.h > using namespace std ; int main() { char ch ; cout <<“Want to continue (Press :(y/n)) : ”; ch = getche (); return 0; }

int main() { char dir ='a'; int x=10,y=10; cout <<"\ nPress direction key ( n,s,e,w ): "; cin >> dir ; if( dir == 'n') {y--;} else if( dir == 's') {y++;} else if( dir == 'e') {x++;} else if( dir == 'w') {x--;} cout << "\ nYour location is " <<x<<","<<y; return 0; }

The getche () Library function int main() { char dir ='a'; int x=10,y=10; cout <<"Type enter to quit\n"; while( dir != '\r') { cout <<"\ nPress direction key ( n,s,e,w ): "; dir = getche (); if ( dir == 'n') {y--;} else if( dir == 's') {y++;} else if( dir == 'e') {x++;} else if( dir == 'w') {x--;} cout << "\ nYour location is " <<x<<","<<y; } return 0; }

Switch – Activity Write the direction program using switch statement. 17

The getche () Library function – using switch int main() { char dir ='a'; int x=10,y=10; while( dir != '\r') { cout << "\ nYour location is " <<x<<","<<y; cout <<"\ nPress direction key ( n,s,e,w ): "; dir = getche (); switch( dir ) case ‘n’: y--; break; case ‘s’: y++; break; case ‘e’: x++; break; case ‘w’: x--; break; case ‘\r’: cout <<“Exiting\n”; break; default: cout <<“Try Again\n”; } return 0; }

The getche () Library function int main(){ int chcount = 0; int wdcount =1; char ch ='a'; cout << "Enter a new phrase: "; while( ch != '\r' ) { ch = getche (); if ( ch == ' ') wdcount ++; else chcount ++; } cout <<"\ nWOrds =" << wdcount << endl ; cout <<"Letters=" <<( chcount - 1 )<< endl ; return 0; }

The getche () Library function int main() { int chcount = 0; int wdcount =1; char ch ='a'; cout << "Enter a new phrase: "; while(( ch = getche () )= '\r' ) { if ( ch == ' ') wdcount ++; else chcount ++; } cout <<"\ nWOrds =" << wdcount << endl ; cout <<"Letters=" <<( chcount - 1 )<< endl ; return 0; }

Questions??
Tags