




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Objective of this cours is to develop effective computer programming skills in solving complex problems and to learn adequate and operational software organization in developing real life engineering solutions using powerful object oriented paradigm of the language. It includes: Object, Oriented, Programming, Namespace, Identifies, Library, Parenthesis, Function, Compiler, Text, String, Constant
Typology: Slides
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Usman Younis
Namespace identifies the part of a program in which certain names are recognized, std namespace includes all entities of standard C++ library Parenthesis follow the function name Function body is surrounded in braces Compiler ignores the whitespaces Text with in “quotation marks” is a string constant \n is an escape sequence (causes following text to be printed in a new line)
Program Basics (contd..)
<< is a left shift bitwise operator!
Program Basics (contd..)
cin serves the similar purpose as scanf () in C cin is also an object in C++ >> is extraction operator
endl manipulator , same as using \n
Arithmetic operators
6 % 8 will result in 6 8 % 8 will result in 0 10 % 8 will result in 2
A = A + B, can be written as A += B Similar applies for: *, −, /, and %
A = A + 1, can be written as A += 1, or simply ++A Remember the prefix (++A) and postfix (A++) precedence. In first the increment is performed before using the variable; andin second, the increment is performed after.
Relational operators
Operator Meaning
Greater than < Less than == Equal to != Not equal to = Greater than or equal to <= Less than or equal to
Usman Younis
Loops
The for loop
Initialization Expression
Body of Loop
Increment Expression
Test Expression Exit
True
False
Loops (contd..)
The while loop
Body of Loop
Test Expression Exit
True
False
Decisions (contd..)
if (condition is true) execute the statement; //single statement else execute this statement; Or if (condition is true) { execute multiple statements; statement ……. 1; statement ……. 2; and so on …. } else { execute multiple statements; }
Body of if
Test Expression
True
False
Body of else
Exit
Decisions (contd..)
if (condition is true) execute the statement; else if (this condition is true) execute this statement; else if (this conditions is true) execute this statement; else execute this statement;
Body of if
Test Expression
True
False
Exit Body of if
Test Expression
True Body of else
False
Remember to match the else with required if. It is a best practice to properly indent your code.
Decisions (contd..)
switch ( integer or character variable ){ case 1: execute statement; execute statement;break; case 2: execute statement; execute statement;break; case 3: execute statement; execute statement;break; .. default: execute statement; } //no break, as it is the only choice left
Switch 1st caseequals
False
True (^) Case Body
Exit
Switch 2nd caseequals False
True (^) Case Body
Default Body
You can use the break statement in a loop as well!
Decisions (contd..)
The conditional operator result = (check a condition)? first expression : second expression; if the condition is true, then first expression is assigned to the result; otherwise, the second expression is assigned e.g., k = ( a < 20)? a : b; (^) Test expression False
Exit
True Value of expression 1 Value of expression 2