In: Computer Science
1) Here is a program in c++ that calculates a speeding ticket, modify the program to double to cost of the ticket in a construction zone.
// This project will calculate a speeding ticket between 0 to 150 mph.
// 1. Ask for speed.
// 2. Input speed of vehicle
// 3. Calculate ticket cost (50$ if over 50mph with an additional 5$ for every mph over).
// 4. Display cost of ticket.
#include<iostream>
using namespace std;
int main()
{
double speed;//to store speed value
//get input
cout<<"Please insert speed of vehicle: ";
cin>>speed;//check the speed output result accordingly
if(speed<0|| speed>150)
return 1;
if(speed<=55)
return 1;
if(speed<=55)
cout<<"\nNo Speeding Ticket."<<endl;
else if(speed<=75)
cout<<"\nThe ticket cost is: "<<(50+2*(speed-55))<<endl;
else if(speed<=110)
cout<<"\nThe ticket cost is: "<<(50+5*(speed-55))<<endl;
else
cout<<"\nDriver should be arrested. "<<endl;
return 0;
}
The program is modified to double to cost of the ticket in a construction zone.
The Modified program
#include<iostream>
using namespace std;
int main()
{
double speed;//to store speed value
string zone;
int flag=0;
//get input
cout<<"Please insert speed of vehicle: ";
cin>>speed;//check the speed output result accordingly
cout <<"Is vehicle in the construction zone reply with ( Y or N) "<<endl;
cin>>zone;
if(zone=="Y")
flag=1;
if(speed<0|| speed>150)
return 1;
if(speed<=55)
return 1;
if(speed<=55)
cout<<"\nNo Speeding Ticket."<<endl;
else if(speed<=75 && flag==0)
cout<<"\nThe ticket cost is: "<<(50+2*(speed-55))<<endl;
else if(speed<=75 && flag==1)
cout<<"\nThe ticket cost is: "<<(50+2*(speed-55))*2<<endl;
else if(speed<=110 && flag==0)
cout<<"\nThe ticket cost is: "<<(50+5*(speed-55))<<endl;
else if(speed<=110 && flag == 1)
cout<<"\nThe ticket cost is: "<<(50+5*(speed-55))*2<<endl;
else
cout<<"\nDriver should be arrested. "<<endl;
return 0;
}
The screenshot of the output of working program
for reference the screenshot of the code is given
You can comment if you have any doubt.
Upvote if you got your answer.
Thanks