CODE FOR CAR AND BIKE MANAGEMENT USING(Virtual functions) C++
- Get link
- X
- Other Apps
PROBLEM STATEMENT:
CODE:
#include<iostream>
using namespace std;
class mymode_of_travel {
protected:
int noofmiles;
int price;
public:
virtual void store()=0
{
cout << "ENTER NO OF MILES\n";
cin >> noofmiles;
cout << "\nENTER PRICE\n";
cin >> price;
}
virtual void print()=0
{
cout << "\nno of miles\t" << noofmiles << endl;
cout << "\nprice\t" << price;
}
};
class Automobile:public mymode_of_travel {
protected:
string enginetype;
int yearofmanufacture;
int remainingwarranty;//in months
public:
void store()
{
cout << "\nENTER Engine Type\n";
cin >> enginetype;
cout << "\nENTER YEAR OF MANUFACTURE\n";
cin >> yearofmanufacture;
cout << "\nENTER REMAINING WARRANTY\n";
cin >> remainingwarranty;
cout << "ENTER NO OF MILES\n";
cin >> noofmiles;
cout << "\nENTER PRICE\n";
cin >> price;
}
void print()
{
cout << "\n Engine Type\n";
cout<< enginetype;
cout << "\n YEAR OF MANUFACTURE\n";
cout<< yearofmanufacture;
cout << "\n REMAINING WARRANTY\n";
cout<< remainingwarranty;
cout << "\nno of miles\t" << noofmiles << endl;
cout << "\nprice\t" << price;
}
};
class Motorcycle :public mymode_of_travel {
protected:
int cylinders;
int gears;
int tanksize;//in inches;
string wheeltype;//A,B,C,D
void store()
{
cout << "\nENTER cylinders number\n";
cin >> cylinders;
cout << "\nENTER no of gears\n";
cin >> gears;
cout << "\nENTER TANK SIZE\n";
cin >> tanksize;
cout << "\nENTER WHEEL TYPE\n";
cin >> wheeltype;
}
void print()
{
cout << "\n cylinders number\n";
cout<< cylinders;
cout << "\n no of gears\n";
cout<< gears;
cout << "\n TANK SIZE\n";
cout<< tanksize;
cout << "\nWHEEL TYPE\n";
cout << wheeltype;
}
};
class manual :public Automobile {
protected:
string transmissiontype;
void store()
{
cout << "transmission type\n";
cin >> transmissiontype;
}
void print()
{
cout<< transmissiontype;
}
};
class automatic :public Automobile {
public:
string transmission_type;
void store()
{
cout << "transmission type\n";
cin >> transmission_type;
}
void print()
{
cout << transmission_type;
}
};
class Honda :public Motorcycle {
public:
string make_type;
void store()
{
cout << "MAKE type\n";
cin >> make_type;
}
void print()
{
cout << make_type;
}
};
class Suzuki :public Motorcycle {
public:
string maketype;
void store()
{
cout << "MAKE type\n";
cin >> maketype;
}
void print()
{
cout << maketype;
}
};
int main()
{
mymode_of_travel* m,*n;
for (int i = 0; i < 2; i++)
{
cout << "1.AUTOMOBILE\n2.MOTORCYCLE\nENTER YOUR CHOICE\n";
int c;
cin >> c;
if (c == 1)
{
cout << " 3.HONDA\n4.SUZUKI\n ENTER YOUR CHOICE";
int j;
cin >> j;
if (j == 3)
{
cout << "\n\n\n\n\n";
manual m1;
m = &m1;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
automatic a1;
m = &a1;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
Automobile ai;
m = &ai;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
}
else if (j == 4)
{
manual m1;
m = &m1;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
automatic a1;
m = &a1;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
Automobile ai;
m = &ai;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
}
}
else if (c == 2)
{
cout << " 3.HONDA\n4.SUZUKI\n ENTER YOUR CHOICE";
int j;
cin >> j;
if (j == 3)
{
Honda h1;
m = &h1;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
Automobile ai;
m = &ai;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
}
else if (j == 4)
{
Suzuki h1;
m = &h1;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
Automobile ai;
m = &ai;
m->store();
cout << "SHOWING DETAILS\n";
m->print();
cout << "\n\n\n\n\n";
}
}
}
}
- Get link
- X
- Other Apps
Comments
Post a Comment