Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please read full assignment including the parts in bold. data has to be read fro

ID: 3855610 • Letter: P

Question

Please read full assignment including the parts in bold. data has to be read from file(ifstream). Output(time) should be in format 00 instead of 0.

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 put the data on a file with the hours and the minutes as two separate variables separated by a space, read that from file. Please have the hours ranging from 0 to 23, and minutes ranging from 0 to 59 with a blank in between hours and minutes. See the second table below for the data.

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 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 <= 12 hours

30.00 + 5.00 per additional half hour

>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 from an input file:

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:

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.

More Information on Project 3

If the ticket is lost (code 99), charge the patron $110.00.
If the patron has a parking pass (code 55), the charge is $5.00.
If the ticket shows more than 12 hours in the parking deck, print ERROR in the column where the charge usually goes.
If you do the extra credit (in at 17:00 hours (5PM)and out at 4:00 (4AM)), the charge will be $100.00 for 11 hours.
Present the answers in a table with column headings of entry hours & min (could be 99), exit hours & min (could be 99 or 55), total minutes in the parking deck (leave blank for codes of 99 and 55), and total cost of parking.

Answers are: 3.00, 10.00, 30.00, 15.00, 45.00, 15.00, 110.00, 5.00, ERROR, and 100.00(extra credit).

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 <= 12 hours

30.00 + 5.00 per additional half hour

>12 Hours <= 24 Hours )

Error prints out, see notes above.

Lost ticket

110.00

Special Parking Pass

5.00

Explanation / Answer

Here is the code for the question. It prompts for input filename and writes to an output file whose name has prefix "out-" followed by input file name. Example, if input filename was parking.txt , then output fileanme is out-parking.txt

In case of any issues running the code, post a comment. If happy with the answer, please rate it. Thank you.

#include <iostream>

#include <fstream>

#include <cstdlib>

#include <iomanip>

using namespace std;

int main()

{

ifstream ifs;

string fname;

int entryH, entryM, exitH, exitM;

int entryMinutes, exitMinutes, diff = -1;

  

  

double charges;

  

cout << "Enter file name containing parking data: ";

cin >> fname;

  

ifs.open(fname.c_str());

if(!ifs.is_open())

{

cout << "Error opening input file " << fname << endl;

exit(1);

}

  

  

cout << fixed << setprecision(2); //2 decimal points in display of double values

  

ifs >> entryH >> entryM >> exitH >> exitM;

  

if(entryM == 99 && entryH == 99)

{

//special pass

charges = 5.00;

}

else if(exitM == 55 && exitM == 55) //lost ticket

{

charges = 110.00;

}

else

{

//convert both entry and exit times to total minutes so that we can

//calculate difference in minutes only

  

entryMinutes = entryH * 60 + entryM;

exitMinutes = exitH * 60 + exitM;

  

diff = exitMinutes - entryMinutes; //diff is in minutes

  

//we will add extra day and take modulus by day hours to handle extra credit cases,

//this will take care when the exit time is in the next day

int day = 24 * 60;

diff = (diff + day) % day;

  

if(diff <= 30) // <= 30 mins

charges = 3.0;

else if(diff <= 60) // >30 mins and <= hour

charges = 5.0;

else if(diff <= 2 *60) //>1 hr and <= 2hrs

charges = 10.00;

else if(diff <= 3 * 60) // >2hr and <= 3 hrs

charges = 15.00;

else if(diff <= 4 * 60) // >3hr adn <= 4hrs

charges = 30.00;

else if(diff <= 12 * 60) // > 4 hrs and <=12

{

charges = 30.00;

int extra = diff - 4 * 60; //the number of minutes above 4 hrs

int numHalfHours = extra / 30; //the number of half hours

charges += 5.00 * numHalfHours; //5.00 per each half hours

  

if(numHalfHours % 30 != 0) //for any mins less than half hour

charges += 5.0;

}

else //more than 12 hours is error

{

charges = -1;

}

  

  

  

//use setfill to display to use as fill character to display 0 as 00

  

cout << "Entry time: " << setfill('0') << setw(2) << entryH << ":" << setw(2) << entryM << endl;

cout << "Exit time: " << setfill('0') << setw(2) << exitH << ":" << setw(2) << exitM << endl;

cout << "Total parking time: ";

if(diff == -1) //not applicable for special and lost pass

cout << "-" << endl;

else

cout << diff << " mins"<< endl;

  

cout << "Charges: ";

if(charges == -1) // error , more than 12 hrs

cout << "ERROR" << endl;

else

cout << charges << endl;

  

  

}

ifs.close();

  

ofstream ofs("out-" + fname);//write an output file having prefix "out-" followed by input filename

ofs << entryH << " " << entryM << " " << exitH << " " << exitM << " " << diff << " ";

if(charges == -1)

ofs << "ERROR" << endl;

else

ofs << fixed << setprecision(2) << charges << endl;

  

ofs.close();

  

}

input file: parking.txt

09 32 14 35

output

$ g++ parking.cpp
$ ./a.out
Enter file name containing parking data: parking.txt
Entry time: 09:32
Exit time: 14:35
Total parking time: 303 mins
Charges: 45.00
$ cat out-parking.txt
9 32 14 35 303 45.00

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote