Create a base class called Vehicle that has the manufacturer\'s name (string), n
ID: 3757310 • Letter: C
Question
Create a base class called Vehicle that has the manufacturer's name (string), number of cylinders in the engine (int) and owner (type Person class). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (double) and towing capacity in pounds (int). Be sure your classes have a reasonable complement of constructors, accessor and mutator member functions. Person class has a private member name (string) and the following public methods: no-arg constructor, constructor passing name as a string, getName returning string. Define Car class that is derived from the Vehicle class. Define a class called SportCar that is derived from Car class. Choose the appropriate member variables and methods. Write a driver program that test all your member functions Answer in java
Explanation / Answer
ANSWER :
#include<iostream>
using namespace std;
class Person{
string name;
public:
Person();
Person(string theName){
name=theName;
}
Person(const Person&theObject){
this->name=theObject.name;
}
string getName(){
return this->name;
}
Person & operator=(const Person &rtSide){
Person newperson;
newperson.name=rtSide.name;
return newperson;
}
friend istream & operator >>(istream & inStream,Person &personobject){
cout<<"Enter person name : ";
inStream >> personobject.name;
return inStream;
}
friend ostream & operator <<(ostream & outStream,Person &personobject){
outStream<<"Enter person name : "<<personobject.name<<" ";
return outStream;
}
};
class vehicle{
protected: string manufacturer;
int cylinder;
Person person;
public :vehicle();
vehicle(string m,int c,Person p ){
manufacturer=m;
c=cylinder;
person=p;
}
void setManufacturer(string m){
manufacturer=m;
}
void setCylinder(int n){
cylinder=n;
}
void setPerson(Person p){
person=p;
}
string getManufacturer(){
return manufacturer;
}
int getCyliner(){
return cylinder;
}
Person getPerson(){
return person;
}
};
class Truck:public vehicle{
double load;
public:
Truck():vehicle(){
}
Truck(string m,int c,Person p,double l):vehicle(m,c,p){
load=l;
}
Truck(const Truck &t){
this->load=t.load;
this->manufacturer=t.manufacturer;
this->cylinder=t.cylinder;
this->person=t.person;
}
Truck & operator = (const Truck & t){
Truck newtruck;
newtruck.cylinder=t.cylinder;
newtruck.manufacturer=t.manufacturer;
newtruck.person=t.person;
newtruck.load=t.load;
return newtruck;
}
void setLoad(double l){
this->load=l;
}
double getload(){
return load;
}
};