Question

In: Computer Science

Code should be written in C++ using Visual Studios Community This requires several classes to interact...

Code should be written in C++ using Visual Studios Community

This requires several classes to interact with each other. Two class aggregations are formed. The program will simulate a police officer giving out tickets for parked cars whose meters have expired.

You must include both a header file and an implementation file for each class.

Car class (include Car.h and Car.cpp) Contains the information about a car.

  • Contains data members for the following
    • String make
    • String model
    • String color
    • String license number
  • Default constructor
  • Mutators and accessors for all data members
  • Overload the << operator.

ParkedCar class (include ParkedCar.cpp ParkedCar.h) simulates a parked car. Knows which type of car is parked and the number of minutes that the car has been parked.

  • Contains data members for the following
    • Car (instance of the class above)
    • Integer minutes parked.
  • Default constructor
  • Constructor (5 parameters)
  • Copy constructor
  • Mutators and accessors for data members other than Car
  • Overload the << operator

ParkingMeter class (include ParkingMeter.h and ParkingMeter.cpp) simulates a parking meter. Should know the number of minutes of parking time that has been purchased.

  • Contains data members for the following
    • Integer minutes purchased to park
  • Default constructor
  • Constructor (1 parameter)
  • Mutator and accessor for data member
  • Overload the << operator

ParkingTicket class (include ParkingTicket.h and ParkingTicket.cpp) simulates a parking ticket.

  • Responsibilites are:
    • Report the car information for illegally parked car
    • Report the amount of 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
  • Contains data members for the following
    • ParkedCar instance of class above
    • Double fine – the calculated parking fine
    • Int minutes – the minutes illegally parked
  • Default constructor
  • Constructor (2 parameter – ParkedCar and integer)
  • Mutator and accessor for all data member
  • Overload the << operator
  • Private method to calculate the fine

PoliceOfficer class (include PoliceOffier.h and PoliceOfficer.cpp)

  • Responsibilites are:
    • Know the name and badge number of the officer
    • Examine a ParkedCar object and a ParkingMeter object and determine whether the car’s time has expired
    • Issue a parking ticket (create a ParkingTicket) if the car’s time has expired
  • Contains data members for the following
    • ParkingTicket pointer to an instance of class above
    • String name of officer
    • String badge number of officer
  • Default constructor (correctly initialize all data members)
  • Constructor (2 parameter – name and badge number, all data member initialized correctly)
  • Mutator and accessor for all data member (not ParkingTicket)
  • Overload the << operator
  • Method called patrol which issues (returns) ParkingTicket as a pointer. Has two parameters ParkedCar and ParkingMeter.

Main should test the interactions of all the classes. The main example below is how the program should work. This is not a complete main. The program should have a car that is not given a ticket, one with a ticket within an hour and another for more than one hour.

EXAMPLE

#include 
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "ParkingTicket.h"
#include "PoliceOfficer.h"
using namespace std;

int main()
{
   ParkingTicket *ticket = nullptr;
   ParkedCar car("Volkswagen", "1972", "Red", "147RHZM", 125);
   ParkingMeter meter(60);
   PoliceOfficer officer("Joe Friday", "4788");
   ticket = officer.patrol(car, meter);
   if (ticket != nullptr)
   {
      cout << officer;
      cout << *ticket;

      delete ticket;
      ticket = nullptr;
   }
   else
      cout << "No crimes were committed.\n";

   return 0;
}

Solutions

Expert Solution

car.h
#pragma once
#include<iostream>
using namespace std;
class Car {
#pragma region Data Members
string _make, _model, _color, _licenseNumber;
#pragma endregion
public:
#pragma region functions
//setters
void setMake(string make);
void setModel(string model);
void setColor(string color);
void setLicenseNum(string licenseNumber);
//getters
string getMake();
string getModel();
string getColor();
string getLicenseNumber();
//constructor
Car();
//operator overloading
friend ostream& operator<<(ostream&,Car);
#pragma endregion
};
car.cpp
#include"Car.h"
#include<iostream>
#include<string>
#define MakeSize 10
using namespace std;

//setters
void Car::setMake(string make){ this->_make = make;}
void Car::setModel(string model){this->_model = model;}
void Car::setColor(string color){this->_color = color;}
void Car::setLicenseNum(string licenseNumber) { this->_licenseNumber = _licenseNumber; }

//getters
string Car::getMake() { return this->_make; }
string Car::getModel() { return this->_model; }
string Car::getColor() { return this->_color; }
string Car::getLicenseNumber() { return this->_licenseNumber; }

