467,166 Members | 1,043 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,166 developers. It's quick & easy.

Create Class Person with data members weight, height and gender. Create another Class

Bit
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5. class Person
  6. {
  7. protected:
  8.     double Weight;
  9.     double Height;
  10.     string Gender;
  11. public:
  12.     Person()
  13.     {
  14.         Weight=0.0;
  15.         Height=0.0;
  16.         Gender="Unknown";
  17.     }
  18.     Person(double w,double h,string g)
  19.     {
  20.         Weight=w;
  21.         Height=h;
  22.         Gender=g;
  23.     }
  24.  
  25.     void setWeight(double w){Weight=w;}
  26.     void setHeight(double h){Height=h;}
  27.     void setGender(string g){Gender=g;}
  28.     double getWeight(){return Weight;}
  29.     double getHeight(){return Height;}
  30.     string getGender(){return Gender;}
  31.  
  32.  
  33. };
  34. class Employee
  35. {
  36. protected:
  37.     string Designation;
  38.     int HoursPerDay;
  39.  
  40. public:
  41.     Employee()
  42.     {   Designation="";
  43.         HoursPerDay=0;
  44.     }
  45.     Employee(string d,int hpd)
  46.     {
  47.         Designation=d;
  48.         HoursPerDay=hpd;
  49.     }
  50.  
  51.     void setDesignation(string d){Designation=d;}
  52.     void setHoursPerDay(int hpd){HoursPerDay=hpd;}
  53.  
  54.     string getDesignation(){return Designation;}
  55.     int getHoursPerDay(){return HoursPerDay;}
  56.  
  57. };
  58. class Teacher:public Person,public Employee
  59. {
  60. protected:
  61.     Person p1;
  62.     Employee e1;
  63. public:
  64.     void display()
  65.     {
  66.  
  67.         cout<<"Gender of Teacher :: "<<getGender()<<endl;
  68.         cout<<"Weight of Teacher :: "<<getWeight()<<endl;
  69.         cout<<"Height of Teacher :: "<<getHeight()<<endl;
  70.     }
  71. };
  72.  
  73. int main()
  74. {
  75.     Teacher t1;
  76.     t1.display();
  77.     return 0;
  78. }
2 Weeks Ago #1
  • viewed: 1038
Share:
2 Replies
Expert 256MB
What's the question?
2 Weeks Ago #2
32bit
Hello,
I do not get your question.
In order to assist you properly, please
add more information to your question.
2 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Robert May | last post: by
10 posts views Thread by Zap | last post: by
5 posts views Thread by meyousikmann | last post: by
5 posts views Thread by Brad Pears | last post: by
5 posts views Thread by greek_bill | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.