Question

In: Computer Science

1) Here is a program in c++ that calculates a speeding ticket, modify the program to...

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;

}

Solutions

Expert Solution

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


Related Solutions

Write a java program that calculates a speeding fine. The user is prompted for the speed...
Write a java program that calculates a speeding fine. The user is prompted for the speed of the vehicle, the posted speed limit and if the offence took place in the construction zone. The fine is calculated at $75 + 3$/ km over the speed limit for the first 20km over + $6 / km for the next 20 and $9/km after that. If the posted limit is 40km, the fine is doubled. If the offence took place in a...
DESIGH A FLOWCHART IN FLOWGORITHM Speeding Violation Calculator. Design a program that calculates and displays the...
DESIGH A FLOWCHART IN FLOWGORITHM Speeding Violation Calculator. Design a program that calculates and displays the number of miles per hour over the speed limit that a speeding driver was doing. The program should ask for the speed limit and the driver's speed. Validate the input as follows: The speed limit should be at least 20, but not greater than 70. The driver's speed should be at least the value entered for the speed limit (otherwise the driver was not...
Modify the provided code to create a program that calculates the amount of change given to...
Modify the provided code to create a program that calculates the amount of change given to a customer based on their total. The program prompts the user to enter an item choice, quantity, and payment amount. Use three functions: • bool isValidChoice(char) – Takes the user choice as an argument, and returns true if it is a valid selection. Otherwise it returns false. • float calcTotal(int, float) – Takes the item cost and the quantity as arguments. Calculates the subtotal,...
Write a program that calculates the floor of a decimal number as defined here. Basically the...
Write a program that calculates the floor of a decimal number as defined here. Basically the Floor of any decimal number x, is the nearest whole number less than or equal to x. ( Code Should Be In C++) Requirements 1) You must implement a function to calculate the floor (you cannot use C++'s floor function). Name it floorAndError). It will have a return value and a single parameter 2) The program will ask the user to input a number...
In C Program #include Create a C program that calculates the gross and net pay given...
In C Program #include Create a C program that calculates the gross and net pay given a user-specified number of hours worked, at minimum wage. The program should compile without any errors or warnings (e.g., syntax errors) The program should not contain logical errors such as subtracting values when you meant to add (e.g., logical errors) The program should not crash when running (e.g., runtime errors) When you run the program, the output should look like this: Hours per Week:...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
C Programming: POSIX: Producer / Consumer Modify the code below so that the Producer.c file calculates...
C Programming: POSIX: Producer / Consumer Modify the code below so that the Producer.c file calculates the Fibonacci sequence and writes the sequence to the shared-memory object. The Consumer.c file should then output the sequence. Producer.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <sys/shm.h> #include <sys/stat.h> #include <sys/mman.h> #include <zconf.h> int main() { /* The size (in bytes) of shared-memory object */ const int SIZE = 4096; /* The name of shared-memory object */ const char *Obj =...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
Read the article entitled "Faster than a Speeding Text" link is here: "Faster than a Speeding...
Read the article entitled "Faster than a Speeding Text" link is here: "Faster than a Speeding Text" by Sigal Barsade and answer the following questions: A. Discuss a communication event in which you experienced emotional contagion. What was the outcome? B. Why is it important to be aware of emotional contagion theory? At work? At home?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT