3.PNG
    4.PNG
    5.PNG

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. //Dividing Line----------------------------------------------------------------------------------------
    4. class CStudent
    5. {
    6. private:
    7. string name;
    8. string id;
    9. char gender;
    10. int age;
    11. public:
    12. void SetInfo(const string &, const string &, const char &, const int &);
    13. void PrintInfo(void);
    14. };
    15. void CStudent::SetInfo(const string &_name, const string &_id, const char &_gender, const int &_age)
    16. {
    17. name = _name;
    18. id = _id;
    19. gender = _gender;
    20. age = _age;
    21. }
    22. void CStudent::PrintInfo(void)
    23. {
    24. cout << "Name: " << name << endl;
    25. cout << "Id: " << id << endl;
    26. cout << "Gender: " << gender << endl;
    27. cout << "Age: " << age << endl;
    28. }
    29. //Dividing Line--------------------------------------------------------------------------
    30. class CUnderGraduate : public CStudent
    31. {
    32. private:
    33. string major;
    34. public:
    35. void SetInfo(const string &, const string &, const char &, const int &, const string &);
    36. void PrintInfo(void);
    37. };
    38. void CUnderGraduate::SetInfo(const string &_name, const string &_id, const char &_gender, const int &_age, const string &_major)
    39. {
    40. CStudent::SetInfo(_name, _id, _gender, _age);
    41. major = _major;
    42. }
    43. void CUnderGraduate::PrintInfo(void)
    44. {
    45. CStudent::PrintInfo();
    46. cout << "Major: " << major << endl;
    47. }
    48. //Dividing Line-----------------------------------------------------------------------------------------------------
    49. int main(void)
    50. {
    51. CUnderGraduate c;
    52. c.SetInfo("Hermann", "21200319", 'M', 19, "Computer Science");
    53. c.PrintInfo();
    54. return 0;
    55. }