Question

This is assignment and code from this site but it will not compile....can you help? home...

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 will simulate a police officer’s beat where the officer is giving out tickets for parked cars whose meters have expired.

The following are the list of classes required for the program and the interaction between them. 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 completely test the interactions of all the classes and all of the method required. The main below shows and example of how the program should work. This is not a complete main for the program.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.

#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;
}

View comments (1)

Expert Answer

  • vermafvermaf answered this

    Was this answer helpful?

    1

    0

    316 answers


    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;
    }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
// FILL IN THE CODE TO DECLARE A CLASS CALLED Square. TO DO THIS SEE
// THE IMPLEMENTATION SECTION.
class Square
{
private:
//float length;
float side;
public:
Square(float side);
Square();
~Square();
void SetSide(float);
float findArea();
float findPerimeter();
};
int main()
{
Square box1(9);
Square box; // box is defined as an object of the Square class
float size; // size contains the length of a side of the square
//cout << "Please input the length of the side of the square "; // FILL IN THE CLIENT CODE THAT WILL ASK THE USER FOR THE LENGTH OF THE SIDE
//cin >> size; // OF THE SQUARE. (This is stored in size)
//box1.SetSide(size); // FILL IN THE CODE THAT CALLS SetSide.
float Area = box1.findArea(); // FILL IN THE CODE THAT WILL RETURN THE AREA FROM A CALL TO A FUNCTION
cout << "\nThe area of the square is " << Area << endl; // AND PRINT OUT THE AREA TO THE SCREEN
float peri = box1.findPerimeter(); // FILL IN THE CODE THAT WILL RETURN THE PERIMETER FROM A CALL TO A
cout << "The perimeter of the square is " << peri << endl; // FUNCTION AND PRINT OUT THAT VALUE TO THE SCREEN
char ch; // Used for output
std::cin >> ch;
return 0;
}
// Implementation section Member function implementation
//__________________________________________________________________
//*************************************************************
// Square Constructor
//
// task: This member function of the class Square creates a constructor that sets the length equal to side_1.
// data in: None (uses default value of 1)
// data out: Declaration of length set to 9
//
//*******************************************************************
Square::Square(float side)
{
this->side = side;
}
//*******************************************************************
// Square Default Constructor
//
// task: This function of the class Square is the default constructor that sets the of Square to 1
//
// data in: None
// data out: Length is declared as side and set to default value of 1.
//*******************************************************************
Square::Square()
{
side = 1;
}
//*************************************************************
// Square Destructor
//
// task: Reclaim memory space
// data in: Data for Square in the Square class
// data out: none, object destroyed
//**************************************************************8
Square::~Square()
{
}
//**************************************************
// setSide
//
// task: This procedure takes the length of a side and
// places it in the appropriate member data
// data in: length of a side
//***************************************************
void Square::SetSide(float length)
{
side = length;
}
//**************************************************
// findArea
//
// task: This finds the area of a square
// data in: none (uses value of data member side)
// data returned: area of square
//***************************************************
float Square::findArea()
{
return side * side;
}
//**************************************************
// findPerimeter
//
// task: This finds the perimeter of a square
// data in: none (uses value of data member side)
// data returned: perimeter of square
//***************************************************
float Square::findPerimeter()
{
return 4 * side;
}

Add a comment
Know the answer?
Add Answer to:
This is assignment and code from this site but it will not compile....can you help? home...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    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...

  • Parking Ticket Simulator C++ HELP PLEASE

    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...

  • I need help with this java project and please follow the instruction below. thank Class Project...

    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. •          ...

  • Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment =====================...

    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,...

  • PART TWO Write a program which will populate an integer ArrayList with user input, and then...

    PART TWO Write a program which will populate an integer ArrayList with user input, and then provide a menu of various operations to perform on that ArrayList. The first step is to have the user push a bunch of integers into a ArrayList. The second step is to perform various operations on that ArrayList. Your input must be in the format below. The user can enter either a positive integer or -99 to quit. The menu to present is: Sum...

  • in java PART ONE ================================================== Write a program that will read employee earnings data from an...

    in java PART ONE ================================================== Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read. You will want to use parallel arrays for this program. Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array....

  • using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checkin...

    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...

  • Please Implement ParkingLot.cpp below based off the completed Automobile Class and ClaimCheck class down below. Automobile.hpp...

    Please Implement ParkingLot.cpp below based off the completed Automobile Class and ClaimCheck class down below. Automobile.hpp #pragma once #include <iostream> #include <string> class Automobile { friend bool operator==( const Automobile& lhs, const Automobile& rhs ); friend std::ostream & operator<<( std::ostream& stream, const Automobile& vehicle ); private: std::string color_; std::string brand_; std::string model_; std::string plateNumber_; public: Automobile( const std::string & color, const std::string & brand, const std::string & model, const std::string & plateNumber ); }; bool operator!=( const Automobile& lhs, const...

  • A library maintains a collection of books. Books can be added to and deleted from and...

    A library maintains a collection of books. Books can be added to and deleted from and checked out and checked in to this collection. Title and author name identify a book. Each book object maintains a count of the number of copies available and the number of copies checked out. The number of copies must always be greater than or equal to zero. If the number of copies for a book goes to zero, it must be deleted from the...

  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT