SlideServe
Menu
Préférences
© SlideServe · v2026

Review of Basic Structured Programming

wanda avatar
37 diapositives · 495 Views · Jul 09, 2014

This comprehensive guide covers the fundamental concepts and syntax of basic program construction in C++, including variables, control statements, loops, operators, and functions. Explore key elements essential for programming beginners.

Review of Basic Structured Programming - slide 1
01 / 37Review of Basic Structured Programming
1 / 17

Télécharger la présentation

Review of Basic Structured Programming
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. M. Taimoor Khan taimoorkhan@ciit-attock.edu.pk Review of Basic Structured Programming

  2. Basic Program Construction #include<iostream.h> void main() { //This is my first C++ Program /* This program will display a string message on the screen */ cout << “Hello to C++”; } Header file Preprocessor directives Main method Console output stream Insertion operator String constant or string literal Comments White spaces Program statements

  3. Variables #include<iostream.h> void main() { int var1; int var2, var3; var1 = 5; int var4 = 10; cout << var1 + var4 << endl; } Variable names Type Declaration Initialization Arithmetic's / Comparisons End line manipulator

  4. Local and Global Variables #include<iostream.h> int numb = 15; void main() { int var1; int var2, var3; { intvar 4; intvar 5; } var1 = 5; int var6 = 10; cout << var1 + var4 << endl; }

  5. Static and Constant Variables #include<iostream.h> void main() { int var1; int var2, var3; { static int var4 = 9; } var1 = 5; int var5 = 10; const int var6 = 20; cout << var1 + var4 << endl; }

  6. Other Variables Types • Float • Double • Char • Bool • Short • long

  7. Escape Characters #include<iostream.h> void main() { cout << “ Things are \a getting \n better in \t c++”; } \a beep \b backspace \n new line \t tab \\ \’ \” etc

  8. Input Stream #include<iostream.h> void main() { int score; cout << “Please enter the score value\n”; cin >> score; cout << “Score is: \t” << score; } Extraction operation / get from operator

  9. Type Conversion / Mixed Expression #include<iostream.h> void main() { int height = 7; float length = 4.5; double sum = height + length; }

  10. Type Conversion / Type Casting #include<iostream.h> void main() { int var1 = 5; char var2 = static_cast<char>(var1); } Static_cast<type>(Variable)

  11. Arithmetic Operations #include<iostream.h> void main() { int a = 5; int b = 6; cout << a % b; } +, -, %, * /

  12. Assignment Operators #include<iostream.h> void main() { int a = 5; int b = 6; b += a; cout << a % b; } =, +=, -=, *=, /=

  13. Increment / Decrement Operator #include<iostream.h> void main() { int a = 5; cout << a << endl; cout << a++ << endl; cout << ++a << endl; cout << a-- << endl; cout << --a << endl; } Prefix, postfix

  14. Relational Operators #include<iostream.h> void main() { int a = 5; int b = 6; cout << (a <= b); } <, >, ==, !=, <= >=

  15. Loops • For Loop • While Loop • Do While Loop

  16. For Loop #include<iostream.h> void main() { for(inti = 0; i < 5; i++) cout << i*2; } Declaration and initialization expression Test expression Increment expression

  17. For Loop #include<iostream.h> void main() { int a; for( a =0; a<5; a++) { a = a*2; cout << a; } } Blocks

  18. Nested For Loop #include<iostream.h> void main() { for(inti=0; i<2;i++) { for(int j=0; j<3; j++) cout << i+j<<endl; } }

  19. While Loop #include<iostream.h> void main() { int a = 4; while (a > 1) { cout <<a <<endl; a--; } }

  20. Do-While Loop #include<iostream.h> void main() { int a = 5; do{ cout <<a <<endl; a--; }while(a>2); }

  21. Control / Decision Statements #include<iostream.h> void main() { int a = 5; int b = 6; if(a > b) cout << a % b; } if

  22. If-else statement #include<iostream.h> void main() { int a = 5; int b = 6; if(a > b) cout << a % b; else cout << b % a; }

  23. Nested If-else #include<iostream.h> void main() { int a = 5; int b = 6; if(a < 3) if( a > b) cout << a % b; else cout << b % a; }

  24. Switch Statement #include<iostream.h> void main() { int num; cout << Enter a number <<endl;cin>> marks; switch(marks) { case 0: cout << “low”; break; case 1: cout << “medium”; break; case 2: cout << “high”; break; default: cout << “very high”; } }

  25. Logical Operators #include<iostream.h> void main() { int var1 = 5; int var2 = 6; if(var1>3 && var1>var2) cout << “var1 is a high number” <<endl; } &&, ||, !

  26. Operator Precedence • Unary !, ++, -- • Arithmetic *, /, %, +, - • Relational <,>,<=,>=,==,!= • Logical &&, || • Conditional ?: • Assignment =, +=, -=, *=, /=, %=

  27. Functions #include<iostream.h> void display(); void main() { cout << “main body” <<endl; display(); cout << “main body” <<endl; } void display() { cout << “Display function called” <<endl; } Declaration Definition Calling

  28. Passing variables #include<iostream.h> int sum(intv1, int v2); void main() { int a = 5; int b = 6; cout << sum(a, b); } int sum(int v1, int v2) { int temp = v1 + v2; return temp; } By value Return statement

  29. By Reference #include<iostream.h> int sum(int& v1, int& v2) { return v1 + v2; } void main() { int a = 5; int b = 6; cout << a % b; } Passing objects

  30. Function Overloading #include<iostream.h> int sum(int v1, int v2) { cout << “function 1” <<endl; return v1 + v2; } int sum(int v1, int v2, int v3) { cout << “function 2” <<endl; return v1 + v2 + v3; } float sum (float v1, float v2) { cout << “function 3” <<endl; return v1 + v2; } void main() { int a = 5; int b = 6; int c = 10; float d = 4.5; float e = 6.4; cout << sum(a, b); cout << sum(a, b, c); cout << sum (d, e); }

  31. Recursion #include<iostream.h> Int fact(int n) { if(n > 1) return n * fact(n – 1); else return 1; } void main() { fact(3); }

  32. Inline Function #include<iostream.h> inline intgetTwice(int a) { return a*2; } void main() { cout << getTwice(4); }

  33. Scope of variables • Local Variables • Global Variables • Static Local Variables

  34. Global Variable #include<iostream.h> int a = 5; intsomeFunction() { return a; } void main() { int b = a; cout << a % b; }

  35. Static Local Variables #include<iostream.h> int a = 5; intsomeFunction() { static inthalfValue = a/2; return a; } void main() { int b = a + halfValue; cout << a % b; }

  36. Returning by Reference #include<iostream.h> int& sum(int a, int b) { return a+b; } void main() { int a = 4; int b = 5; sum(a, b); }

  37. Const Function Arguments #include<iostream.h> intsomeFunction(const int b) { if(b < 2) cout << “B < 2” <<endl; } void main() { int b = 5; cout <<someFunction(b); }