CODE FOR + OPERATOR OVER LOADING C++

 PROBLEM STATEMENT: ADD 2 OBJECTS AND ADD INTO OTHER. CODE: #include<iostream> using namespace std; class Experience { private: int days; int month; double year; public: Experience() { } Experience(int a,int b,double c) { days = a; month = b; year = c; } Experience operator +(Experience E) { Experience E1; E1.days = days + E.days; E1.month = month + E.month; E1.year = year + E.year; return E1; } void display() { cout << "\nDAYS\t" << days << "\nMONTHS\t" << month << "\nYEAR\t" << year << endl; } }; int main() { Experience e1(2, 12, 2), e2(1, 12, 4), e3; e3 = e1 + e2; cout << "showing data of 1st Experience\n"; e1.display(); cout << "\n\n\n\n"; cout << "showing data of 2nd Experience\n"; e2.display(); cout << "\n\n\n\n"; cout << "showing data of sum of Experiences\

CODE FOR CAR AND BIKE MANAGEMENT USING(Virtual functions) C++

 

PROBLEM STATEMENT:

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";

}


}

}

}




Comments

Popular posts from this blog

NESTED LOOPS IN C++