SlideShare a Scribd company logo
DECISION MAKING IN
C++
C++ switch statement
• A switch statement allows a variable to be tested for equality against a
list of values.
• Each value is called a case, and the variable being switched on is
checked for each case.
C++ switch statement
◦ Syntax
◦ switch(expression)
◦ { case constant-expression : statement(s); break; //optional case
case constant-expression : statement(s); break; //optional
◦ // you can have any number of case statements.
◦ default : //Optional statement(s);
◦ }
C++ switch statement
◦ The following rules apply to a switch statement:
1. The expression used in a switch statement must have an integral or
character.
2. You can have any number of case statements within a switch. Each
case is followed by the value to be compared to and a colon.
3. The constant-expression for a case must be the same data type as the
variable in the switch, and it must be a constant or a literal.
4. When the variable being switched on is equal to a case, the
statements following that case will execute until a break statement is
reached.
C++ switch statement
5. When a break statement is reached, the switch terminates, and the
flow of control jumps to the next line following the switch statement.
6. Not every case needs to contain a break. If no break appears, the flow
of control will fall through to subsequent cases until a break is
reached.
7. A switch statement can have an optional default case, which must
appear at the end of the switch. The default case can be used for
performing a task when none of the cases is true. No break is needed
in the default case.
Flow Diagram
Example
◦ #include <iostream> using
namespace std; int main ()
◦ { // local variable declaration:
◦ char grade = 'D';
switch(grade)
◦ { case 'A' : cout <<
"Excellent!" << endl; break;
◦ case 'B' : cout << “Very
Good!" << endl; break;
◦ case 'C' : cout << "Well
done" << endl; break;
◦ case 'D' : cout << "You
passed" << endl; break;
◦ case 'F' : cout << "Better try
again" << endl; break;
◦ default : cout << "Invalid
grade" << endl; }
◦ cout << "Your grade is " <<
grade << endl;
◦ return 0; }
Nested if Statements
◦ Syntax
◦ The syntax for a nested if statement is as follows:
◦ if( boolean_expression 1)
◦ { // Executes when the boolean expression 1 is true
◦ if(boolean_expression 2)
◦ { // Executes when the boolean expression 2 is true }
◦ }
Example
◦ #include <iostream>
◦ using namespace std;
◦ int main ()
◦ { // local variable declaration:
◦ int a = 100;
◦ int b = 200;
◦ // check the boolean
condition
◦ if( a == 100 )
◦ { // if condition is true then
check the following
◦ if( b == 200 ) {
◦ // if condition is true then print
the following
◦ cout << "Value of a is 100 and b
is 200" << endl;
◦ } }
◦ cout << "Exact value of a is : "
<< a << endl;
◦ cout << "Exact value of b is : "
<< b << endl;
◦ return 0; }
exercise
1. Write a menu driven C++ Program to Make a Simple Calculator to
Add, Subtract, Multiply or Divide Using switch...case.
2. Write a program that will ask number of the month as input and print
the number of the days in that month.
3. Write a program that presents the user with a choice of your 5
favorite beverages (Coke, Water, Sprite, ... , Whatever).
Then allow the user to choose a beverage by entering a number 1-5.
Output which beverage they chose with price.
4. Modify the program so that if the user enters a choice other than 1-5
then it will output "Error. choice was not valid, here is your money
back."
exercise
5. Write a C++ program to find whether a given year is a leap year or
not.
6. Write a C++ program to accept a coordinate point in a XY coordinate
system and determine in which quadrant the coordinate point lies.
7. Write a C++ program to find the eligibility of admission for a
professional course based on the following criteria:
Marks in Maths >=65
Marks in Phy >=55
Marks in Chem>=50
Total in all three subject >=180
or
Total in Math and Subjects >=140
exercise
8. Write a program in C++ which is a Menu-Driven Program to compute
the area of the various geometrical shape. (e.g. circle, triangle,
rectangle)
9. Write a C++ program to check whether a character is an alphabet,
digit or special character.
10. Write a program in C++ to calculate and print the Electricity bill of a
given customer. The customer id., name and unit consumed by the
user should be taken from the keyboard and display the total amount
to pay to the customer. The charge are as follow :
exercise
◦ If bill exceeds Rs. 400 then a additional charge of 15% will be charged
and the minimum bill should be of Rs. 100/-
Unit Charge/unit
upto 199 @1.20
200 and above but
less than 400
@1.50
400 and above but
less than 600
@1.80
600 and above @2.00

More Related Content

Similar to Switch.pptx

Control structure
Control structureControl structure
Control structure
Samsil Arefin
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
Anil Dutt
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
C Programming Lesson 3.pdf
C Programming Lesson 3.pdfC Programming Lesson 3.pdf
C Programming Lesson 3.pdf
Rajeev Mishra
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
TAlha MAlik
 
Lecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptLecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.ppt
MaiGaafar
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2
Ammara Javed
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
sanjay
 
Control All
Control AllControl All
Control All
phanleson
 
Decision Controls in C++ Programming Lecture
Decision Controls in C++ Programming LectureDecision Controls in C++ Programming Lecture
Decision Controls in C++ Programming Lecture
TishaFayeMendoza
 
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiM2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
rakshithatan
 
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical OperatorsIntro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Blue Elephant Consulting
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
JavvajiVenkat
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
Praveen M Jigajinni
 
Control structures in C
Control structures in CControl structures in C
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
valerie5142000
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 

Similar to Switch.pptx (20)

Control structure
Control structureControl structure
Control structure
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
C Programming Lesson 3.pdf
C Programming Lesson 3.pdfC Programming Lesson 3.pdf
C Programming Lesson 3.pdf
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
 
Lecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptLecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.ppt
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
Control All
Control AllControl All
Control All
 
Decision Controls in C++ Programming Lecture
Decision Controls in C++ Programming LectureDecision Controls in C++ Programming Lecture
Decision Controls in C++ Programming Lecture
 
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiM2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
 
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical OperatorsIntro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 

Recently uploaded

Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 

Recently uploaded (20)

Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 

Switch.pptx

  • 2.
  • 3. C++ switch statement • A switch statement allows a variable to be tested for equality against a list of values. • Each value is called a case, and the variable being switched on is checked for each case.
  • 4. C++ switch statement ◦ Syntax ◦ switch(expression) ◦ { case constant-expression : statement(s); break; //optional case case constant-expression : statement(s); break; //optional ◦ // you can have any number of case statements. ◦ default : //Optional statement(s); ◦ }
  • 5. C++ switch statement ◦ The following rules apply to a switch statement: 1. The expression used in a switch statement must have an integral or character. 2. You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon. 3. The constant-expression for a case must be the same data type as the variable in the switch, and it must be a constant or a literal. 4. When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.
  • 6. C++ switch statement 5. When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement. 6. Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached. 7. A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.
  • 8. Example ◦ #include <iostream> using namespace std; int main () ◦ { // local variable declaration: ◦ char grade = 'D'; switch(grade) ◦ { case 'A' : cout << "Excellent!" << endl; break; ◦ case 'B' : cout << “Very Good!" << endl; break; ◦ case 'C' : cout << "Well done" << endl; break; ◦ case 'D' : cout << "You passed" << endl; break; ◦ case 'F' : cout << "Better try again" << endl; break; ◦ default : cout << "Invalid grade" << endl; } ◦ cout << "Your grade is " << grade << endl; ◦ return 0; }
  • 9. Nested if Statements ◦ Syntax ◦ The syntax for a nested if statement is as follows: ◦ if( boolean_expression 1) ◦ { // Executes when the boolean expression 1 is true ◦ if(boolean_expression 2) ◦ { // Executes when the boolean expression 2 is true } ◦ }
  • 10. Example ◦ #include <iostream> ◦ using namespace std; ◦ int main () ◦ { // local variable declaration: ◦ int a = 100; ◦ int b = 200; ◦ // check the boolean condition ◦ if( a == 100 ) ◦ { // if condition is true then check the following ◦ if( b == 200 ) { ◦ // if condition is true then print the following ◦ cout << "Value of a is 100 and b is 200" << endl; ◦ } } ◦ cout << "Exact value of a is : " << a << endl; ◦ cout << "Exact value of b is : " << b << endl; ◦ return 0; }
  • 11. exercise 1. Write a menu driven C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch...case. 2. Write a program that will ask number of the month as input and print the number of the days in that month. 3. Write a program that presents the user with a choice of your 5 favorite beverages (Coke, Water, Sprite, ... , Whatever). Then allow the user to choose a beverage by entering a number 1-5. Output which beverage they chose with price. 4. Modify the program so that if the user enters a choice other than 1-5 then it will output "Error. choice was not valid, here is your money back."
  • 12. exercise 5. Write a C++ program to find whether a given year is a leap year or not. 6. Write a C++ program to accept a coordinate point in a XY coordinate system and determine in which quadrant the coordinate point lies. 7. Write a C++ program to find the eligibility of admission for a professional course based on the following criteria: Marks in Maths >=65 Marks in Phy >=55 Marks in Chem>=50 Total in all three subject >=180 or Total in Math and Subjects >=140
  • 13. exercise 8. Write a program in C++ which is a Menu-Driven Program to compute the area of the various geometrical shape. (e.g. circle, triangle, rectangle) 9. Write a C++ program to check whether a character is an alphabet, digit or special character. 10. Write a program in C++ to calculate and print the Electricity bill of a given customer. The customer id., name and unit consumed by the user should be taken from the keyboard and display the total amount to pay to the customer. The charge are as follow :
  • 14. exercise ◦ If bill exceeds Rs. 400 then a additional charge of 15% will be charged and the minimum bill should be of Rs. 100/- Unit Charge/unit upto 199 @1.20 200 and above but less than 400 @1.50 400 and above but less than 600 @1.80 600 and above @2.00

Editor's Notes

  1. Area of circle: 3.14*radius*radius Triangle= .5*base*height Rectangle= length * width