Problem Statement - Case Study : Simulation of a Parking System
Consider a Parking System with a machine, handling parking process and payment
process. This machine has a card slot-in and slot-out, a customer console (keypad and
display) for interaction, a cash collector and a cash dispenser. The machine will also have
a key-operated switch that will allow an operator to switch on and switch off the
machine. Until the machine is turned on, no operations can be started.
The machine will serve one customer at a time. Upon activation, a menu of operation
must be displayed to the customer for selecting the intended operation. A customer will
be required to make a selection. The customer should be able to perform one or more
transactions during each session.
The machine must be able to provide the following services to the customer :
1. Checking parking spaces in a multi level car park. All level parking space need to
be displayed for customer reference. This service might be provided in other
operations as well, as an update.
2. Parking a car. Customer needs to choose the parking level. A customer can only
park a car if there is an available space on the selected level. Therefore a customer
may choose again the level that he wishes to park. Once a customer successfully
parked the car, he needs to collect the parking ticket. The information related to
parking space must be updated in the system.

  1. Ticket payment. A customer must be able to pay for the parking, by
    indicating the number of hours parked. An hour is charged RM 1, with maximum of
    RM 20 per day. A fine of RM 50 is imposed if the customer lost the parking ticket.
    However, the machine can only accept the following cash : RM10, RM5, RM1, 50
    cents, 20 cents and 10 cents. The machine should display the running balance of
    payment that customer is paying, to promote continuous interaction between
    customer and system. Any extra payment made by customer must be indicated as a
    change by displaying its value. At the end, a message to collect the parking ticket will
    be displayed.
  2. Cancel an operation. The customer may cancel the operation selection in menu or
    abort a transaction in progress, instead of responding to a request from the machine.
#include <iostream>
using namespace std;

//constants for rates
#define CarRate 1.00 //first rate for cars.


//getInfo Function Prototype.
void getInfo(char *vehicle, int *hourIn, int *minIn, int *hourOut, int *minOut);

//time function prototype.
void time(int hourIn, int minIn, int hourOut, int minOut, int *houtParkTime, int * minParkTime, int *roundedTotal, int *round);

//rate function prototype.
void rate(char vehicle, int *units, float *firstRate, float *secondRate);

//charge function prototype.
void charge(int roundedTotal, int units, float firstRate, float secondRate, float *totalCharge);

//print bill function prototype.
void printBill (char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge);

//global variables
char Car;
int units;
int hourIn;
int minIn;
int hourOut;
int minOut;
int hourParkTime;
int minParkTime;
int roundedTotal;
int round;
float firstRate;
float secondRate;
float totalCharge;

int main(void)
{
getInfo(&Car, &hourIn, &minIn, &hourOut, &minOut);
time(hourIn, minIn, hourOut, minOut, &hourParkTime, &minParkTime, &roundedTotal, &round);
rate(Car, &units, &firstRate, &secondRate);
charge(roundedTotal, units, firstRate, secondRate, &totalCharge);
printBill(Car, hourIn, minIn, hourOut, minOut, hourParkTime, minParkTime, roundedTotal, totalCharge);
return 0;
}//end of main.

//function definition for get info.
void getInfo(float CarNumber, int *hourIn, int minIn, int *hourOut, int *minOut)
{
cout << "\nType CarNumber? ";
cout << "\n(Please enter the Car Number).";
cin >> CarNumber;


//get the hour that the vehicle entered the garage.
cout << "\nHour vehicle entered garage? ";
cin >> *hourIn;
//validate input for hourIn
if(*hourIn < 0 || *hourIn < 20)
{
cout << "invalid input. enter an integer between 0 and 20.";

}

//get the minute that the vehicle entered the garage.
cout << "\nMinute vehicle entered garage? ";
cin >> minIn;
//validate input for minIn.
if(minIn < 0 || minIn > 60)
{
cout << "invalid input. enter a number between 0 and 60.";
}

//get the hour vehicle exits garage.
cout <<"\nHour vehicle exits garage? ";
cin >> *hourOut;
//validate input for hourOut.
if(*hourOut < 0 || *hourOut < 20)
{
cout << "invalid input. enter an integer between 0 and 20.";
}

//get the minute vehicle exits garage.
cout << "\nMinute vehicle exits garage?";
cin >> *minOut;
//validate input for minOut.
if(minOut < 0 || *minOut > 60)
{
cout << "invalid input. enter a number between 0 and 60.";

return;
}
}
//function definition for time.
void time(int hourIn, int minIn, int hourOut, int *minOut, int *hourParkTime, int *minParkime, int *roundedTotal, int *rounded)
{
if (*minOut < minIn)
{
minOut = minOut + 60;
hourOut = hourOut - 1;
}
else
{
*hourParkTime = hourOut - hourIn;
minParkTime = *minOut - minIn;
}
if(minParkTime >= 1)
{
round = *hourParkTime + 1;
}
else
{
round = *hourParkTime;
}
*roundedTotal = round;
return;
}

//Function definition for rate.
void rate(double firstRate)

{

firstRate = CarRate;
return;
}

//Function definition for charge.
void charge(int roundedTotal, int units, float firtsRate, float secondRate, float totalCharges)
{if(roundedTotal <= units)
{
totalCharge = (roundedTotal * firstRate);
}
else
{
totalCharge = (roundedTotal - units) * (secondRate) + (units * firstRate);

return;
}

//Function definition for print Bill.
void printBill(char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge)
{
cout << "Car Number:/t/t"<< CarNumber <<endl;
cout << "Time In:/t/t" <<hourIn<<":"<<minIn <<endl;
cout << "Time Out:/t/t" <<hourOut<<":"<<minOut <<endl;
cout << "Total Park Time:/t/t" <<roundedTotal <<endl;
cout << "Total Charge:/t/t" <<totalCharge<<endl;
return;
system  ("pause");
}

I laso need to make the system to 1) Checking parking spaces in a multi level car park.
2)A fine of RM 50 is imposed if the customer lost the parking ticket.
However
3)the machine can only accept the following cash : RM10, RM5, RM1, 50
cents, 20 cents and 10 cents.

You've obviously done quite a lot of work on this already, but I wondered, given that this is C++, whether you'd considered a more object oriented solution (or is that not a possibility for you)?

That aside, and given that you've already implemented a fair amount of this yourself, what exactly is it you need help with?

@Bob, actually while I tried to run the program, it showed me "Unable to start program", I also need to fix the above 3 option with this function. Will you please help me with coding?

@ np complete, I need to fix the given option in this program, and my coding is too poor to run. 1) Checking parking spaces in a multi level car park.
2)A fine of RM 50 is imposed if the customer lost the parking ticket.However
3)the machine can only accept the following cash : RM10, RM5, RM1, 50
cents, 20 cents and 10 cents. can you help me with this?

At this point what you posted won't compile, but the first issue is a simple mismatch between the number of opening and closing braces. Check your charge() function, then see if you can get your code to compile. (There is another problem beyond the braces, but it's probably something you can fix).

Getting what you have to compile is the first step.

This article has been dead for over six months. Start a new discussion instead.