Need help completing this program in C++. Program listed below. Write a simulati
ID: 645999 • Letter: N
Question
Need help completing this program in C++. Program listed below. Write a simulation program 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
//main.cpp
#include <iostream>
#include <random>
#include <list>
#include "Car.h"
#include "Policeofficer.h"
#include "Parking.h"
using namespace std;
//initialize instance
Parking* instance = 0;
int main ()
{
//declare variables
int tempTime;
int carFrequency = 7;
int policeFrequency = 4;
cout <<" New simulation for parking " << endl;
cout << "Enter the lot amount time in minutes: ";
cin >> tempTime;
Parking::getInstance () -> setTime (tempTime);
for (int count =1; count <= Parking::getInstance () -> getTime(); count++)
{
cout << " Your minutes " << count << ": ";
Parking::getInstance() -> entersParking (carFrequency, count);
Parking::getInstance() -> carsLeaving (count);
Parking::getInstance() -> patrolsParkingLot (policeFrequency, count);
}
Parking::getInstance() -> displayData ();
cout << endl << endl;
system ("Pause");
return 0;
}
//Car.h
#ifndef CAR_H
#define CAR_H
#include <iostream>
#include <random>
#include <list>
#include "Policeofficer.h"
#include "Parking.h"
using namespace std;
class Car
{
public:
Car ();
int getInitialTime() {};
int getpaymentTime () {};
int getpaymentTime () {};
bool checkTimeToLeave (int) {};
~Car ();
//Car process
Car::Car (int iTime) //calculating car in, parking, and payment time
{
int initialTime = iTime;
int paymentTime = (1 + rand () % 4) * 15;
int parkTime = (1 + rand () % 70) * 5;
}
int Car::getInitialTime () //get time in
{
return initialTime;
}
int Car:: getpaymentTime () //get payment time
{
return paymentTime;
}
bool Car::checkTimeToLeave (int time)
{
if (time - initiaTime >= parkTime)
{
return true;
}
else
{
return false;
}
}
};
#endif
//Policeofficer.h
#ifndef POLICEOFFICER_H
#define POLICEOFFICER_H
#include <iostream>
#include <random>
#include <list>
#include "Car.h"
#include "Parking.h"
using namespace std;
class Policeofficer
{
public:
Policeofficer ();
void Patrol ();
void readyPatroling (int);
~Policeofficer ();
//police officer checking parking
void Policeofficer::Patrol ()
{
bool patroling = true;
int minute = 0;
}
void Policeofficer::readyPatroling (int patrolTime)
//add minutes
{
minute++;
if (minute >= 10)
{
patroling = true;
minute = 0;
}
else
{
if (rand() % 10 < partrolTime)
{
patroling = true;
minute = 0;
}
else
{
patroling = false;
}
}
}
};
#endif
//Parking.h
#ifndef PARKING_H
#define PARKING_H
#include <iostream>
#include <random>
#include <list>
#include "Car.h"
#include "Policeofficer.h"
using namespace std;
class Parking
{
private:
static bool instanceFlag;//not sure if i need
static Parking* single; //not sure if i need
public:
Parking ();
void setTime (int);
int getTime ();
int getLot ();
void minusLot ();
void entersParking (int, int);
void carsLeaving (int);
void addToCarViolation ();
void patrolsParkingLot (int, int);
void displayData ();
static Parking* getInstance();
~Parking ();
//parking lot
Parking::~Parking ()
{
instanceFlag = false; //not sure if this is needed
}
Parking* Parking::getInstance() //not sure if i need this
{
if(! instanceFlag)
{
single = new Singleton();
instanceFlag = true;
return single;
}
else
{
return single;
}
}
Parking::Parking()
//initialize count to 0 to check for violations, spaces available, and parked
{
int lot = 0;
int numOfCarsViolation = 0;
int numOfCarsParked = 0;
int turnedAwayCars = 0;
int averageFullSpaces = 0;
}
void Parking::setTime(int t)
{
time = t;
}
int Parking::getTime()
{
return time;
}
int Parking:: getLot()
{
return lot;
}
void Parking::minusLot()
{
lot -= 1;
}
//checking frequency and time for car
void Parking::entersParking (int frequency, int currentTime)
{
if ((rand() % 10) <= frequency)
{
if (lot <= 20)
{
Car newCar (currentTime);
car.push_back (newCar);
lot += 1;
numOfCarsParked += 1;
cout << "The car is entered in the lot.";
}
else
{
turnedAwayCars += 1;
cout << "Too many cars, car is turned away.";
}
}
}
void Parking::carsLeaving (int time)
{
list <Car>::iterator iter;
for (iter = car.begin(); iter != car.end(); iter++)
{
if (time - iter -> getInitialTime() >= 60)
{
iter = car.erase (iter); //removing car
numOfCarsViolation +=1; //violation list
lot -= 1;
cout <<"One Hour Violation!";
}
else
{
iter = car.erase (iter);
lot -= 1;
cout <<"The car leaves the parking lot";
}
}
averageFullSpaces += lot;
}
void Parking::addToCarViolation()
{
numOfCarsViolation += 1;
}
void Parking::patrolsParkingLot (int frequency, int time)
//checking policeofficer patrol is available or not
{
police.readyPatroling (frequency);
if (police.getPatroling())
{
police.patrolParkingLot (car, time);
cout << "Police officer is partoling lot.";
police.setPatrol ();
}
}
void Parking::displayData()
{
cout << " Number of cars wer found in violation: " << numOfCarsViolation << endl;
cout << " Number of cars parked in lot: " << numOfCarsParked << endl;
cout << " Lot full, Cars turned away: " << turnedAwayCars << endl;
cout << " Number of full spaces average: " << (averageFullSpaces / time) endl;
}
};
#endif
Explanation / Answer
public class ParkedCar
{
private String make;
private String model;
private String color;
private String licenseNumber;
public int minutes;
//Constructor with no arguments
public ParkedCar()
{
make = "";
model = "";
color = "";
licenseNumber = "";
minutes = 0;
}
//constructor with arguments
public ParkedCar(String cMake, String cModel,
String cColor, String cLicenseNum, int cMinutes)
{
make = cMake;
model = cModel;
color = cColor;
licenseNumber = cLicenseNum;
minutes = cMinutes;
}
//The set method sets a value for each field
public void set(String carMake, String carModel,
String carColor, String carLicenseNum,
int carMinutes)
{
make = carMake;
model = carModel;
color = carColor;
licenseNumber = carLicenseNum;
minutes = carMinutes;
}
//copy constructor initializes
//the object as a copy of another
//instructor object.
public ParkedCar(ParkedCar object2)
{
make = object2.make;
model = object2.model;
color = object2.color;
licenseNumber = object2.licenseNumber;
minutes = object2.minutes;
}
public String getMake()
{
return make;
}
public String getModel()
{
return model;
}
public String getColor()
{
return color;
}
public String getLicenseNumber()
{
return licenseNumber;
}
public int getMinutes()
{
return minutes;
}
//converts everything into a string
public String toString()
{
String str = " Make: " + make +
" Model: " + model +
" Color: " + color +
" License number: " + licenseNumber +
" Minutes parked: " + minutes;
return str;
}
//comparing
public boolean equals(ParkedCar ParkedCar2)
{
boolean status;
if(make.equals(ParkedCar2.make) &&
model.equals(ParkedCar2.model) &&
color.equals(ParkedCar2.color) &&
licenseNumber.equals(ParkedCar2.licenseNumber))
status = true;
else
status = false;
return status;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.