A local Road Safety Department is tasked with monitoring and issuing speeding ti
ID: 3728879 • Letter: A
Question
A local Road Safety Department is tasked with monitoring and issuing speeding tickets and warnings for drivers who violate the 120 km/hr speed it. Write a complete C++ program that reads the travelled distance of a car in km (as integer) and the elapsed time in minutes (as integer). The program should compute the speed of the car and issue violation ticket if the driver exceeds the speed lmit. The program must distinguish between private small vehicles (S"), large commercial trucks (T"), and government owned ones (G'). Your program should perform the following tasks o Prompt the user to enter the type of the car (S, T, or G). Prompt the user to enter the travelled distance. Prompt the user to enter the elapsed time Convert the time from minutes to hours. (e.g. 90 minutes 1.5 hours) Compute the speed as the travelled distance divided by the time in hours. Check if the driver violated the speed limit of 120 km/hr and issue speed violation ticket/notices/action according to the following tablo o o Speed Violation fee Between 120 and 140 km/hour Between 140 and 160 km/hour More than 160 km/hour 0 OMR 30 OMR 50 OMR, and 20 OMR 60 OMR Notify the government 100 OMR, and nstitution of the driver's licence is driver s licence iS violation suspended suspended Less than or equal to 120 0 OMR No violationExplanation / Answer
#include<iostream>
using namespace std;
int main(){
char type; // To store the tye of the car
int distance; // to get the distance
int minutes; // To get the elapsed time
cout<<"Enter the type of the car"<<endl;
cin>>type;
cout<<"Enter the travelled distance"<<endl;
cin>>distance;
cout<<"Enter the elapsed time in minutes"<<endl;
cin>>minutes;
float hours = float(minutes)/float(60); // Convert minutes to hours
float speed = float(distance)/float(hours); // Calculate the speed
cout<<"Driver speed is "<<speed<<" KM/hr for ''"<<type<<"' vehicle"<<endl;
if(speed <=120){ // if speed is < 120
cout<<"No violation fee"<<endl;
}else if(speed >120 && speed <=140){ // if speed is between 120 to 140
if(type == 'S'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"violation fee: 10 OMR"<<endl;
}else if(type == 'T'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"violation fee: 20 OMR"<<endl;
}else if(type =='G'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"Notify the government institution of violation"<<endl;
}
}else if(speed >140 && speed <= 160){ // If speed is between 140 to 160
if(type == 'S'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"violation fee: 30 OMR"<<endl;
}else if(type == 'T'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"violation fee: 60 OMR"<<endl;
}else if(type =='G'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"Notify the government institution of violation"<<endl;
}
}else{ // If speed is more than 160
if(type == 'S'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"violation fee: 50 OMR"<<endl;
cout<<"Driver's licence is suspended"<<endl;
}else if(type == 'T'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"violation fee: 100 OMR"<<endl;
cout<<"Driver's licence is suspended"<<endl;
}else if(type =='G'){
cout<<"Driver violated the speed Limit"<<endl;
cout<<"Notify the government institution of violation"<<endl;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.