Question

uestion 1 - Nested selection statements (if/else-switch The Quebec government is trying to crack down on texting and driving. The law is very clear: you must not hold a cell phone in your hand while driving. Failure to abide by this rule is an offence subject toa Write a program that determines the penalty for a driver holding a cell phone while driving based on Nancys Crazy criteria If the driver is driving and holding a cell phone On the highway the fine is $80. If it is the drivers 1st offence s/he gets 1 demerit point otherwise 2 demerit points In a school zone the fine is $100 (the maximum). If the driver has been driving for less than 24 months s/he loose his/her license on the spot otherwise s/he get 4 demerit points (the maximum) If the car is stopped, for example at a stop sign or a traffic light, and the cellphone is an iPhone, the fine is $100 and s/he gets 2 demerit point otherwise the fine is $80 and s/he gets 1 demerit points. (Crazy Nancy does not like iPhones.) All other cases the fine is $90 and the driver gets 3 demerit points After determining where the driver was stopped and what their fine if they have not yet lost their license, ask the user how many demerit points the driver originally had. When a driver has 12 demerit points they lose their license. Determine if the driver should lose their license given where they were when they were holding their cell phone. Output how many demerit points the driver now has Assume you have a perfect user who enters valid input The following are recommended statements for solving this problems: switch, if/else and nested if/else. Here are a few sample outputs to illustrate the expected behavior of your program Weleone to the Fine and Denerit Point Evaluatert er t.cforeteleu vhat the fine and denerit w leone 0fF icer one iafornat lon hefere I tel1 yu what the fine and denerit peinES AP iver ua,stepped the highway Ner stepped a the kigay is stepped at a Stop sign or traffie light ..tepped at ㅿ Stop .ign or traffic light lease enter the digit corresponding to your case Efieer- is this the driver蠱 1st offence <aeruer.vitb lease enter the digit cerrespeading te your eS escer. i. the cellphone in-..tionan iPhone Cansuer with for ye. and anything else for yes and anything else for no), y - ques on efficer1 llou nany deserit points did the driver hav. prior Co belay ast pestion officert Hew nany denerit po ints did the driver have prior to heing stopped >rite a ticket fer $08 and inforn the driver that they nou have 6 denerit points ood jab efficert Crary Naneys tells you to heep up the geod werkt -) uvite a ticket fo『$8 and inform the driver that they hawe 1.denerit points. jeb officert Crazy Hancy te1ls you te heep up the geed vrkttt based on Craay HeasysCriteria oKerrinfornat ion lefere I sel hat the fine and deneri ein iver yas stopped ee the kiuay Car is stepped at a Stop sign or traffie light lease enter the digit carrespending to your cas questian officert Bau nany denerit points did driver have riar t heing steppedT Offic.r. write a ticket far tie take aus, their deǐver. 1&cense and make arrangeest. to have the cap tas e oed jeb off icert Craay Nancytells you to keep up tle seed vorkft1

SIDE NOTE: PLEASE USE C++, thank you in advanced

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <cstdlib>
#include <iostream>
#include<iomanip>

using namespace std;
void display_menu();//prototype to display the menu