//constructor
Car::Car(){
this->_color = "";
this->_licenseNumber = "";
this->_make = "";
this->_model = "";
}
//operator overloading
ostream& operator<<(ostream& out,Car car) {
out << "Make : " + car.getMake() << endl;
out << "Model : " + car.getModel() << endl;
out << "Color : " + car.getColor() << endl;
out << "License Number : " + car.getLicenseNumber() << endl;
return out;
}
parkedcar.h
#pragma once
#include<iostream>
#include"Car.h"
class ParkedCar
{
int _minutes;
Car _car;
public:
//setters
void setCar(Car);
void setMinutes(int);
//getters
int getMinutes();
Car getCar();
//constructors
ParkedCar();
ParkedCar(string, string, string, string, int);
ParkedCar(const ParkedCar&);
//operator overloading
friend ostream& operator<<(ostream&,ParkedCar);
};

parkedcar.cpp
#include "ParkedCar.h"
using namespace std;
//setters
void ParkedCar::setMinutes(int min) { this->_minutes = min; }
void ParkedCar::setCar(Car car) { this->_car = car; }
//getters
int ParkedCar::getMinutes() { return this->_minutes; }
Car ParkedCar::getCar() { return this->_car; }
//constructors
ParkedCar::ParkedCar(){
this->_minutes = 0;
}
ParkedCar::ParkedCar(string carMake, string carModel, string carColor, string carLicense, int minParked) {
this->_car.setMake(carMake);
this->_car.setModel(carModel);
this->_car.setColor(carColor);
this->_car.setLicenseNum(carLicense);
this->_minutes = minParked;
}
ParkedCar::ParkedCar(const ParkedCar& parkedCar) {
// no hints are given for woorking of copy constructor
}
//operator overloading
ostream& operator<<(ostream& out, ParkedCar car) {
out << car;
out << "minutes : " + car.getMinutes()<<endl;
return out;
}
parkingmeter.h
#pragma once
#include<iostream>
using namespace std;
class ParkingMeter
{
int _minPurchased;
public:
//setter
void setMinPurchased(int);
//getter
int getMinPurchased();
//constructors
ParkingMeter();
ParkingMeter(int);
//operator overloading
friend ostream& operator<<(ostream&, ParkingMeter);
};

parkingmeter.cpp
#include "ParkingMeter.h"
#include<iostream>
using namespace std;
//setter
void ParkingMeter::setMinPurchased(int minPurchase) { this->_minPurchased = minPurchase; }
//getter
int ParkingMeter::getMinPurchased() { return this->_minPurchased; }
//constructors
ParkingMeter::ParkingMeter(){
this->_minPurchased = 0;
}
ParkingMeter::ParkingMeter(int minPurchase) { this->_minPurchased = minPurchase; }
//operator overloading
ostream& operator<<(ostream& out, ParkingMeter meter)
{
out << "Parking Minutes purchased : " + meter.getMinPurchased() << endl;
return out;
}

parkingticket.h
#pragma once
#include"ParkedCar.h"
class ParkingTickets
{
ParkedCar _parkedCar;
double _fine;
int _min;
double _calculateFine();
public:
//setters
void setParkedCar(ParkedCar);
void setFine(double);
void setMinIllegalParkingTime(int);
//getters
ParkedCar getParkedCar();
double getFine();
int getIllegalMin();
//constructors
ParkingTickets();
ParkingTickets(ParkedCar, int);
//operator overloading
friend ostream& operator<<(ostream&,ParkingTickets);
};
parkingtickets.cpp
#include "ParkingTickets.h"


double ParkingTickets::_calculateFine(){
int temp = 0;
//for first hour
this->_fine = 25;
temp %= 60;
while (temp > 0) {
this->_fine += 10;
temp %= 60;
}
return temp;
}
//setters
void ParkingTickets::setParkedCar(ParkedCar car) { this->_parkedCar = car; }
void ParkingTickets::setFine(double fine) { this->_fine = fine; }
void ParkingTickets::setMinIllegalParkingTime(int min) { this->_min = min; }
//getters
ParkedCar ParkingTickets::getParkedCar() { return this->_parkedCar; }
double ParkingTickets::getFine() { return this->_fine; }
int ParkingTickets::getIllegalMin() { return this->_min; }
//constructors
ParkingTickets::ParkingTickets(){
this->_fine = 90;
this->_min = 0;
}
ParkingTickets::ParkingTickets(ParkedCar car, int min) {
this->_parkedCar = car;
this->_min = min;
}
//operator overloading
ostream& operator<<(ostream& out, ParkingTickets ticket) {
out << ticket.getParkedCar() << endl;
out << "Illegal minutes : " + ticket.getIllegalMin() << endl;
out << "Fine : " << ticket.getFine() << endl;
return out;
}

policeofficer.h
#pragma once
#include<iostream>
#include"ParkingTickets.h"
#include"ParkingMeter.h"
using namespace std;
class PoliceOfficer
{
string _name, _badge;
ParkingTickets *_ticket;

public:
//setters
void setName(string);
void setBadge(string);
//getters
string getName();
string getBadge();
ParkingTickets* Patrol(ParkedCar,ParkingMeter);
//constructor
PoliceOfficer();
PoliceOfficer(string, string);
//operator overloading
friend ostream& operator<<(ostream&,PoliceOfficer);
};
policeofficer.cpp
#include "PoliceOfficer.h"
#include<string>

