OOCP3-1

//BCA Support //www.bcasupport.xyz #include <iostream.h> #include <conio.h> class vehicle { protected: int num,chassis; public: void getdata() { cout<<"\nEnter vehicle no. : "; cin>>num; cout<<"Enter chassis no. : "; cin>>chassis; } virtual void print() { cout<<"\nVehicle no. : "<<num; cout<<"\nChassis no. : "<<chassis; } }; class scooter: public vehicle { int wheels; char company[20]; public: scooter() { cout<<"\nEnter no. of wheels : "; cin>>wheels; cout<<"Enter company name : "; cin>>company; } void print() { cout<<"\nNo. of wheels : "<<wheels; cout<<"\nCompany : "<<company; } }; class price: public vehicle { float cost; char company[20]; public: price() { cout<<"\nEnter price : Rs. "; cin>>cost; } void print() { cout<<"\nPrice : Rs. "<<cost; } }; int main() { clrscr(); vehicle v1; vehicle *ptr=&v1; ptr->getdata(); scooter s1; price p1; clrscr(); ptr->print(); ptr=&s1; ptr->print(); ptr=&p1; ptr->print(); getch(); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.