single inheritance

PHOTO EMBED

Sun Apr 28 2024 17:21:22 GMT+0000 (Coordinated Universal Time)

Saved by @Mohamedshariif #c++

#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
content_copyCOPY