Answer to Question #208922 in C++ for Farhan khan

Question #208922

In traditional way, there are three classes: TRUCK (number, name , NoOfWheel, Price, Capacity, EnginePower, TypeOfConsump), BUS (number, name , NoOfWheel, Price, NoOfSeat, EnginePower, TypeOfConsump, Color, Speed), CAR (number, name , NoOfWheel, Price, NoOfSeat, EnginePower, TypeOfConsump, Color, Speed). 

Divide the above three classes into two base classes and three derived classes. Each class will contain two member functions, getdata() to get that class data from user and putdata() to display that class data on the screen. How the above member data of three classes will be distributed into five classes as shown in the following diagram.


1
Expert's answer
2021-06-20T18:15:07-0400
#include <iostream>
#include <string>
using namespace std;

class NormalVehicle{
    public:
    int number, NoOfWheel, EnginePow, NoSeats, speed;
    string name, TypeOfConsumption, color;
    double price;
    void getdata(){
    };
    void putdata(){
    };  


};
class VehicleTrucks{
    public:
    int number, NoOfWheel, EnginePow;
    string name;
    string TypeOfConsumption;
    double price, capacity;
    void getdata(){
    };
    void putdata(){
    };
};

class Truck: public VehicleTrucks{
    public:
    void getdata(){
        cout<<"Enter Truck number: ";
        cin>>number;
        cout<<"Enter Truck name: ";
        cin>>name;
        cout<<"Enter Truck Number of Wheels: ";
        cin>>NoOfWheel;
        cout<<"Enter Truck Engine Power: ";
        cin>>EnginePow;
        cout<<"Enter Truck type of Consumption: ";
        cin>>TypeOfConsumption;
        cout<<"Enter Truck price: ";
        cin>>price;
    };
    void putdata(){
        cout<<"Truck Number:       "<<number<<endl;
        cout<<"Truck Name:         "<<name<<endl;
        cout<<"Number of wheels:   "<<NoOfWheel<<endl;
        cout<<"Truck Consumption:  "<<TypeOfConsumption<<endl;
        cout<<"Truck Engine Power: "<<EnginePow<<endl;
        cout<<"Truck Capacity:     "<<capacity<<endl;
        cout<<"Truck Price:        "<<price<<endl;
    };
};
class Bus: public NormalVehicle{
    public:
    void getdata(){
        cout<<"Enter Bus number: ";
        cin>>number;
        cout<<"Enter Bus name: ";
        cin>>name;
        cout<<"Enter Bus Number of Wheels: ";
        cin>>NoOfWheel;
        cout<<"Enter Bus Number of Seats: ";
        cin>>NoSeats;
        cout<<"Enter Bus Engine Power: ";
        cin>>EnginePow;
        cout<<"Enter Bus type of Consumption: ";
        cin>>TypeOfConsumption;
        cout<<"Enter Bus price: ";
        cin>>price;
        cout<<"Enter Bus Top speed: ";
        cin>>speed;
        cout<<"Enter Bus color: ";
        cin>>color;
    };
    void putdata(){
        cout<<"Bus Number:       "<<number<<endl;
        cout<<"Bus Name:         "<<name<<endl;
        cout<<"Number of wheels: "<<NoOfWheel<<endl;
        cout<<"Bus Consumption:  "<<TypeOfConsumption<<endl;
        cout<<"Bus Seats:        "<<NoSeats<<endl;
        cout<<"Bus Engine Power: "<<EnginePow<<endl;
        cout<<"Bus Price:        "<<price<<endl;
        cout<<"Bus Speed:        "<<speed<<endl;
        cout<<"Bus Color:        "<<color<<endl;
    };
};
class Car: public NormalVehicle{
    public:
    void getdata(){
        cout<<"Enter CarCar number: ";
        cin>>number;
        cout<<"Enter Car name: ";
        cin>>name;
        cout<<"Enter Car Number of Wheels: ";
        cin>>NoOfWheel;
        cout<<"Enter Car Number of Seats: ";
        cin>>NoSeats;
        cout<<"Enter Car Engine Power: ";
        cin>>EnginePow;
        cout<<"Enter Car type of Consumption: ";
        cin>>TypeOfConsumption;
        cout<<"Enter Car price: ";
        cin>>price;
        cout<<"Enter Car Top speed: ";
        cin>>speed;
        cout<<"Enter Car color: ";
        cin>>color;
    };
    void putdata(){
        cout<<"CarCar Number:    "<<number<<endl;
        cout<<"Car Name:         "<<name<<endl;
        cout<<"Number of wheels: "<<NoOfWheel<<endl;
        cout<<"Car Consumption:  "<<TypeOfConsumption<<endl;
        cout<<"Number of seats:  "<<NoSeats<<endl;
        cout<<"Car Engine Power: "<<EnginePow<<endl;
        cout<<"Car Price:        "<<price<<endl;
        cout<<"Car Speed:        "<<speed<<endl;
        cout<<"Car Color:        "<<color<<endl;
    };
};
int main() {
    Truck t;
    Bus b;
    Car c;
    t.getdata();
    t.putdata();
    b.getdata();
    b.putdata();
    c.getdata();
    c.putdata();
    return 0;
}

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
APPROVED BY CLIENTS