Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Experiment 2

#include <iostream>
using namespace std;
class Vehicles
{
public:
int id;
int avg;
string brand_name;
string model;
// Default Constructor
Vehicles()
{
cout << "Default Constructor called !!" << endl;
}
// Parameterised Constructor
Vehicles(int _id, int _avg, string _brand_name, string _model)
{
cout << endl
<< "Parameterised Constructor called !!";
id = _id;
avg = _avg;
brand_name = _brand_name;
model = _model;
}
// Copy Constructor
Vehicles(Vehicles &V)
{
cout << endl
<< "Copy Constructor called !!";
id = V.id;
avg = V.avg;
brand_name = V.brand_name;
model = V.model;
}
// Overloaded Constructor
Vehicles(int _id, string _brand_name, string _model)
{
cout << endl
<< "Parameterised Overloaded Constructor called !!";
id = _id;
brand_name = _brand_name;
model = _model;
}
// Destructor
~Vehicles()
{
Experiment 2

cout << endl


<< "Destructor called !!";
}
void Show_data()
{
cout << endl
<< id;
cout << endl
<< avg;
cout << endl
<< brand_name;
cout << endl
<< model;
cout << endl;
}
};
int main()
{
system("cls");
Vehicles V1;
Vehicles V2(1, 2, "Ford", "Mustang");
V2.Show_data();
Vehicles V3(V2);
V3.Show_data();
Vehicles V4(2, "Nissan", "Skyline");
V4.Show_data();

return 0;
}
Output :

Parameterised Constructor called !!


1
2
Ford
Mustang
Copy Constructor called !!
1
2
Ford
Mustang
Parameterised Overloaded Constructor called !!
2
1878006816
Nissan
Skyline
Destructor called !!
Destructor called !!
Destructor called !!
Destructor called !!

You might also like