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)
class Driver(Experience, Car, WinCount), inherit Driver from Person.
Display all classes.show output into screen.
#include<iostream>
#include<cstring>
using namespace std;
class Car
{
string make,model,type,geartype;
int passengers;
float wheelsize;
public:
void setmake(string make)
{
this->make=make;
}
void setmodel(string model)
{
this->model=model;
}
void settype(string type)
{
this->type=type;
}
void setgeartype(string geartype)
{
this->geartype=geartype;
}
void setpassengers(int passengers)
{
this->passengers=passengers;
}
void setwheelsize(float wheelsize)
{
this->wheelsize=wheelsize;
}
string getmake() const
{
return make;
}
string getmodel() const
{
return model;
}
string gettype() const
{
return type;
}
string getgeartype() const
{
return geartype;
}
int getpassengers() const
{
return passengers;
}
float getwheelsize() const
{
return wheelsize;
}
Car(string m1,string md,string tp,string gtp,int pss,float ws)
{
setmake(m1);
setmodel(md);
settype(tp);
setgeartype(gtp);
setpassengers(pss);
setwheelsize(ws);
}
Car(const Car &old_car)
{
setmake(old_car.getmake());
setmodel(old_car.getmodel());
settype(old_car.gettype());
setgeartype(old_car.getgeartype());
setpassengers(old_car.getpassengers());
setwheelsize(old_car.getwheelsize());
}
void display()
{
cout<<"\n\nClass Car \n";
cout<<"Make : "<<make<<"\n";
cout<<"Type : "<<type<<"\n";
cout<<"Model : "<<model<<"\n";
cout<<"Auto/Manual : "<<geartype<<"\n";
cout<<"Passengers : "<<passengers<<"\n";
cout<<"Wheelsize : "<<wheelsize<<"\n\n";
}
~Car()
{
make.erase();
model.erase();
type.erase();
geartype.erase();
}
};
class SportsCar : public Car
{
string engine_type;
float torque,time_zeroto60,acceleration,topspeed;
public:
void setengine_type(string engine_type)
{
this->engine_type=engine_type;
}
void settorque(float torque)
{
this->torque=torque;
}
void settime_zeroto60(float time_zeroto60)
{
this->time_zeroto60=time_zeroto60;
}
void setacceleration(float acceleration)
{
this->acceleration=acceleration;
}
void settopspeed(float topspeed)
{
this->topspeed=topspeed;
}
string getengine_type() const
{
return engine_type;
}
float gettorque() const
{
return torque;
}
float gettime_zeroto60() const
{
return time_zeroto60;
}
float getacceleration() const
{
return acceleration;
}
float gettopspeed() const
{
return topspeed;
}
SportsCar(string m1,string md,string tp,string gtp,int pss,float ws,string eng,float tq, float tm,float acc, float ts) : Car{ m1,md,tp,gtp,pss,ws }
{
setengine_type(eng);
settorque(tq);
settime_zeroto60(tm);
setacceleration(acc);
settopspeed(ts);
setmake(m1);
setmodel(md);
settype(tp);
setgeartype(gtp);
setpassengers(pss);
setwheelsize(ws);
}
SportsCar(const Car& old_car,const SportsCar& old_scar): Car(getmake(),getmodel(),gettype(),getgeartype(),getpassengers(),getwheelsize())
{
setengine_type(old_scar.getengine_type());
settime_zeroto60(old_scar.gettime_zeroto60());
settorque(old_scar.gettorque());
setacceleration(old_scar.getacceleration());
settopspeed(old_scar.gettopspeed());
setmake(old_car.getmake());
setmodel(old_car.getmodel());
settype(old_car.gettype());
setgeartype(old_car.getgeartype());
setpassengers(old_car.getpassengers());
setwheelsize(old_car.getwheelsize());
}
void display()
{
cout<<"Class SportsCar ";
cout<<"Make : "<<getmake()<<"\n";
cout<<"Model : "<<getmodel()<<"\n";
cout<<"Type : "<<gettype()<<"\n";
cout<<"Manual/automatic : "<<getgeartype()<<"\n";
cout<<"Passengers : "<<getpassengers()<<"\n";
cout<<"Wheelsize : "<<getwheelsize()<<"\n";
cout<<"Engine Type : "<<engine_type<<"\n";
cout<<"Torque : "<<torque<<"\n";
cout<<"Time zero to sixty : "<<time_zeroto60<<"\n";
cout<<"Acceleration : "<<acceleration<<"\n";
cout<<"Topspeed : "<<topspeed<<"\n\n";
}
~SportsCar()
{
engine_type.erase();
}
};
class Person
{
string name,gender,nationality,CNIC;
int age;
public:
void setname(string name)
{
this->name=name;
}
void setgender(string gender)
{
this->gender=gender;
}
void setnationality(string nationality)
{
this->nationality=nationality;
}
void setCNIC(string CNIC)
{
this->CNIC=CNIC;
}
void setage(int age)
{
this->age=age;
}
string getname() const
{
return name;
}
string getgender() const
{
return gender;
}
string getnationality() const
{
return nationality;
}
string getCNIC() const
{
return CNIC;
}
int getage() const
{
return age;
}
Person(string nm, string gnd,string ntn, string cnc,int ag)
{
setname(nm);
setgender(gnd);
setnationality(ntn);
setCNIC(cnc);
setage(ag);
}
Person(const Person& old_person)
{
setname(old_person.getname());
setgender(old_person.getgender());
setnationality(old_person.getnationality());
setCNIC(old_person.getCNIC());
setage(old_person.getage());
}
void display()
{
cout<<"Class Person \n";
cout<<"Name : "<<name<<"\n";
cout<<"Gender : " <<gender<<"\n";
cout<<"Nationality : "<<nationality<<"\n";
cout<<"CNIC : "<<CNIC<<"\n";
cout<<"Age : "<<age<<"\n\n";
}
~Person()
{
name.erase();
gender.erase();
nationality.erase();
CNIC.erase();
}
};
class Driver : public Person
{
int experience,wincount;
string car;
public:
void setexperience(int experience)
{
this->experience=experience;
}
void setwincount(int wincount)
{
this->wincount=wincount;
}
void setcar(string car)
{
this->car=car;
}
int getexperience() const
{
return experience;
}
int getwincount() const
{
return wincount;
}
string getcar() const
{
return car;
}
Driver(string nm, string gnd,string ntn, string cnc,int ag, int exp,int wc, string cr) : Person(nm, gnd, ntn, cnc, ag)
{
setname(nm);
setgender(gnd);
setnationality(ntn);
setCNIC(cnc);
setage(ag);
setexperience(exp);
setwincount(wc);
setcar(cr);
}
Driver(const Person& old_person, const Driver& old_driver) : Person { getname(),getgender(),getnationality(),getCNIC(),getage() }
{
setname(old_person.getname());
setgender(old_person.getgender());
setnationality(old_person.getnationality());
setCNIC(old_person.getCNIC());
setage(old_person.getage());
setexperience(old_driver.getexperience());
setwincount(old_driver.getwincount());
setcar(old_driver.getcar());
}
void display()
{
cout<<"Class Driver \n";
cout<<"Name : "<<getname()<<"\n";
cout<<"Gender : "<<getgender()<<"\n";
cout<<"Nationality : "<<getnationality()<<"\n";
cout<<"CNIC : "<<getCNIC()<<"\n";
cout<<"Age : "<<getage()<<"\n";
cout<<"Experience : "<<experience<<"\n";
cout<<"Win Count : "<<wincount<<"\n";
cout<<"Car : "<<car<<"\n\n";
}
~Driver()
{
car.erase();
}
};
int main()
{
Car c1("Honda","Civic","Sedan","Manual",4,5.6);
cout<<"Original Class \n\n";
c1.display();
Car c2=c1;
cout<<"Copied Class \n\n";
c2.display();
SportsCar s1("Honda","Civic","Sedan","Manual",4,5.6,"V8",5,4,5.5,10);
cout<<"Original Class \n\n";
s1.display();
SportsCar s2=s1;
cout<<"Copied Class \n\n";
s2.display();
Person p1("Name","M/F","Nationality","1123gn",30);
cout<<"Original Class \n\n";
p1.display();
Person p2=p1;
cout<<"Copied Class \n\n";
p2.display();
Driver d1("Name","M/F","Nationality","1123gn",30,5,30,"F1");
cout<<"Original Class \n\n";
d1.display();
Driver d2=d1;
cout<<"Copied Class \n\n";
d2.display();
}
Comments
Leave a comment