//setters
void PoliceOfficer::setName(string name) { this->_name = name; }
void PoliceOfficer::setBadge(string badge) { this->_badge = badge; }
//getters
string PoliceOfficer::getName() { return this->_name; }
string PoliceOfficer::getBadge() { return this->_badge; }
ParkingTickets* PoliceOfficer::Patrol(ParkedCar car, ParkingMeter meter) {
if (meter.getMinPurchased() <= car.getMinutes())//if time is expire, issue new ticket
this->_ticket = new ParkingTickets(car,meter.getMinPurchased());//this will double the purchased time of the car
return this->_ticket;
}
//constructor
PoliceOfficer::PoliceOfficer() { this->_name = ""; this->_badge = ""; }
PoliceOfficer::PoliceOfficer(string name, string badge) {
this->_name = name;
this->_badge = badge;
}
//operator overloading
ostream& operator<<(ostream &out,PoliceOfficer officer) {
out << "Name : "+officer.getName() << endl;
out << "Enter Badge : "+ officer.getBadge() << endl;
return out;
}

main
#include <iostream>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "ParkingTickets.h"
#include "PoliceOfficer.h"
using namespace std;
int main()
{
ParkingTickets *ticket = nullptr;
ParkedCar car("Volkswagen", "1972", "Red", "147RHZM", 125);
ParkingMeter meter(60);
PoliceOfficer officer("Joe Friday", "4788");
ticket = officer.Patrol(car, meter);
if (ticket != nullptr)
{
cout << officer;
cout << *ticket;
delete ticket;
ticket = nullptr;
}
else
cout << "No crimes were committed.\n";
system("pause");
return 0;
}


Related Solutions

Program is to be written in C++ using Visual studios Community You are to design a...
Program is to be written in C++ using Visual studios Community You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be one class that is the CD/DVD/Blu-ray. The CD...
Must be written in C++ in Visual studios community In this lab, you will modify the...
Must be written in C++ in Visual studios community In this lab, you will modify the Student class you created in a previous lab. You will modify one new data member which will be a static integer data member. Call that data member count. You also add a static method to the Student class that will display the value of count with a message indicating what the value represents, meaning I do not want to just see a value printed...
I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and...
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and screenshots 1. Boxes for first name, last name, address. 2. Radio buttons to select: hard cover, soft cover, ebook. 3. Drop down list to select the book (make up three or four book names). 4. Radio buttons to select credit card (at least Visa, Master Card, American Express). 5. Box to enter credit card numbers. 6. The credit card box MUST verify that numbers...
The code should be written in c++. It should be in only OpenGL // ***** ONLY...
The code should be written in c++. It should be in only OpenGL // ***** ONLY OpenGL PLEASE ******// write a program snippet that accepts the coordinates of the vertices of a rectangle centered around the origin, with edges that are parallel to the X and Y axes, and with aspect ratio W and converts it into a rectangle centered around the origin with aspect ratio of 1/W. The program has to figure W from the given points. You MUST...
Create a C++ code for the mastermind game using classes(private classes and public classes). Using this...
Create a C++ code for the mastermind game using classes(private classes and public classes). Using this uml as a reference.
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that...
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that serves as a healthcare billing management system. This application is a multiform project (Chapter 9) with three buttons. The "All Accounts" button allows the user to see all the account information for each patient which is stored in an array of class type objects (Chapter 9, section 9.4).The "Charge Service" button calls the Debit method which charges the selected service to the patient's account...
Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each...
Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election hold the names of the subdivision hold the vote counts in the Brampton subdivision for each candidate hold the vote counts in the Pickering subdivision for each candidate hold the vote counts in the Markham subdivision for each candidate Use the data from the example below. Your C program should take the...
Use C++ please Implement the following exercise on Visual Studios and submit the necessary (.h and...
Use C++ please Implement the following exercise on Visual Studios and submit the necessary (.h and .cpp) files in a .zip folder 1.   Create a class NumberType such that it has the following functionality: The draw function in NumberType only prints 'this is an empty function' message. Create a class NumberOne (derived from NumberType) which in the draw function prints the number using a 5(rows)x3(columns) matrix. See example at https://www.istockphoto.com/vector/led-numbers-gm805084182-130563203 * * * * * Similarly create a class NumberTwo...
DEVELOP IN VISUAL STUDIOS C++ PLEASE 1. Develop a main program that does the following a)...
DEVELOP IN VISUAL STUDIOS C++ PLEASE 1. Develop a main program that does the following a) Create six nodes of integers such as n0, n1, n2, n3, n4, n5 (n0 is the head) b) Assign data to each nodes such as n1->data = 2; n2->data = 5, n3->data = 3, n4->data = 10, n5->data = 1. c) Make n0 ->next to point to n1, and n0->prev to point to NULL 2.) Print out the content of list you have created...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT