SlideServe
Menu
Préférences
© SlideServe · v2026

Programming Fundamentals

reginald-ethelbert avatar
61 diapositives · 778 Views · Oct 31, 2014

Programming Fundamentals. Lecture 5. In the Previous Lecture. Basic structure of C program Variables and Data types Operators ‘ cout ’ and ‘ cin ’ for output and input Braces. Relational Operators. Decision. If Statement. If condition is true statements

Programming Fundamentals - slide 1
01 / 61Programming Fundamentals
1 / 17

Télécharger la présentation

Programming Fundamentals
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Programming Fundamentals Lecture 5

  2. In the Previous Lecture • Basic structure of C program • Variables and Data types • Operators • ‘cout’ and ‘cin’ for output and input • Braces

  3. Relational Operators

  4. Decision

  5. If Statement If condition is true statements If Ali’s height is greater then 6 feet Then Ali can become a member of the Basket Ball team

  6. If Statement in C If (condition) statement ;

  7. If Statement in C If ( condition ) { statement1 ; statement2 ; : }

  8. If statement in C

  9. Int n; • Cin>>n; • If(n>10) • { • Cout<<“uol”; • Cout<<“ok”; • }

  10. Add two num..r they equal to five??

  11. Divisible by 3 • Int n; • Cout<<“enter any number”; • Cin>>; • If(n%3==0) • { • Cout<<“the number”<<n<<“is divisible by 3”; • }

  12. If-else statement • Used for making two way decsns(need?) • One condition and two blocks of statements are given • After evaluating a condition, one of the block will be executed • If condition is true than the first block will be executed • If condition is false than the second block will be executed

  13. if-else if (condition) { statement ; - - } else { statement ; - - }

  14. <100 or >100 • Int n; • Cout<<“enter any integer value”; • Cin>>n; • If(n>100) • Cout<<“>100”; • Else • Cout<<“<100”;

  15. Even or odd • Int n; • Cout<<“enter an integer”; • Cin>>n; • If(n%2==1) • Cout<<“it is an odd number”; • Else • Cout<<“even”;

  16. Take avg of 5 students marks and tell if that avg is > or < 100

  17. Nested if statement When an if statement is used within another if statement , it is called nested if statement Used for multiway (not two way) decision making

  18. Syntax If(condition-1) { If (condition-2) { Statement } Statement }

  19. example Inta,b,c; Cout Cin>>a Cout Cin>>b; Cout Cin>>c; If(a==b) { if(a==c) cout<<“equal”; } Else Cout<<“different”; }

  20. Nested if-else structure Used for multiple selection Syntax If(condition1) Statement1; Else if(condition2) Statement2; Else if(condition3) Statement3… . .. .

  21. Logical Operators AND && OR ||

  22. Logical Operators If a is greater than b AND c is greater than d In C if(a > b && c> d) if(age > 18 || height > 5)

  23. Multi-way decision

  24. if Statements if ( grade ==‘A’ ) cout << “ Excellent ” ; if ( grade ==‘B’ ) cout << “ Very Good ” ; if ( grade ==‘C’ ) cout << “ Good ” ; if ( grade ==‘D’ ) cout << “ Poor ” ; if ( grade ==‘F’ ) cout << “ Fail ” ;

  25. if else if ( grade ==‘A’ ) cout << “ Excellent ” ; else if ( grade ==‘B’ ) cout << “ Very Good ” ; else if ( grade ==‘C’ ) cout << “ Good ” ; else if ( grade ==‘D’ ) cout << “ Poor ” ;

  26. if else if ( grade == ‘A’ ) cout << “ Excellent ” ; else if ( grade == ‘B’ ) … else if … … else …

  27. switch statement

  28. switch statements switch ( variable name ){ case ‘a’ : statements; case ‘b’ : statements; case ‘c’ : statements; …}

  29. switch statements switch ( grade){ case ‘A’ : cout << “ Excellent ” ; case ‘B’ : cout << “ Very Good ” ; case ‘C’ : … …}

  30. switch statements case ‘A’ : cout << “ Excellent ” ; … …

  31. Example switch ( grade) { case ‘A’ : cout << “ Excellent ” ; case ‘B’ : cout << “ Very Good ” ; case ‘C’ : cout << “Good ” ; case ‘D’ : cout << “ Poor ” ; case ‘F’ : cout << “ Fail ” ; }

  32. break;

  33. Example switch ( grade ) { case ‘A’ : cout << “ Excellent ” ; break ; case ‘B’ : cout << “ Very Good ” ; break ; case ‘C’ : cout << “Good ” ; break ; case ‘D’ : cout << “ Poor ” ; break ; case ‘F’ : cout << “ Fail ” ; break ; }

  34. default : default : cout << “ Please Enter Grade from ‘A’ to ‘D’ or ‘F’ “ ;

  35. GOTO { Int c=1; abc: Cout<<c<<endl; C++; If(c<=10) Gotoabc; }

  36. Flow Chart of switch statement switch (grade) case ‘A’ : Display “Excellent” case ‘B’ : Display “Very Good” … Default : “……..”

  37. Limitations of switch if ( amount > 2335.09 ) statements ;

  38. Whole Number • short • int • long

  39. case ‘A’ : case ‘ 300 ‘ : case ‘ f ‘ :

  40. break ; if (c == ‘z’ ) { cout << “ Great ! You have made the correct guess “ ;break ; }

  41. continue ;