Project 3 -Parking Deck Ticketing System Objectives: 1. Use if, switch, and loop
ID: 3828809 • Letter: P
Question
Project 3 -Parking Deck Ticketing System Objectives: 1. Use if, switch, and loop statements to solve a problem. 2. Use input and output statements to model a real world application 3. Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then ask you what time the car left the parking deck. You should then calculate the time that has passed between issuing the time ticket and the time the car left. Lastly, you will use this information to determine how much the person needs to pay upon leaving the deck. The rates are in the table below. Please read through all of the notes below! You should write a single function for each of the following things Reading in the arrival times and departure times Calculate the passage of time Determine how much the player needs to pay Print out the receipt for the user. Including their arrival and departure times, time in the deck and how much they owe.Explanation / Answer
#include<iostream>
using namespace std;
int main(){
//Prompt user to enter arrival and departure time
int hr_arrival, min_arrival, hr_departure, min_departure;
cout<<"Enter hours (0 to 23) and minutes (0 to 59) when the
car arrived at the parking deck"<<endl;
cin>>hr_arrival>>min_arrival;
cout<<"Enter hours (0 to 23) and minutes (0 to 59) when the
car left the deck"<<endl;
cin>>hr_departure>>min_departure;
//Calculate the time for which the car was in the deck (in minutes)
int passed_Time;
passed_Time = calcTime(hr_departure, min_departure,hr_arrival,min_arrival);
int diff_hr;
int diff_min;
diff_hr = hr_departure - hr_arrival;
diff_min = min_departure - min_arrival;
passed_Time = (diff_hr*60) + diff_min;
//Calculate the rate for the car depending on the rate-chart (Coverted to minutes)
int rate;
if(passed_Time < 30)
rate = 3;
if(passed_Time >= 30 && passed_Time <= 60)
rate = 5;
if(passed_Time > 60 && passed_Time <= 120)
rate = 10;
if(passed_Time > 120 && passed_Time <= 180)
rate = 15;
if(passed_Time > 180 && passed_Time <= 240)
rate = 30;
if(passed_Time > 240 && passed_Time <= 720){
rate = 30;
int x = passed_Time - 240;
rate += (x/30)*5;
}
//Invalid if car is in deck for more than 12 hours
if(passed_Time > 720 && passed_Time <= 1440)
rate = -1;
//rate if ticket is lost
if(hr_departure == 55 && min_departure == 55)
rate = 110;
//Rate for special ticket
if(hr_arrival == 99 && min_arrival == 99)
rate = 5;
//Convert passed_Time to hour and minutes
int deck_time_hr = passed_Time/60;
int deck_time_min = passed_Time%60;
//Print out the receipt
cout<<"Printing receipt..."<<endl;
//If car was in deck for >12 hours, its an error
if(rate == -1) cout<<"Error : Invalid time spent in deck!!"<<endl;
else {
//Print out the valid receipt
cout<<"Your arrival time was "<<hr_arrival<<" hr and "<<
min_arrival<<" min"<<endl;
cout<<"Your departure time is "<<hr_departure<<" hr and "<<
min_departure<<" min"<<endl;
cout<<"Time spent in the deck is "<<deck_time_hr<<" hr and "<<
deck_time_min<<" min."<<endl;
cout<<"You owe $"<<rate<<"! Please pay and proceed. Have
a great day ahead!!"<<endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.