#include <iostream> using namespace std; //PUre Virtual Function class Employee{ int code; string name[20]; public: virtual void getData(); virtual void Display(); }; class Grade : public Employee{ char grade[20]; float salary; public: void getData(); void Display(); }; void Employee::getData(){ } void Employee::Display(){ } void Grade::getData(){ cout<<"Enter Employee Grade: "<<endl; cin>>grade; cout<<"Enter Employee Salaray: "<<endl; cin>>salary; } void Grade::Display(){ cout<<"Employee Grade is: "<<grade<<endl; cout<<"Employee Salaray is: "<<salary<<endl; } int main() { Employee *ptr; Grade obj; ptr = &obj; ptr->getData(); ptr->Display(); return 0; } //OUTPUT: Enter Employee Grade: A Enter Employee Salaray: 24000 Employee Grade is: A Employee Salaray is: 24000
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter