#include <iostream> using namespace std; class worker{ int age; char name[10]; public: void get(); void show(); }; void worker::get(){ cout<<"Your Name Please: "<<endl; cin>>name; cout<<"Your Age Please: "<<endl; cin>>age; } void worker::show(){ cout<<"My name is: "<<name<<endl; cout<<"My Age is: "<<age<<endl; } class manager: public worker{ int now; public: void get(); void show(); }; void manager::get(){ worker::get(); cout<<"Num of workers are: "<<endl; cin>>now; } void manager::show(){ worker::show(); cout<<"Num of workers are: "<<now<<endl; } int main() { worker w1; manager m1; m1.get(); m1.show(); return 0; } //Output: Your Name Please: moha Your Age Please: 34 Num of workers are: 67 My name is: moha My Age is: 34 Num of workers are: 67
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