Programming Fundamentals (COMP1112) Selection Structure
Programming Fundamentals (COMP1112) Selection Structure
(COMP1112)
Lecture 4
Selection Structure
Syntax:
if (condition) statement
int a,b,c;
cout<<"Enter the values of a, b and c";
cin>>a>>b>>c;
if( a==b)
if (a==c)
cout<<"\n All numbers are equal";
else
cout<<"\n Numbers are different";
else
cout<<"\n Numbers are different";
Compound condition
• A type of condition in which more than one conditions are checked.
• Implemented using logical operators &&, ||, !
Example:
if(grade==‘A’ || grade==‘a’)
Switch statement
• The switch statement executes one or more of a series of cases, based on the value
of a controlling expression.
Syntax:
switch ( expression )
statement
The Switch statement is typically a compound statement, within which are one or
more case statements executed if the control expression matches the case.
Switch statement (cont..)
The syntax for a case label and expression follows:
case constant-expression :
statement
• Object oriented programming using C++ by Tasleem Mustafa, Imran Saeed, Tariq Mehmood, Ahsan Raza
• https://www.tutorialspoint.com/cplusplus
• http://ecomputernotes.com/cpp/introduction-to-oop
• http://www.cplusplus.com/doc/tutorial
• https://www.w3schools.com/cpp