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

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...
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...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
C++ Code! This code was written/implemented using the "class format." How would I go about in...
C++ Code! This code was written/implemented using the "class format." How would I go about in converting it to the "struct format?" #include <iostream> #include <iomanip> using namespace std; class ListNode{ public: string course_name; string course_number; string course_room; ListNode* next; ListNode(){ this->next = NULL; } ListNode(string name, string number, string room){ this->course_name = name; this->course_number = number; this->course_room = room; this->next = NULL; } }; class List{ public: ListNode* head; List(){ this->head = NULL; } void insert(ListNode* Node){ if(head==NULL){ head...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i <= 0) { cout << "!"; --i; }
Using C++, Right down a code that calculates insuranceprice:* requires driver to enter their...
Using C++, Right down a code that calculates insurance price:* requires driver to enter their age and the amounts of accidents they have hadbased on that:*base price is $500*additional fees of $100 if driver is younger than 25*additional fees based on accidents:number of accidentsfees of accidents15021253225437555756 or moreno insurance*Use switch*if had 6 or more accidents won't be able to get insurance
ASSEMBLY X86, using VISUAL STUDIOS 2019 Please follow ALL directions! Write a program that calculates and...
ASSEMBLY X86, using VISUAL STUDIOS 2019 Please follow ALL directions! Write a program that calculates and printout the first 6 Fibonacci numbers.   Fibonacci sequence is described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). (sequence 0 1 1 2 3 5 8 13 21 34 ...) Have your program print out "The first six numbers in the Fibonacci Sequence are". Then the numbers should be neatly printed out, with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT