In the following code, there is two class one is wheel and anther is a car. Wheel class object objWheel is declared inside the car class. Inside the main only we have to create an object of car. Due to car class is an associate with wheel.this is good example of an association in class.
#include<iostream>
#include<string>
using namespace std;
class wheel
{
private:
string name_of_compnay;
public:
void GetCompany()
{
cout<<"What is your tire compnay :";
cin>>name_of_compnay;
}
void print()
{
cout<<"Wheel compny is "<<name_of_compnay<<endl;
}
};
class car
{
private:
int Number_of_wheel;
wheel objWheel;//object of wheel class inside car(Assocation) relationship between class .
public:
int GetNumbeOfWheel()
{
cout<<"How many wheel has problem in your car :";
cin>>Number_of_wheel;
objWheel.GetCompany();
}
void print_car()
{
objWheel.print();
cout<<"You can change :"<<Number_of_wheel<<endl;
}
};
int main()
{
car c1;
c1.GetNumbeOfWheel();
c1.print_car();
}
outPut
How many wheel has problem in your car :2 What is your tire compnay :MRF Wheel compny is MRF You can change :2
0 Comments
If you have any doubt and suggestion Please let me know