Wednesday, April 7, 2021

simple program using constructor (OOP) (52)

#include<iostream>

#include<string>

using namespace std;

class MotorVehicle

{

public:

string make;

string fuel_type;

int year_of_manufacture;

string colour;

int engine_capacity;

MotorVehicle() //this is a default constructure

{

make="honda";

fuel_type="petrol";

colour="red";

year_of_manufacture=2020;

engine_capacity=800;

}

MotorVehicle(int x,int y) //this is a parameterized constructure

{

make="honda";

fuel_type="petrol";

colour="";

year_of_manufacture=x;

engine_capacity=y;

}

void display_car_detail()

{

cout<<"colour:"<<colour<<endl;

cout<<"fuel_type"<<fuel_type<<endl;

cout<<"year_of_manufacture"<<year_of_manufacture<<endl;

cout<<"engine_capacity"<<engine_capacity<<endl;

cout<<"make"<<make<<endl;

}

};

int main()

{

MotorVehicle  mu();

int x,y;

cout<<"please enter the year of manufacture: ";

cin>>x;

cout<<"please enter the engine capacity: ";

cin>>y;

MotorVehicle mv(x,y);

mv.display_car_detail();

} 

No comments:

Post a Comment