473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

1 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. }
Jan 3 '21 #1
2 2291
dev7060
636 Expert 512MB
What's the question?
Jan 4 '21 #2
Naheedmir
62 32bit
Hello,
I do not get your question.
In order to assist you properly, please
add more information to your question.
Jan 4 '21 #3

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

Similar topics

5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
2
by: Xiangliang Meng | last post by:
Hi, all. What will we get from sizeof(a class without data members and virtual functions)? For example: class abnormity { public: string name() { return "abnormity"; }
1
by: Robert May | last post by:
Hi, Can anybody tell me whether the use of static class data members is any different than using global variables? i.e. do they remain persistent in memory for the duration of main() execution? ...
10
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this...
2
by: Susan Baker | last post by:
Hi, I got this error msg whilst building some classes. It is realatively asy to fix. But I just wondered, does anyone know the technical reason why one can't initialiaze a const static...
5
by: meyousikmann | last post by:
Given these two (incomplete but representative) classes in two seperate header files: Class1.h class Class1 { public: Class(const char CharValue, const int IntValue1, const int IntValue2);...
11
by: dalu.gelu | last post by:
Hi, can anyone help me by writing a sample code of defining a copy constructor in a class having data member as an object of another class. for eg: class A{ int x; public: A(){ x=6;} };
5
by: Brad Pears | last post by:
Hi guys!!! Thanks for all your input on previous OO posts. I know it will be all the same people responding again and I really appreciate your insight etc.. as you all appear to know what you are...
5
by: greek_bill | last post by:
Hi, I'm trying to develop a system where I can register some data/ information about a class. For example // ClassInfo.h template <class T> struct ClassInfo { static const std::string ...
1
by: braineater | last post by:
Define a base class person that will contain universal information, including name, address, birth date, gender and identification (student, worker etc). Derive from this class the following classes:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.