Question

In: Computer Science

Using C++. For this assignment you will design a set of classes that work together to...

Using C++. 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 design are :

The ParkedCar class: This class should simulate a parked car. The class's responsibilities are:

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

-To know the number of minutes of parking time that has been purchased.

The ParkingTicket Class: This clas should simulate a aprking ticket. The class's responsibilities are:

-To report the make, model, color, and license number of the illegally parked car

-To report the amount of the fine,which is $25 for the first hour or part of an hour that the car is illegal parked, plus $10 for every additional hour or part of an hour that the car is illegally parked

-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. This class's responsibilities are:

-To know the police officer's name and badge number

-To examine a ParkedCar object and a ParkingMeter object, and determine whether the car's time expired

-To issue a parking ticket (generate a ParkingTicket object) if the car's time has expired

Write a program that demonstrates how these collaborate.

Solutions

Expert Solution

Below is the program for the above question statement. Go through the program and the comments to better understand the program flow and logic.

//Program to to simulate a police officer issuing a parking ticket

#include <iostream>
using namespace std;

class ParkedCar{
   //car's make, model,color ,license number,and the number of minutes that the car has been parked
   //Access specifier
    public:

    // Data Members
    string make;
    string model;
    string color;
    string license_number;
    int parked_minutes;

   };

class ParkingMeter{
   //To know the number of minutes of parking time that has been purchased.
   //Access specifier
    public:

    // Data Member
    int parking_minutes_purchased;
   };

class ParkingTicket {
   //Access specifier
    public:
  
   //To report the make, model, color, and license number of the illegally parked car
    void printcardetails(ParkedCar pc)
    {
        cout << "Car's make, model, color, and license number is given below:\n" ;
        cout << pc.make <<"\n";
        cout << pc.model<<"\n";
        cout << pc.color<<"\n";
        cout << pc.license_number<<"\n";
    }
  
   //To report the amount of the fine,which is $25 for the first hour or part of an hour that the car is illegal parked, plus $10 for every additional hour or part of an hour that the car is illegally parked
   void printfine(ParkedCar pc, ParkingMeter pm)
   {   int fine = 0;
       //calculate the fine when illegal parked time is less than or exactly one hour
       int extratime = pc.parked_minutes - pm.parking_minutes_purchased;
       if(extratime<=60)
       {
               fine = 25;
       }
       else
       { //when illegal parked time is more than an hour
               fine = 25;
               extratime = extratime - 60;
               //for every additional hour plus $10
               while(extratime>0){
                   fine = fine + 10;
                   extratime = extratime - 60;
                   }
       }
       cout << "Fine is $"<< fine ;
       cout <<"\n";          
   }
  
   //To report the name and badge number of the police officer issuing the ticket
   void printofficerdetail(string name,int number)
   {
       cout << "Officer's name : " << name;
       cout <<"\n";
       cout << "Officer's Badge number : " << number;  
       cout <<"\n";  
   }
};

class PoliceOfficer : public ParkingTicket{
   //Access specifier
    public:

    // Data Members
   //To know the police officer's name and badge number
   string officername;
   int badge_number;
  
   //To examine a ParkedCar object and a ParkingMeter object, and determine whether the car's time expired
   int examineparkedcar(ParkedCar pc, ParkingMeter pm){
       if(pc.parked_minutes <= pm.parking_minutes_purchased)
       {
           return 1;
       }
       else
           return 0;
      
       }
   //To issue a parking ticket (generate a ParkingTicket object) if the car's time has expired
   void generateticket(ParkedCar pc, ParkingMeter pm)
   {   //create an objectof Paring ticket class
       ParkingTicket pt;
       //generate the parking ticket
       pt.printcardetails(pc);
       pt.printfine(pc,pm);
       pt.printofficerdetail(officername,badge_number);
   }
};

int main()
{   
   //create object for parked car class
   ParkedCar pc;
   pc.make = "Honda";
   pc.model = "Accord";
   pc.color = "White";
    pc.license_number = "XYZ11111";
    pc.parked_minutes = 180;
    //create object for parking meter class
    ParkingMeter pm;
    pm.parking_minutes_purchased= 60;
    //create object for policeofficer class
    PoliceOfficer po;
    po.officername = "John";
    po.badge_number = 1111;
  
    //determine whether the car's time expired
    if(po.examineparkedcar(pc,pm))
    {
       cout << "Time not expired.Fine is Zero!" ;
   }
   else
   {
       cout << "Time Expired .\n" ;
       po.generateticket(pc,pm);
   }

    return 0;
}

//End of the program

Please find attached the screenshot of the program and the console output.


Related Solutions

For this assignment you will design a set of classes that work together to simulate a...
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should 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. - The ParkingMeter Class: This class should simulate a parking meter. The class's only...
Parking Ticket simulator For this assignment you will design a set of classes that work together...
Parking Ticket simulator For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are as follows: – 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....
parking Ticket simulator For this assignment you will design a set of classes that work together...
parking Ticket simulator For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are as follows: – 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....
Design a set of classes that work together to simulate a police officer issuing a parking...
Design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: The ParkedCar Class: this class should simulate a parked car. The classes' responsibilities are as the following: -to know the make, the model, 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 as follows: -to know the number...
For this assignment you will create a set of simple classes that model a cookbook. The...
For this assignment you will create a set of simple classes that model a cookbook. The cookbook will consist of set or recipes. Each recipe will consist of a set of ingredients and instructions. Your submission will consist of the below three classes and a test driver (the only class with a main()) that exercises the functionality of your system. You will need to implement the following classes based on the description of their attributes and operations: Ingredient name -...
C++ Assignment 1: Make two classes practice For each of the two classes you will create...
C++ Assignment 1: Make two classes practice For each of the two classes you will create for this assignment, create an *.h and *.cpp file that contains the class definition and the member functions. You will also have a main file 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. Class #1 Ideas for class one are WebSite, Shoes, Beer, Book, Song, Movie, TVShow, Computer, Bike, VideoGame, Car, etc Take your chosen class from...
LAUNGEG: C# Objective: For this assignment you will be creating two classes, an interface, and a...
LAUNGEG: C# Objective: For this assignment you will be creating two classes, an interface, and a driver program: Class Calculator will implement the interface CalcOps o As such it will implement hexToDec() - a method to convert from Hexadecimal to Decimal. Class HexCalc will inherit from Calculator. Interface CalcOps will have abstract methods for add( ), subtract( ), multiply( ) and divide( ). Both classes will implement the CalcOps interface. o Class Calculator’s add, subtract, multiply and divide will take...
Design a set of classes that keeps track of demographic information about a set of people,...
Design a set of classes that keeps track of demographic information about a set of people, such as age, nationality, occupation, income, and so on. Design each class to focus on a particular aspect of data collection. Assume the input data is coming from a text file. Create a main driver class to instantiate several of the classes.
Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance) Below...
Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance) Below is the code only need to add the classes and make the program run with at least one class of Polymorphism and Inheritance. CODE: #include <iostream> #include <cstdlib> #include<ctime> #include <string> using namespace std; int NUM_TRY=8; //A classic Hangman game has 8 tries. You can change if you want. int checkGuess (char, string, string&); //function to check the guessed letter void main_menu(); string message...
Developing a set of classes demonstrating inheritance - in class work
Developing a set of classes demonstrating inheritance - in class work
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT