Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class human{
- protected:
- string name,surname;
- int age;
- public:
- human(string x,string y){
- name=x;
- surname=y;
- age=0;
- }
- human(string x,string y,int age_1){
- name=x;
- surname=y;
- age=age_1;
- }
- void say_hello(){
- if(age>0){
- cout<<"hello my name is "<<name<<" "<<surname<<endl<<age<<" years old"<<endl;
- }
- else{
- cout<<"hello my name is "<<name<<" "<<surname<<endl;
- }
- }
- };
- class worker : public human{
- protected:
- float salary;
- string jobname;
- public:
- worker(string x, string y, float z,string job) : human(x, y), salary(z),jobname(job){}
- worker(string x, string y,int age_1, float z,string job) : human(x, y, age_1), salary(z),jobname(job){}
- void say_hello(){
- human::say_hello();
- cout << "\t salary - "<<salary<<" job name is "<<jobname << endl;
- }
- };
- int main()
- {
- human b=human("Vasya","Pupkin",4356);
- b.say_hello();
- worker a = worker("Ivan", "Ivanov", 15, 12345.0,"human");
- a.say_hello();
- }
Add Comment
Please, Sign In to add comment