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 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
//parking ticket simulator example
#include<iostream>
#include<string>
using namespace std;
int m=0, min, k[10], c;
class parkedcar //class holds data of the car in parking
{
string make;
int model;
string color;
string licnumber;
int minutesparked;
public:
parkedcar()
{
make=" ";
model=0;
licnumber=" ";
color=" ";
minutesparked=0;
}
void setmake(string mk)
{
make=mk;
}
void setmodel(int ml)
{
model=ml;
}
void setcolor(string c)
{
color=c;
}
void setlicnumber(string l)
{
licnumber=l;
}
void setminutesparked(int mnp)
{
minutesparked=mnp;
}
string getmake() const
{
return (make);
}
int getmodel() const
{
return (model);
}
string getcolor() const
{
return (color);
}
string getlicnumber() const
{
return (licnumber);
}
int getminutesparked() const
{
return (minutesparked);
}
void print();
};
void parkedcar:rint() //outside class definition
{
cout<<"Car Make :"<<getmake()<<endl;
cout<<"Car Model :"<<getmodel()<<endl;
cout<<"Car License Number
:"<<getlicnumber()<<endl;
cout<<"Car Color :"<<getcolor()<<endl;
}
class parkingticket: public parkedcar //class calculates and
shows
fine (if any)
{
int fine;
int minutes;
void calfine(); //helper function, calculates fine
public:
void showfine(); //function to show the fine
void getticket (int min) //calls the helper function
calfine()
{
minutes=min;
calfine();
cout<<endl;
}
int getfine() const
{
return(fine);
}
};
void parkingticket::calfine() //outside class definition
{
if(minutes/60<=0)
{
fine = 45;
}
else
{
int mn;
mn=minutes - 60;
fine = 45 + 30 + 30*(mn/60);
}
}
void parkingticket::showfine() //outside class definition
{
cout<<" ILLEGAL PARKING"<<endl;
cout<<" Time in violation is "<<minutes/60<<"
hours & "<<minutes
%60<<" minutes "<<endl;
cout<<" Fine : Rs. "<<getfine()<<endl;
}
parkingticket tck[10]; //Parking ticket array of objects
created
class parkingmeter //This class take carea of number of
minutes
purchased
{
int minpurchased;
public:
parkingmeter()
{
minpurchased=0;
}
void setminpurchased(int m)
{
minpurchased=m;
}
int getminpurchased() const
{
return(minpurchased);
}
void print()
{
cout<<"Mins purchased are"<<getminpurchased();
}
};
class policeofficer //Responsible for patrolling and
issuing
parkingticket
{ //in case vehicle is illegally parked
string name;
string badgenumber;
parkingticket *ticket; //Pointer of the type parkingticket
class
public:
policeofficer()
{
name=" ";
badgenumber=" ";
ticket = NULL;
}
void setname(string n)
{
name=n;
}
void setbadgenumber(string b)
{
badgenumber=b;
}
string getname() const
{
return(name);
}
string getbadgenumber() const
{
return(badgenumber);
}
parkingticket* patrol(parkingticket pc1, parkingmeter pc2)
//Patrol
function
{
if ( pc1.getminutesparked() < pc2.getminpurchased() ||
pc1.getminutesparked() == pc2.getminpurchased() )
{
return NULL; //No crimes
}
else //Illegal parking
{
tck[m].getticket(pc1.getminutesparked() -
pc2.getminpurchased());
cout<<"--------------------------------------------------------------------------------"<<endl;
tck[m].showfine();
ticket=&tck[m];
return(ticket);
}
}
void print()
{
cout<<"Name: "<<getname()<<endl;
cout<<"Badge Number:
"<<getbadgenumber()<<endl;
}
};
void intro()
{
cout<<"*******************************************
*************************************"<<endl;
cout<<" THIS IS PARKING TICKET SIMULATOR"<<endl;
cout<<"*******************************************
*************************************"<<endl;
}
void choice()
{
cin>>c;
if(c==0)
{
m++;
}
else if(c==1)
{
}
else
{
cout<<"Invalid Entry, try again :"<<endl;
choice();
}
}
int main()
{
system("cls");
int i=0, y;
intro();
cout<<"PARKING RATES ::"<<endl;
cout<<"Parking rate is Rs. 25 for 60
minutes"<<endl;
cout<<endl<<endl;
cout<<"FINE RATES ::"<<endl;
cout<<"In case number of minutes car has been parked exceeds
the
number of minutes purchased, then a fine is
applied."<<endl;
cout<<"Rs 45 for first hour or part of an hour that the car
is
illegally parked and Rs 30 for every additional hour or part of
an
hour that the car is illegally parked."<<endl;
cout<<"___________________________________________
_____________________________________"<<endl;
policeofficer officer; //Police Officer object created
string pname, pbadge;
cout<<"OFFICER'S INFORMATION ::"<<endl;
cout<<"Name: ";
cin>>pname;
cout<<"Badge Number: ";
cin>>pbadge;
officer.setname(pname);
officer.setbadgenumber(pbadge);
parkingmeter meter[10]; //Parking meter array of objects
created
parkingticket* ticket = NULL;
do //Iteration of statements
{
system("cls");
intro();
cout<<"PARKED CAR'S INFORMATION ::"<<endl; //Officer
inputs the data
of the car
string mk;
cout<<"Make :";
cin>>mk;
tck[m].setmake(mk);
int mod;
cout<<"Model :";
cin>>mod;
tck[m].setmodel(mod);
string lic;
cout<<"License number :";
cin>>lic;
y=0;
while(y<=m)
{
if (y!=m)
{
if (lic == tck[y].getlicnumber()) //License number being a
primary key
{
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Car with this License Number already
exists"<<endl;
tck[y].print();
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Try re-entering the license number :";
cin>>lic;
}
}
y++;
}
tck[m].setlicnumber(lic);
string col;
cout<<"Color :";
cin>>col;
tck[m].setcolor(col);
int parmin; //The number of minutes a car has been parked
cout<<"Minutes in parking :";
cin>>parmin;
tck[m].setminutesparked(parmin);
int purmin; //The number of minutes purchased
cout<<"Minutes purchased :";
cin>>purmin;
meter[m].setminpurchased(purmin);
system("cls");
intro();
ticket = officer.patrol(tck[m], meter[m]); //The officer
patrols
if(ticket==NULL)
{
// Display the ticket information.
tck[m].print();
cout<<endl;
cout<<endl;
cout<<"----------------------"<<endl;
cout<<"| NO CRIMES COMMITTED |"<<endl;
cout<<"----------------------"<<endl;
}
else
{
cout<<endl<<"Non-permitted vehicle
::"<<endl;
ticket->print(); // Display the ticket information.
cout<<"--------------------------------------------------------------------------------"<<endl;
ticket = NULL;
}
k[m] = tck[m].getminutesparked() -
meter[m].getminpurchased();
cout<<endl<<endl<<endl<<endl<<endl;
cout<<"___________________________________________
_____________________________________"<<endl;
cout<<"Enter your choice -"<<endl;
cout<<"0 - Patrol another car 1 - View cars
patrolled"<<endl;
choice();
}while (c == 0);
system("cls");
intro();
for(i=0;i<=m;i++)
{
cout<<" PARKED CAR
"<<i+1<<endl<<endl;
tck[i].print();
cout<<endl<<endl;
if (k[i]>0)
{
tck[i].showfine();
cout<<"--------------------------------------------------------------------------------"<<endl;
}
else
{
cout<<"Vehicle permitted for "<<-k[i]/60<<" hours
& "<<-k[i]%60<<"
minutes"<<endl;
}
cout<<"===========================================
====================================="<<endl;
}
cout<<"Officer responsible for issuing these tickets
and
patroling ::"<<endl;
officer.print();
return 0;
} // marks end of Parking Ticket Simulator
//beginning of Bank Teller Simulator example
class Customer
{
public:
// constructors
Customer (int at) {
arrivalTime! = at;
processTime = 2 + (rand() % 6);
}
Customer () : arrivalTime(0), processTime(0) { }
// operations
bool done () {
return --processTime == 0;
}
int arrival () { return arrivalTime; }
int remain() { return processTime; }
// order by arrival time
bool operator<(const Customer & c)
{ return arrivalTime < c.arrivalTime; }
// no two customers are alike
bool operator==(const Customer & c) { return false; }
// friend ops
friend ostream& operator<<(ostream&,
Customer&);
protected:
unsigned int arrivalTime;
unsigned int processTime;
};
class Teller {
public:
Teller() { // creating a new teller
free = true;
}
bool isFree() { // see if teller is free to work
if (free)
return true;
if (customer.done()) {
free = true;
cout << "\t--Customer Leaves " <<
customer << endl;
}
return free;
}
void addCustomer(Customer & c) {
// start servicing customer
customer = c;
free = false;
}
protected:
bool free;
Customer customer;
};
//driver
int numberOfTellers = 5;
int numberOfMinutes = 180;
double totalWait = 0;
int numberOfCustomers = 0;
srand(time(NULL));
vector<Teller> teller(numberOfTellers);
queue<Customer, list<Customer> > line;
// maintain simulation time
for (int time = 0; time < numberOfMinutes; time++) {
cout << "Time " << time << ":" <<
endl;
// a new customer may arrive 10% of the time each minute
if ((rand() % 10) < 1) {
Customer newCustomer(time);
line.push(newCustomer);
cout << "\t++Customer Arrives " << newCustomer <<
endl;
}
// check the status of each teller. If one is available and
// someone is waiting then they should be helped.
for (int i = 0; i < numberOfTellers; i++) {
if (teller[i].isFree() & ! line.empty()) {
Customer frontCustomer = line.front();
numberOfCustomers++;
totalWait += (time - frontCustomer.arrival());
cout << "\t**Customer serviced " <<
frontCustomer;
cout << "by teller #" << i << endl;
teller[i].addCustomer(frontCustomer);
line.pop();
}
}
}
This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...
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...
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...
Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment ===================== For this assignment you will create a set of classes from scratch (no provided class files for this assignment) that work together to simulate a police officer issuing a parking ticket. You should design the following classes / functionality within them: ===================== ParkedCar.java: ===================== This class should simulate a parked car. The class's responsibilities are as follows: - To store the car's make, model,...
This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...
using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checking a parked car issuing a parking ticket if there is a parking violation. Here are the classes that need to collaborate: • The ParkedCar class: This class should simulate a parked car. The car has a make, model, color, license number. •The ParkingMeter class: This class should simulate a parking meter. The class has three parameters: − A 5-digit...
I need help with this java project and please follow the instruction below. thank Class Project - Parking Ticket simulator Design a set of classes that work together to simulate a police officer issuing a parking ticket. Design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. • ...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...
Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...