Dynamic Objects and Run Time Polymorphism
Develop a C++ program for mobile users of prepaid and postpost schemes using pure virtual functions. The mobile detail consists of data members such as mobile vendor and Branch. The prepaid account consists of data members such as prepaid_plan. The current account consists of data members such as postpaid_plan. The member functions are getdetails() and display()
Runtime Input :
Aircel
Chennai
199
499
Output :
Aircel
Chennai
199
499
#include <iostream>
using namespace std;
class Mobile{
protected:
string vendor, branch;
public:
Mobile(){}
virtual void getdetails(){}
virtual void display(){}
};
class Prepaid: public Mobile{
protected:
int prepaid_plan;
public:
};
class Current: public Prepaid{
int postpaid_plan;
void getdetails(){
cout<<"Runtime Input:\n";
cin>>vendor;
cin>>branch;
cin>>prepaid_plan;
cin>>postpaid_plan;
}
void display(){
cout<<"output:\n";
cout<<vendor<<endl;
cout<<branch<<endl;
cout<<prepaid_plan<<endl;
cout<<postpaid_plan<<endl;
}
};
int main(){
Mobile* mobile;
mobile = new Current();
mobile->getdetails();
mobile->display();
return 0;
}
Comments
Leave a comment