Answer to Question #199793 in C++ for sayyam butt

Question #199793

Make following classes into code. Write Getter and Setters for all members mentioned in brackets of each class, write Copy Constructor, Constructor and Destructor for each class.



class Car (Make, Model, Type, Passengers, WheelSize, ManualAuto)

class SportsCar (EngineType, Torque, Time_Zeroto60, Acceleration, TopSpeed) inherit SportsCar from Car

class Person (Name, Gender, Age, Nationality, CNIC)

  1. class Driver(Experience, Car, WinCount), inherit Driver from Person
1
Expert's answer
2021-05-27T23:11:55-0400
#include <iostream>
#include <string>
using namespace std;
class Car{
    protected:
    string Make, Model, Type, ManualAuto;
    int Passengers, Wheelsize;
    public:
    Car(){}
    void Set(string make, string model, string type, int passengers, int wheelsize, string manualauto){
        Make = make;
        Model = model;
        Type = type;
        Passengers = passengers;
        Wheelsize = wheelsize;
        ManualAuto = manualauto;
    }
    void Get(){
        cout<<"Make: "<<Make<<endl;
        cout<<"Model: "<<Model<<endl;
        cout<<"Type: "<<Type<<endl;
        cout<<"Passengers: "<<Passengers<<endl;
        cout<<"Wheelsize: "<<Wheelsize<<endl;
        cout<<"ManualAuto: "<<ManualAuto<<endl;
    }
    Car(Car &other){
        this->Model = other.Model;
        this->Make = other.Make;
        this->Type = other.Type;
        this->Passengers = other.Passengers;
        this->Wheelsize = other.Wheelsize;
        this->ManualAuto = other.ManualAuto;
    }
    ~Car(){}
};
class SportsCarpublic Car{
    string EngineType;
    float Torque, Time_zeroto60, Acceleration, TopSpeed;
    public:
    SportsCar(): Car(){}
    void Set(string make, string model, string type, int passengers, int wheelsize, string manualauto, 
            string engineType, float torque, float time_zeroto60, float acceleration, float topSpeed){
        Make = make;
        Model = model;
        Type = type;
        Passengers = passengers;
        Wheelsize = wheelsize;
        ManualAuto = manualauto;
        EngineType = engineType;
        Torque = torque;
        Time_zeroto60 = time_zeroto60;
        Acceleration = acceleration;
        TopSpeed = topSpeed;
    }
    virtual void Get(){
        Car::Get();
        cout<<"Torque: "<<Torque<<endl;
        cout<<"Time zero to 60: "<<Time_zeroto60<<endl;
        cout<<"Acceleration: "<<Acceleration<<endl;
        cout<<"TopSpeed: "<<TopSpeed<<endl;
    }
};
class SportsCarpublic Car{
    string EngineType;
    float Torque, Time_zeroto60, Acceleration, TopSpeed;
    public:
    SportsCar(): Car(){}
    void Set(string make, string model, string type, int passengers, int wheelsize, string manualauto, 
            string engineType, float torque, float time_zeroto60, float acceleration, float topSpeed){
        Make = make;
        Model = model;
        Type = type;
        Passengers = passengers;
        Wheelsize = wheelsize;
        ManualAuto = manualauto;
        EngineType = engineType;
        Torque = torque;
        Time_zeroto60 = time_zeroto60;
        Acceleration = acceleration;
        TopSpeed = topSpeed;
    }
    void Get(){
        Car::Get();
        cout<<"Engine Type: "<<EngineType<<endl;
        cout<<"Torque: "<<Torque<<endl;
        cout<<"Time zero to 60: "<<Time_zeroto60<<endl;
        cout<<"Acceleration: "<<Acceleration<<endl;
        cout<<"TopSpeed: "<<TopSpeed<<endl;
    }
    SportsCar(SportsCar &other){
        this->Model = other.Model;
        this->Make = other.Make;
        this->Type = other.Type;
        this->Passengers = other.Passengers;
        this->Wheelsize = other.Wheelsize;
        this->ManualAuto = other.ManualAuto;
        this->EngineType = other.EngineType;
        this->Torque = other.Torque;
        this->Time_zeroto60 = other.Time_zeroto60;
        this->Acceleration = other.Acceleration;
        this->TopSpeed = other.TopSpeed;
    }
    ~SportsCar(){}
};
class Person{
    protected:
    string Name, Nationality;
    char Gender;
    int Age, CNIC;
    public:
    Person(){}
    void Set(string name, string nationality, int age, int cnic, char gender){
        Name = name;
        Nationality = nationality;
        Age = age;
        CNIC = cnic;
        Gender = gender;
    }
    void Get(){
        cout<<"Name: "<<Name<<endl;
        cout<<"Age: "<<Age<<endl;
        cout<<"Nationality: "<<Nationality<<endl;
        cout<<"Gender: "<<Gender<<endl;
        cout<<"CNIC: "<<CNIC<<endl;
    }
    Person(Person &other){
        this->Age = other.Age;
        this->Name = other.Name;
        this->Nationality = other.Nationality;
        this->CNIC = other.CNIC;
        this->Gender = other.Gender;
    }
    ~Person(){}
};
class Driverpublic Person{
    int Experience, Wincount;
    Car *car;
    public:
    Driver(): Person(){}
    void Set(string name, string nationality, int age, int cnic, char gender, Car* ca, int exp, int wnc){
        Person::Set(name, nationality, age, cnic, gender);
        Experience = exp;
        Wincount = wnc;
        car = ca;
    }
    void Get(){
        Person::Get();
        cout<<"Experience: "<<Experience<<endl;
        cout<<"Wincount: "<<Wincount<<endl;
        car->Get();
    }
    Driver(Driver &other){
        this->Age = other.Age;
        this->Name = other.Name;
        this->Nationality = other.Nationality;
        this->CNIC = other.CNIC;
        this->Gender = other.Gender;
        this->Experience = other.Experience;
        this->Wincount = other.Wincount;
        this->car = other.car;
    }
    ~Driver(){
        delete this->car;
    }
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog