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

Your task is to write a program that simulates a parking meter within the parkin

ID: 3678758 • Letter: Y

Question

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 driver needs to pay

Print out the receipt for the driver, including his arrival and departure times, time in the deck, and how much he owes.

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, 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 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.)

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

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

Run 9

9

10

23

30

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

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


/**The c++ program that prompts the start and end times of the parking
vachicle. Then calculates the total time in the parking lot.
Then calculate the parking charge and display to console*/
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{

   //set special parking charge
   const int SPECIAL_PARKING_CHARGE=5;
   //set lost ticket charge
   const int LOST_TICKET=110;

   int startHour;
   int startminutes;

   int endHour;
   int endMinutes;

   //set hours and minutes to zero
   int totalHours=0;
   int totalMinutes=0;


   double parkingCharge=0;

   cout<<"Enter starting Hour : HH"<<endl;
   //read starting hour
   cin>>startHour;

   cout<<"Enter starting Minute : MM"<<endl;
   //read starting minutes
   cin>>startminutes;

   cout<<"Enter ending Hour : HH"<<endl;
   //read end hours
   cin>>endHour;

   cout<<"Enter ending Minute : MM"<<endl;
   //read end minutes
   cin>>endMinutes;


   if(startHour==99 && endHour==99 && endHour==99 && endMinutes==99)
       parkingCharge=SPECIAL_PARKING_CHARGE;
   else if(startHour==55 && endHour==55 && endHour==55 && endMinutes==5)
       parkingCharge=LOST_TICKET;
   else
   {
       //find total hours
       totalHours=endHour-startHour;

       if(startminutes!=0)
           totalMinutes=endMinutes+(60-startminutes);
       else
           totalMinutes=endMinutes;

       if(totalMinutes>60)
       {
           totalHours=totalHours+(totalMinutes/60);
           totalMinutes=totalMinutes%60;
       }      
   }

   //Calculate total minutes
   int minutes=totalHours*60+totalMinutes;

   //check if totalHours is zero
   if(totalHours==0)
   {

       //check if totalminutes is less than or equal to 30
       if(totalMinutes<=30)
           //set parking charge=3
           parkingCharge=3;      
       else
           //set parking charge=5
           parkingCharge=5;
   }
   else if(minutes>=60 && minutes<120)
   {
       parkingCharge=10;
   }
   else if(minutes>=120 && minutes<180)
   {
       parkingCharge=15;
   }
   else if(minutes>=180 && minutes<240)
   {
       parkingCharge=30;
   }
   else if(minutes>=240 && minutes<=720)
   {
       parkingCharge=30+((minutes-4*60)/30)*5;
   }
   else if(minutes>720)
   {
       cout<<"More than 12 hours .Visit parking adminstrative office"<<endl;
   }

   cout<<"Starting Time HH:MM = "
       <<startHour<<":"<<startminutes<<endl;
   cout<<"Ending Time HH:MM = "
       <<endHour<<":"<<endMinutes<<endl;

   //print total parking time
   cout<<"Time in parking Lot HH:MM = "<<totalHours<<":"<<totalMinutes<<endl;
   //print the due to console
   cout<<"Due : $"<<setprecision(2)<<parkingCharge<<endl;

   //pause the program output on console
   system("pause");
   return 0;

}

------------------------------------------------------------------------------------------------------

Sample output:

Enter starting Hour : HH
00
Enter starting Minute : MM
00
Enter ending Hour : HH
00
Enter ending Minute : MM
30
Starting Time HH:MM = 0:0
Ending Time HH:MM = 0:30
Time in parking Lot HH:MM = 0:30
Due : $3

Enter starting Hour : HH
00
Enter starting Minute : MM
00
Enter ending Hour : HH
13
Enter ending Minute : MM
00
More than 12 hours .Visit parking adminstrative office
Starting Time HH:MM = 0:0
Ending Time HH:MM = 13:0
Time in parking Lot HH:MM = 13:0
Due : $0