Hi, I need somehelp with the code for programming challenge beloww in c++ that s
ID: 3773112 • Letter: H
Question
Hi, I need somehelp with the code for programming challenge beloww in c++ that should be executable in visual studio. thanks for your assistance.
Design the following set of classes so that they work together to simulate a police officer issuing a parking ticket. · 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 of minutes of parking time that has been purchased · The ParkingTicket Class: This class should simulate a parking ticket. The class’s responsibilities are: o To report the make, model, color, and license number of the illegally parked car o To report the amount of the fine, which is $25 for the first hour or part of an hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is illegally parked o To report the name and badge number of the police officer issuing the ticket · The PoliceOfficer Class: This class should simulate a police officer inspecting parked cars. The class’s responsibilities are: o To know the police officer’s name and badge number o To examine a ParkedCar object and a ParkingMeter object, and determine whether the car’s time has expired o To issue a parking ticket (generate a ParkingTicket object) if the car’s time has expired Write a program that demonstrates how these classes collaborate.
Explanation / Answer
Answer:
Program code to copy:
#include "stdafx.h"
#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;
string model;
string color;
string licnumber;
int minutesparked;
public:
ParkedCar()
{
make=" ";
model=" ";
licnumber=" ";
color=" ";
minutesparked=0;
}
void setmake(string mk)
{
make=mk;
}
void setmodel(string 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);
}
string getmodel() const
{
return (model);
}
string getcolor() const
{
return (color);
}
string getlicnumber() const
{
return (licnumber);
}
int getminutesparked() const
{
return (minutesparked);
}
void print();
};
void ParkedCar::print() //outside class definition
{
cout<<"Car Make :"<<getmake()<<endl;
cout<<"Car Model :"<<getmodel()<<endl;
cout<<"Car Color :"<<getcolor()<<endl;
cout<<"Car License Number :"<<getlicnumber()<<endl;
cout<<"Number of minutes the car parked: "<<getminutesparked()<<endl;
}
class ParkingMeter
{
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 ParkingTicket: public ParkedCar
{
int fine;
int minutes;
void calfine();
public:
void showfine();
void getticket (int min)
{
minutes=min;
calfine();
cout<<endl;
}
int getfine() const
{
return(fine);
}
};
void ParkingTicket::calfine()
{
if(minutes/60<=0)
{
fine = 45;
}
else
{
int mn;
mn = minutes - 60;
fine = 45 + 30 + 30*(mn/60);
}
}
void ParkingTicket::showfine()
{
cout<<" ILLEGAL PARKING"<<endl;
cout<<" Time in violation is "<<minutes/60<<" hours & "<<minutes%60<<" minutes "<<endl;
cout<<" Fine : Rs. "<<getfine()<<endl;
}
ParkingTicket tck[10];
class policeofficer
{
string name;
string badgenumber;
ParkingTicket *ticket;
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)
{
if ( pc1.getminutesparked() < pc2.getminpurchased() ||
pc1.getminutesparked() == pc2.getminpurchased() )
{
return NULL;
}
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 isillegally parked and Rs 30 for every additional hour or part of an hour that the car is illegally parked."<<endl;
cout<<"___________________________________________"<<endl;
policeofficer officer;
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];
ParkingTicket* ticket = NULL;
do
{
system("cls");
intro();
cout<<"PARKED CAR'S INFORMATION ::"<<endl;
string mk;
cout<<"Make :";
cin>>mk;
tck[i].setmake(mk);
string mod;
cout<<"Model :";
cin>>mod;
tck[i].setmodel(mod);
string lic;
cout<<"License number :";
cin>>lic;
y=0;
while(y<=m)
{
if (y!=m)
{
if (lic == tck[y].getlicnumber())
{
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[i].setlicnumber(lic);
string col;
cout<<"Color :";
cin>>col;
tck[i].setcolor(col);
int parmin; //The number of minutes a car has been parked
cout<<"Minutes in parking :";
cin>>parmin;
tck[i].setminutesparked(parmin);
int purmin; //The number of minutes purchased
cout<<"Minutes purchased :";
cin>>purmin;
meter[i].setminpurchased(purmin);
system("cls");
intro();
ticket = officer.patrol(tck[i], meter[i]); //The officer patrols
if(ticket==NULL)
{
// Display the ticket information.
tck[i].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[i] = tck[i].getminutesparked() - meter[i].getminpurchased();
cout<<endl<<endl<<endl;
i++;
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 andpatroling ::"<<endl;
officer.print();
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.