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,...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
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 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT