Programming language: C++ Project 3 – Parking Deck Ticketing System Objectives:
ID: 3809012 • Letter: P
Question
Programming language: C++
Project 3 – Parking Deck Ticketing System
Objectives:
Use if, switch, and loop statements to solve a problem.
Use input and output statements to model a real world application
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.
Notes:
Time should be handled in the 24 hour format for simplicity. In addition, you should have the user input the hours, then input the minutes as two separate variables. Please have the user enter hours ranging from 0 to 23, and minutes ranging from 0 to 59.
You may assume that the parking deck is open 24/7 for simplicity. You do not need to worry about times the deck closes and such for this project.
If the drive has a special parking pass, please enter the time of 99 for the hour and 99 for the minutes when entering the deck. This should be used as a code for the system to know that this person has a special parking pass.
If the drive has lost their ticket, please input 55 for the hour and 55 for the minutes when exiting the deck. This will prompt the system to handle the payments without a ticketing stub.
Please make sure that the output is attractive and informative. It should include, but is not limited to: the time the ticket was issued the time the ticket was entered back into the machine (time the drive exited the deck.) You should also include the amount of time that transpired while the driver was in the deck and the amount of money due to pay back. Please use proper formatting techniques for output (fixed and set precision, remember we are talking about money.)
Rate Table:
Time in Parking Deck
Rate in Dollars ($)
Less than 30 minutes
3.00
[30 Minutes – 1 Hour)
5.00
[1 Hour – 2 Hours )
10.00
[2 Hours – 3 Hours )
15.00
[3 Hours – 4 Hours )
30.00
Each half hour over four hours
30.00 + 5.00 per additional half hour
[12 Hours – Hours )
Error prints out, see notes above.
Lost ticket
110.00
Special Parking Pass
5.00
Running:
Please run the following sets of data:
Entrance Hour
Entrance Minute
Exit Hour
Exit Minute
Run 1
00
00
00
30
Run 2
05
45
07
00
Run 3
06
32
09
54
Run 4
09
15
12
15
Run 5
09
32
14
35
Run 6
08
00
10
30
Run 7
08
45
55
55
Run 8
99
99
99
99
Submitting:
Please include this document at the front of your project folder. This should be followed by the algorithm for your program. Next please include your source code, followed by all of your output. Lastly, please include your academic honesty promise. Please put all of these documents in a zipped folder and submit to D2L.
Extra Credit:
What happens if you were to arrive at 5:00 PM and leave at 4:00 AM? Would you program still run this correctly? Make sure that you can account for this sort of issue.
Time in Parking Deck
Rate in Dollars ($)
Less than 30 minutes
3.00
[30 Minutes – 1 Hour)
5.00
[1 Hour – 2 Hours )
10.00
[2 Hours – 3 Hours )
15.00
[3 Hours – 4 Hours )
30.00
Each half hour over four hours
30.00 + 5.00 per additional half hour
[12 Hours – Hours )
Error prints out, see notes above.
Lost ticket
110.00
Special Parking Pass
5.00
Explanation / Answer
source code:
#include<iostream>
#include<cmath>
using namespace::std;
int main() {
int inHr, inMin, outHr, outMin, time, price;
void acceptTime(int*, int*,string);
int calcTime(int, int, int, int);
int calcFare(int);
void printRecipt(int, int, int, int, int, int);
acceptTime(&inHr, &inMin, "in-time");
acceptTime(&outHr, &outMin, "out-time");
time = calcTime(inHr, inMin, outHr, outMin);
price = calcFare(time);
printRecipt(inHr, inMin, outHr, outMin, time, price);
}
void acceptTime(int* hr, int* min, string str) {
cout<<"Enter "<<str<<" time hours: ";
cin>>*hr;
while ((*hr < 0 || *hr > 23 )&& *hr != 55 && *hr != 99) {
cout<<"Invalid input. Hour can be between 0-23: ";
cin>>*hr;
}
if (*hr == 55 || *hr == 99) {
*min = *hr;
return;
}
cout<<"min: ";
cin>>*min;
while (*min < 0 || *min > 59) {
cout<<"Invalid input. Min can be between 0-59: ";
cin>>*min;
}
}
int calcTime(int inHr, int inMin, int outHr, int outMin) {
if (outHr == 55 && outMin == 55)
return -2;
if (inHr == 99)
return -1;
if (inHr <= outHr)
return (outHr - inHr)*60 + outMin - inMin;
return (outHr + 24 - inHr)*60 + outMin - inMin;
}
int calcFare (int time) {
if (time == -1) //special pass
return 5;
if (time == -2) // lost token
return 110;
if (time <= 30)
return 3;
if (time <= 60)
return 5;
if (time <= 120)
return 10;
if (time <= 180)
return 15;
if (time <= 240)
return 30;
if (time <= 720)
return 30 + ceil((time - 240)/30)*5;
return -1; //error
}
void printRecipt(int inHr, int inMin, int outHr, int outMin, int time, int fare) {
if (inHr == 99)
cout<<"Thank you for using special pass. Your fare is $"<<fare<<endl;
else if (outHr == 55)
cout<<"In-time: "<<inHr<<":"<<inMin<<endl<<"You have lost your card Fare is: $"<<fare<<endl;
else
cout<<"In-time: "<<inHr<<":"<<inMin<<endl<<"Out-time:" <<outHr<<":"<<outMin<<endl<<"Total-time: "<<time<<"mins"<<endl<<"Fare is $"<<fare<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.