kilolilo

worker

Feb 27th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class human{
  5. protected:
  6.     string name,surname;
  7.     int age;
  8. public:
  9.     human(string x,string y){
  10.         name=x;
  11.         surname=y;
  12.         age=0;
  13.     }
  14.     human(string x,string y,int age_1){
  15.         name=x;
  16.         surname=y;
  17.         age=age_1;
  18.     }
  19.     void say_hello(){
  20.         if(age>0){
  21.             cout<<"hello my name is "<<name<<"  "<<surname<<endl<<age<<" years old"<<endl;
  22.         }
  23.         else{
  24.           cout<<"hello my name is "<<name<<"  "<<surname<<endl;
  25.         }
  26.  
  27.     }
  28. };
  29.  
  30. class worker : public human{
  31. protected:
  32.     float salary;
  33.     string jobname;
  34. public:
  35.     worker(string x, string y, float z,string job) : human(x, y), salary(z),jobname(job){}
  36.     void say_hello_1(){
  37.         cout<<"salary is "<<salary<<"\t"<<" jobname is "<<jobname << endl;
  38.     }
  39. };
  40.  
  41.  
  42. int main()
  43. {
  44.     human b=human("Vasya","Pupkin",4356);
  45.     b.say_hello();
  46.     worker a = worker("Ivan", "Ivanov", 12345.0,"human");
  47.     a.say_hello_1();
  48. }
Add Comment
Please, Sign In to add comment