Question

Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate...

Objectives:

1. Use if, switch, and loop statements

2. Use input and output statements

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.

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code for the given problem:

#include<iostream>

#include<iomanip>

#include<cmath>

#include <string>

#include <fstream>

using namespace std;

//function to find the total parkTime

int findTotTime(int, int, int, int);

//function to calculate the fare

int estimateFare(int);

//print the refare details in the recept

void farePrint(int, int, int, int, int, int);

//The main

int main() {

//the run file

string str="run.txt";

//open the run file

ifstream is(str);

int enterHr, enterMin, exitHr, exitMin, parkTime, charge;

//the while loop to process each entries

while(is>>enterHr>>enterMin>>exitHr>>exitMin)

{

//call the functions

parkTime = findTotTime(enterHr, enterMin, exitHr, exitMin);

charge = estimateFare(parkTime);

farePrint(enterHr, enterMin, exitHr, exitMin, parkTime, charge);

}

//for visual studio

//system("pause");

return 0;

}

//function to find the total parkTime

int findTotTime(int enterHr, int enterMin, int exitHr, int exitMin) {

if (exitHr == 55 && exitMin == 55)

return -2;

if (enterHr == 99)

return -1;

if (enterHr <= exitHr)

return (exitHr - enterHr)*60 + exitMin - enterMin;

  

return (exitHr + 24 - enterHr)*60 + exitMin - enterMin;

}

//function to calculate the fare

int estimateFare (int parkTime) {

int fare;

switch(parkTime)

{

case -1:

fare=5;

return fare;

break;

case -2:

fare=110;

return fare;

break;

}

if (parkTime <= 30)

return 3;

if (parkTime <= 60)

return 5;

if (parkTime <= 120)

return 10;

if (parkTime <= 180)

return 15;

if (parkTime <= 240)

return 30;

if (parkTime <= 720)

{

float x=(parkTime - 240)/30;

return 30 + ceil(x)*5;

}

return -1; //error

}

//print the refare details in the recept

void farePrint(int enterHr, int enterMin, int exitHr, int exitMin, int parkTime, int fare) {

if (enterHr == 99)

cout<<"You are using special pass. Your charge is $"<<fare<<endl;

else if (exitHr == 55)

cout<<"Enter Time: "<<enterHr<<":"<<enterMin<<endl<<"Card Lost \n Charge is: $"<<fare<<endl;

else

cout<<"Enter Time: "<<enterHr<<":"<<enterMin<<endl<<"Exit Time:" <<exitHr<<":"<<exitMin<<endl<<"Total park Time: "<<parkTime<<"mins"<<endl<<"Charge is $"<<fare<<endl;

}

Input file: run.txt

run.tt X main.cpp 00 00 00 30 05 45 07 00 06 32 09 54 09 15 12 15 09 32 14 35 08 00 10 30 08 45 55 55

output:

回 X cluser kannandocumentslvisual studio 2010\Projectsparking Debug\Park ng exe Enter Time: 0:0 Exit Time :0:30 Total park Ti

Add a comment
Know the answer?
Add Answer to:
Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if,...

    I need help in 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...

  • Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need...

    Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example in the PPT) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked beyond their time...

  • Parking Ticket Simulator C++ HELP PLEASE

    For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should designare:• The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are:o To know the car’s make, model, color, license number, and the number of minutes that the car has been parked• The ParkingMeter Class: This class should simulate a parking meter. The class’s only responsibility is:o To know the number...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • Chapter 9 Lab Text Processing and Wrapper Classes Lab Objectives ? Use methods of the Character...

    Chapter 9 Lab Text Processing and Wrapper Classes Lab Objectives ? Use methods of the Character class and String class to process text ? Be able to use the StringTokenizer and StringBuffer classes Introduction In this lab we ask the user to enter a time in military time (24 hours). The program will convert and display the equivalent conventional time (12 hour with AM or PM) for each entry if it is a valid military time. An error message will...

  • JAVA LANGUAGE int choice; Scanner in = new Scanner(System.in); while(true) { System.out.println(); System.out.println("(1) Add a new...

    JAVA LANGUAGE int choice; Scanner in = new Scanner(System.in); while(true) { System.out.println(); System.out.println("(1) Add a new flight."); System.out.println("(2) Buy ticket."); System.out.println("(3) Request a Check-In."); In this assignment, you are required to improve your flight registration system. Your new system should be able to process check-in of passengers and calculate take-off load of planes. You should also use enums to represent menu items such as; (1)Add a new flight. (2)Buy ticket. (3)Request a Check-In. (4) Process a Check-In. (5) Display Valid...

  • Question 5 (1 point) Suppose you work for a marketing consulting firm and you are tasked...

    Question 5 (1 point) Suppose you work for a marketing consulting firm and you are tasked to determine the proportion of Americans who respond positively to an ad your agency is testing for release. A survey is performed and you randomly select 134 respondents. You input your data into a statistical computing package (like Minitab) and you are given a 99% confidence interval of (0.3886 , 0.6114). You need to present these findings next departmental meeting. What is the correct...

  • What to submit: your answers to exercises 1, and 2 and separate the codes to each...

    What to submit: your answers to exercises 1, and 2 and separate the codes to each question. Create a MyTime class which is designed to contain objects representing times in 12-hour clock format. Eg: 7:53am, 10:20pm, 12:00am (= midnight), 12:00pm (= noon). You can assume the user will enter times in the format given by the previous examples. Provide a default constructor, a set method which is given a String (eg: “7:53am”), a getHours method, a getMinutes method and a...

  • //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS ...

    Complete the incomplete code provided //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //Calculate the cost of the gas on a trip /Ideclare, ask, and get the price per gallon and the mpg /Icalculate and return (by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr) //using a 70 MPH speed limit and the miles passed to the function //calculate and...

  • Question 2 A fast-food franchise is considering operating a drive-up window food-service operatio...

    Question 2 A fast-food franchise is considering operating a drive-up window food-service operation. Assume that customer arrivals follow a Poisson probability distribution, with an arrival rate of 24 cars per hour, and that service times follow an exponential probability distribution. Arriving customers place orders at an intercom station at the back of the parking lot and then drive to the service window to pay for and receive their orders. The following three service alternatives are being considered: A single-channel operation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT