Write a simulation program in C++ that simulates cars entering a parking lot, pa
ID: 3806106 • Letter: W
Question
Write a simulation program in C++ 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 limit. If a car is found to be in violation, then the car is towed away (removed from the parking lot). Note may need other classes to have a true OOD. The simulation should have the following parameters:
A lot with 20 spaces
Cars can pay for parking in 15 minute increments: 15, 30, 45, and 60 minutes.
Cars can be parked at a max of 1 hour. Therefore a car could pay for 30 minutes of parking, and park for 45 minutes. Any car parked for more than an hour is automatically in violation and is towed away.
Cars can park for 5 - 70 minutes (using 5 minute increments)
Cars that are towed are just removed from the lot
The police officer should patrol at least once every 10 minutes on average.
If the lot is full, cars are removed from the simulation.
The program should only ask the user for the amount of time (in minutes) to run the simulation. The simulation should run to the end and output the following data:
Number of cars that were found in violation
Number of cars that parked
Number of cars that were turned away because the lot was full
The average # of full spaces
NOTE: Divide your code into .h files, .cpp, and source.cpp (which is just your main)
Explanation / Answer
#include #include #define CAR 1 #define SCOOTER 2 /* to store vehicle number, and its row-col position in an array */ struct vehicle { int num ; int row ; int col ; int type ; } ; int parkinfo[4][10] ; /* a 2-D array to store number of vehicle parked */ int vehcount ; /* to store total count of vehicles */ int carcount ; /* stores total count of cars */ int scootercount ; /* stores total count of scooters */ void display( ) ; void changecol ( struct vehicle * ) ; struct vehicle * add ( int, int, int, int ) ; void del ( struct vehicle * ) ; void getfreerowcol ( int, int * ) ; void getrcbyinfo ( int, int, int * ) ; void show( ) ; /* decrements the col. number by one this fun. is called when the data is shifted one place to left */ void changecol ( struct vehicle *v ) { v -> col = v -> col - 1 ; } /* adds a data of vehicle */ struct vehicle * add ( int t, int num, int row, int col ) { struct vehicle *v ; v = ( struct vehicle * ) malloc ( sizeof ( struct vehicle ) ) ; v -> type = t ; v -> row = row ; v -> col = col ; if ( t == CAR ) carcount++ ; else scootercount++ ; vehcount++ ; parkinfo[row][col] = num ; return v ; } /* deletes the data of the specified car from the array, if found */ void del ( struct vehicle *v ) { int c ; for ( c = v -> col ; c < 9 ; c++ ) parkinfo[v -> row][c] = parkinfo[v -> row][c+1] ; parkinfo[v -> row][c] = 0 ; if ( v -> type == CAR ) carcount-- ; else scootercount-- ; vehcount-- ; } /* get the row-col position for the vehicle to be parked */ void getfreerowcol ( int type, int *arr ) { int r, c, fromrow = 0, torow = 2 ; if ( type == SCOOTER ) { fromrow += 2 ; torow += 2 ; } for ( r = fromrow ; rRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.