int main(int argc, char** argv) {

int choice;//for accepting user choice
  
char offence;//for accepting offence count
int demerit;//for assigning demerits count
int drive_month;//for assigning the driver driving month
char iphone;//for assigning values to the iphone users
  
//do loop is used to perform the operation until the user exit
do{
display_menu();//displays the menu
  
//prompt for user input of choice
cout<<"Please Enter the digit corresponding to your case :";
cin>>choice;
  
//switch case is used to select the option entered by the user
switch(choice){
case 1://if choice is 1
//prompt the user for first time or not
cout<<"Officer, is this the driver's 1st offence (answer with y for yes and anything else for no) :";
cin>>offence;
//if y then demerit is 1 else accept demerit and add the points to it
if((offence=='y')||(offence=='Y')){
demerit= 1;
}
else{
cout<<"Last Question officer! How many demerit points did the driver have prior to being stopped?";
cin>>demerit;
demerit = demerit+2;
}
//display the result
cout<<"Write a ticket for $80 and inform the driver that they now have "<<demerit<<" demerit points."<<endl;
break;
case 2://if the option is 2
cout<<"\nHow many months has the driver been driving?";
cin>>drive_month;
if(drive_month<24){//if driver drives less than 24 the cancel the lisences or demerit the point
cout<<"write a ticket for $100 and take their license"<<endl;
}
else{
cout<<"Last Question officer! How many demerit points did the driver have prior to being stopped?";
cin>>demerit;
demerit = demerit+4;
cout<<"Write a ticket for $100 and inform the driver that they now have "<<demerit<<" demerit points."<<endl;
}
break;
case 3://if the option 3
cout<<"\nOfficer, is the cellphone is iphone(answer with y for yes and anything else for no)?";
cin>>iphone;
int amt;
if((iphone=='y')||(iphone=='Y')){//if the user uses iphone
amt = 100;
cout<<"Officer, is this the driver's 1st offence (answer with y for yes and anything else for no) :";
cin>>offence;
if((offence=='y')||(offence=='Y')){//if the user's offence is first time
demerit= 2;
}
else{//if the user uses iphone and offences not first time then else is performed
cout<<"Last Question officer! How many demerit points did the driver have prior to being stopped?";
cin>>demerit;
demerit = demerit+2;
}
}
else{//if not iphone the else is performed
amt = 80;
cout<<"Officer, is this the driver's 1st offence (answer with y for yes and anything else for no) :";
cin>>offence;
if((offence=='y')||(offence=='Y')){
demerit= 1;
}
else{
cout<<"Last Question officer! How many demerit points did the driver have prior to being stopped?";
cin>>demerit;
demerit = demerit+1;
}
}
cout<<"Write a ticket for $"<<amt<<" and inform the driver that they now have "<<demerit<<" demerit points."<<endl;
break;
case 4://if not all the above three options
amt = 90;
cout<<"Officer, is this the driver's 1st offence(answer with y for yes and anything else for no) :";
cin>>offence;
if((offence=='y')||(offence=='Y'))
demerit= 3;
else{
cout<<"Last Question officer! How many demerit points did the driver have prior to being stopped?";
cin>>demerit;
demerit = demerit+3;
}
cout<<"Write a ticket for $"<<amt<<" and inform the driver that they now have "<<demerit<<" demerit points."<<endl;
break;
case 5://to exit
cout<<"Thank you.!!!";
break;
default://if the user enters other values
cout<<"Officer please choose the correct option(1-4).\n";
  
}
system("PAUSE");
}while(choice!=5);
return 0;
}

void display_menu(){//function for displaying the menu
cout<<"-----------------------------------------------"<<endl;
cout<<"welcome to the fine and demerit point Evaluvater!"<<endl;
cout<<"\tbased on Crazy Nancy Criteria"<<endl;
cout<<"------------------------------------------------"<<endl;
cout<<"Welcome officer- I need some information before i tell you";
cout<<" what the fine and demerit points are.\nHere are the possible locations :"<<endl;
cout<<"\t1. Driver was stopped on the highway."<<endl;
cout<<"\t2. In a School zone."<<endl;
cout<<"\t3. Car is stopper at a stop sign or traffic light."<<endl;
cout<<"\t4. None of the above."<<endl;
cout<<"\t5. Exit."<<endl;

}

Sample Run:

-----------------------------------------------
welcome to the fine and demerit point Evaluvater!
based on Crazy Nancy Criteria
------------------------------------------------
Welcome officer- I need some information before i tell you what the fine and demerit points are.
Here are the possible locations :
1. Driver was stopped on the highway.
2. In a School zone.
3. Car is stopper at a stop sign or traffic light.
4. None of the above.
5. Exit.
Please Enter the digit corresponding to your case :4
Officer, is this the driver's 1st offence(answer with y for yes and anything else for no) :n
Last Question officer! How many demerit points did the driver have prior to being stopped?3
Write a ticket for $90 and inform the driver that they now have 6 demerit points.
Press any key to continue . . .

-----------------------------------------------
welcome to the fine and demerit point Evaluvater!
based on Crazy Nancy Criteria
------------------------------------------------
Welcome officer- I need some information before i tell you what the fine and demerit points are.
Here are the possible locations :
1. Driver was stopped on the highway.
2. In a School zone.
3. Car is stopper at a stop sign or traffic light.
4. None of the above.
5. Exit.
Please Enter the digit corresponding to your case :5
Press any key to continue . . .

Thank you.!!!
RUN SUCCESSFUL (total time: 4m 3s)

Add a comment
Know the answer?
Add Answer to:
SIDE NOTE: PLEASE USE C++, thank you in advanced uestion 1 - Nested selection statements (if/else-switch...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • i really need help with the graphs Driving Can Be Dangerous to Your Health: An Interrupted...

    i really need help with the graphs Driving Can Be Dangerous to Your Health: An Interrupted Case Study in Physiology Phil Stephens Department of Biology Villanova University Part 1-The Grandparents Arrive Dave pulled the cell phone out of his pocket, cursing himself for not putting it on vibrate. The children, Jason and Laura, were both asleep, and he knew that the rest of the day would not be fun if they were awakened from their naps. "Hi, Dave. We're just...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT