Create a class vehicle which stores the vehicleno and chassisno as a member. Define another class for scooter,which inherits the data members of the class vehicle and has a data member for a storing wheels and company. Define another class for which inherits the data member of the class vehicle and has a data member for storing price and company. Display the data from derived class. Use virtual function.
CODING:
#include<iostream.h>
#include<conio.h>
class vehicle
{
protected:
int vehicleno,chassisno;
public:
virtual void set()
{
cout<<"Enter The Vehicle no:";
cin>>vehicleno;
cout<<"Enter The Chassis no:";
cin>>chassisno;
}
virtual void disp()
{
cout<<"Vehicle no:"<<vehicleno;
cout<<"\nChassis no:"<<chassisno;
}
};
class scooter:public vehicle
{
int wheels;
char company[20];
public:
virtual void set()
{
cout<<"\nEnetr The Wheels no:";
cin>>wheels;
cout<<"Enter The Company name:";
cin>>company;
}
virtual void disp()
{
cout<<"Wheels:"<<wheels;
cout<<"\nCompany:"<<company;
}
};
class price:public vehicle
{
int price;
char company;
public:
virtual void set()
{
cout<<"\nEnetr The Price:";
cin>>price;
cout<<"Enter The Company name:";
cin>>company;
}
virtual void disp()
{
cout<<"Price:"<<price;
cout<<"\nCompany:"<<company;
}
};
void main()
{
clrscr();
vehicle v1;
vehicle *p=&v1;
p->set();
p->disp();
scooter s1;
p=&s1;
p->set();
p->disp();
price p1;
p=&p1;
p->set();
p->disp();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class vehicle
{
protected:
int vehicleno,chassisno;
public:
virtual void set()
{
cout<<"Enter The Vehicle no:";
cin>>vehicleno;
cout<<"Enter The Chassis no:";
cin>>chassisno;
}
virtual void disp()
{
cout<<"Vehicle no:"<<vehicleno;
cout<<"\nChassis no:"<<chassisno;
}
};
class scooter:public vehicle
{
int wheels;
char company[20];
public:
virtual void set()
{
cout<<"\nEnetr The Wheels no:";
cin>>wheels;
cout<<"Enter The Company name:";
cin>>company;
}
virtual void disp()
{
cout<<"Wheels:"<<wheels;
cout<<"\nCompany:"<<company;
}
};
class price:public vehicle
{
int price;
char company;
public:
virtual void set()
{
cout<<"\nEnetr The Price:";
cin>>price;
cout<<"Enter The Company name:";
cin>>company;
}
virtual void disp()
{
cout<<"Price:"<<price;
cout<<"\nCompany:"<<company;
}
};
void main()
{
clrscr();
vehicle v1;
vehicle *p=&v1;
p->set();
p->disp();
scooter s1;
p=&s1;
p->set();
p->disp();
price p1;
p=&p1;
p->set();
p->disp();
getch();
}
Comments
Post a Comment