Any help with this program? Write a C++ program to calculate the parking fare fo
ID: 3552830 • Letter: A
Question
Any help with this program?
Write a C++ program to calculate the parking fare for customers who park their cars in a parking lot when the following information is given: character showing the type of vehicle: C for car, B for bus, and T for truck. An integer between 0 and 23 showing the hour the vehicle entered the lot. An integer between 0 and 60 showing the minute the vehicle entered the lot An integer between 0 and 23 showing the hour the vehicle left the lot An integer between 0 and 60 showing the minute the vehicle left the lot Management uses two different rates for each type of vehicle as shown below: No vehicle is allowed to stay in the lot later than midnight; any vehicle that remains past midnight will be towed away. Following is a sample screen input (Bold Italic is used to indicate typical input) Type of vehicle? T Hour vehicle entered lot (0 - 23)? 14 Minute vehicle entered lot (0 - 60)? 23 Hour vehicle left lot (0 - 23)? 18 Minute vehicle left lot (0 - 60)? 8 The output format is shown below. PARKING LOT CHARGE Type of Vehicle: Truck or Bus or Car TIME IN XX : XX TIME OUT XX : XX PARKING TIME XX : XX ROUNDED TOTAL XX TOTAL CHARGE $XX .XXExplanation / Answer
//============================================================================
// Name : Test.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char type;
float inHour,inMinute,outHour,outMinute,totHour,totMinute;
int charge;
cout<<"Type of Vehicle (C for Car, B for Bus, T for Truck): ";
cin>> type;
cout<<"Hour Vehicle enter lot(0-23)? ";
cin>> inHour;
cout<<"Minute Vehicle enter lot(0-60)? ";
cin>> inMinute;
cout<<"Hour Vehicle left lot(0-23)? ";
cin>> outHour;
cout<<"Minute Vehicle left lot(0-60)? ";
cin>> outMinute;
cout<<endl;
cout<<"PARKING LOT CHARG"<<endl;
cout<<endl;
cout<<"Type of Vehicle: ";
if(type == 'C' || type == 'c')
{
cout<<"Car"<<endl;
charge = 1;
}
else if(type == 'T' || type == 't')
{
cout<<"Truck"<<endl;
charge = 2;
}
else if(type == 'B' || type == 'b')
{
cout<<"Bus"<<endl;
charge = 3;
}
cout<<"Time in: "<<inHour<<":"<<inMinute<<endl;
cout<<"Time out: "<<outHour<<":"<<outMinute<<endl;
cout<<" ---------"<<endl;
totHour = outHour-inHour;
totMinute = fabs(outMinute-inMinute);
float tHour;
if(totMinute <60)
{
tHour = 0.5;
}
else
{
tHour = 1;
}
cout<<"Parking Time:"<<totHour<<":"<<totMinute<<endl;
cout<<"Round Total: "<<totHour+tHour<<endl;
cout<<" ---------"<<endl;
cout<<"Total Charge: "<<"$"<<(totHour+tHour)*charge<<endl;
return 0;
}
OUTPUT:
Type of Vehicle (C for Car, B for Bus, T for Truck): c
Hour Vehicle enter lot(0-23)? 14
Minute Vehicle enter lot(0-60)? 35
Hour Vehicle left lot(0-23)? 15
Minute Vehicle left lot(0-60)? 30
PARKING LOT CHARG
Type of Vehicle: Car
Time in: 14:35
Time out: 15:30
---------
Parking Time:1:5
Round Total: 1.5
---------
Total Charge: $1.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.