There are plenty of examples of this project where the user is prompted to enter
ID: 3606066 • Letter: T
Question
There are plenty of examples of this project where the user is prompted to enter the time. However, this one wants the times READ from a .txt FILE and a formatted output .txt file. Any help would be great as I cannot figure reading data in and pushing it out.
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 from a file that a car arrives in the parking deck. Next it will read in the 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 from a file
Calculate the passage of time
Determine how much the driver needs to pay
Print out the information for each driver in a report format, including his Run number, arrival and departure times, time in the deck, and how much he owes. Be sure to include the exceptions of a Lost Ticket, Special Parking Pass, and Error (over 12 hour stay).
Column Headings to be printed once at the beginning of the program – see format below.
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 for this project.
If the driver has a special parking pass, the program will read in 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, the program will enter the input of 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 driver 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 the driver has to pay. Please use proper formatting techniques for output (fixed and set precision, remember we are talking about money.) Use the output format given below in Running.
Rate Table:
Time in Parking Deck
Rate in Dollars ($)
Less than or equal to 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 and <= 12 hrs
30.00 + 5.00 per additional half hour or part thereof
12 Hours < 24 Hours )
Error prints out, see notes above.
Lost ticket
110.00
Special Parking Pass
5.00
Running:
Please run the following sets of data, using this format for the output:
Entrance Hour
Entrance Minute
Exit Hour
Exit Minute
Total Minutes or Hours and Minutes
Price for Parking
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
LOST TKT
Run 8
99
99
99
99
SPECIAL
Run 9
9
10
23
30
ERROR
Run 10 Extra Credit
17
0
4
0
Submitting:
Face-to-face students; please include this document at the front of your project folder. This should be followed by the algorithm for your program, source code, and your output. Lastly, please include your signed Academic Honesty Promise. Please print all of these and clamp them into your project folder. Turn it in on the due date.
Online students should submit the algorithm, the source code, the output, your signed Academic Honesty Promise, and the input data file. All of this should be in a zipped folder.
Extra Credit (5 points):
What happens if you were to arrive at 5:00 PM and leave at 4:00 AM? Would your program still run this correctly? Make sure that you can account for this sort of issue. Add data to test this situation.
Time in Parking Deck
Rate in Dollars ($)
Less than or equal to 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 and <= 12 hrs
30.00 + 5.00 per additional half hour or part thereof
12 Hours < 24 Hours )
Error prints out, see notes above.
Lost ticket
110.00
Special Parking Pass
5.00
Explanation / Answer
// Header files
#include<iostream>
#include<cmath>
#include<string>
using namespace::std;
// main function
int main()
{
// Declare the variables
int time_Inhour, time_Inmin, time_Outhour,time_Outmin, time, price;
// Function prototypes
void read_arr_dep_Times(int*, int*, string);
int cal_Passage_Time(int, int, int, int);
int cal_Pay(int);
void print_User_Receipt(int, int, int,int, int, int);
// call the read_arr_dep_Times() function
read_arr_dep_Times(&time_Inhour, &time_Inmin,"in-time");
// call the read_arr_dep_Times() function
read_arr_dep_Times(&time_Outhour, &time_Outmin,"out-time");
// call the cal_Passage_Time() function
time = cal_Passage_Time(time_Inhour, time_Inmin,time_Outhour, time_Outmin);
// call the cal_Pay() function
price = cal_Pay(time);
// call the print_User_Receipt() function
print_User_Receipt(time_Inhour, time_Inmin, time_Outhour, time_Outmin, time, price);
//system("pause");
return 0;
}
// Reading in the arrival times
//and departure times
void read_arr_dep_Times(int* hour, int* minute, string s)
{
cout << "Enter " << s << " hours: ";
cin >> *hour;
// Hours ranging from 0 to 23 and minutes
//ranging from 0 to 59.
while ((*hour < 0 || *hour > 23) && *hour != 55 && *hour != 99)
{
cout << "Wrong input!(Please enter Hour can be between 0-23): ";
cin >> *hour;
}
if (*hour == 55 || *hour == 99)
{
*minute = *hour;
return;
}
cout << "min: ";
cin >> *minute;
while (*minute < 0 || *minute > 59)
{
cout << "Wrong input!(Please enter Minutes can be between 0-59): ";
cin >> *minute;
}
}
//Calculate the passage of time
int cal_Passage_Time(int time_Inhour,int time_Inmin, int time_Outhour, int time_Outmin)
{
//Check the input 55 for the hour
// and 55 for the minutes
if (time_Outhour == 55 && time_Outmin == 55)
return -2;
//Check the input time of 99 for the hour
//and 99 for the minutes
if (time_Inhour == 99)
return -1;
if (time_Inhour <= time_Outhour)
return (time_Outhour - time_Inhour) * 60 + time_Outmin - time_Inmin;
return (time_Outhour + 24 - time_Inhour)* 60 + time_Outmin - time_Inmin;
}
//Determine how much the player needs to pay
int cal_Pay(int time)
{
//Check the drive has a special parking pass
if (time == -1)
return 5;
// Check the drive has lost their ticket
if (time == -2)
return 110;
// Less than 30 minutes
if (time <= 30)
return 3;
// Between 30 Minutes – 1 Hour
if (time <= 60)
return 5;
//Between 1 Hour – 2 Hours
if (time <= 120)
return 10;
//Between 2 Hours – 3 Hours
if (time <= 180)
return 15;
//Between 3 Hours – 4 Hours
if (time <= 240)
return 30;
//Each half hour over four hours
if (time <= 720)
return 30 + ceil((time - 240) / 30) * 5;
//error
return -1;
}
//Print out the receipt for the user.
void print_User_Receipt(int time_Inhour, int time_Inmin,int time_Outhour, int time_Outmin, int time, int fare)
{
//Check the drive has a special parking pass
if (time_Inhour == 99)
cout << "The person has a special parking pass.Fare is $" << fare << endl;
// Check the drive has lost their ticket
else if (time_Outhour == 55)
cout << "In-time: " << time_Inhour<< ":" << time_Inmin << endl
<< "The drive has lost their ticket Fare is: $" << fare << endl;
else
cout << "In-time: " << time_Inhour<< ":" << time_Inmin << endl << "Out-time:"<< time_Outhour << ":" << time_Outmin << endl << "Total-time: " << time << "mins" << endl << "Fare is $" << fare << endl;
}