Advertisement
vvccs

college hierarchy

Jun 6th, 2023 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class College
  5. {
  6. protected:
  7.     string collegeName;
  8.     int collegeCode;
  9.  
  10. public:
  11.     College(void)
  12.     {
  13.         cout << "Enter the details below:\n";
  14.         cout << "Enter the college Name: ";
  15.         cin >> collegeName;
  16.         cout << "Enter the college code: ";
  17.         cin >> collegeCode;
  18.     }
  19. };
  20.  
  21. class Department : public College
  22. {
  23. protected:
  24.     string Dept;
  25.  
  26. public:
  27.     int a;
  28.     Department(void)
  29.     {
  30.         cout << "Select the Department:\n1--> Mechanical Department.\n2--> Electrical Department\n3--> Civil Department\n4--> CSE Department\n";
  31.         cin >> a;
  32.         switch (a)
  33.         {
  34.         case 1:
  35.             Dept = "Mechanical Department";
  36.             break;
  37.         case 2:
  38.             Dept = "Electrical Department";
  39.             break;
  40.         case 3:
  41.             Dept = "Civil Department";
  42.             break;
  43.         case 4:
  44.             Dept = "CSE Department";
  45.             break;
  46.         default:
  47.             Dept = "Invalid";
  48.             cout << "Please choose correct option";
  49.             break;
  50.         }
  51.     }
  52. };
  53.  
  54. class Staff : public Department
  55. {
  56. protected:
  57.     string staffName;
  58.     string task;
  59.     int age;
  60.  
  61. public:
  62.     Staff(void)
  63.     {
  64.         cout << "\n\n\nEnter the Staff Name: ";
  65.         cin >> staffName;
  66.         cout << "\nEnter the Staff's task (Teaching Subject): ";
  67.         cin >> task;
  68.         cout << "\nEnter the Staff's Age: ";
  69.         cin >> age;
  70.     }
  71.     void display(){
  72.         cout<<"\n\nStaff Details:\n"
  73.             <<"College Name : "<<collegeName<<endl
  74.             <<"College Code: "<<collegeCode<<endl
  75.             <<"Department: "<<Dept<<endl
  76.             <<"Age: "<<age<<endl
  77.             <<"Staff Name: "<<staffName<<endl
  78.             <<"Teaching Subject: "<<task<<endl;
  79.     }
  80. };
  81.  
  82. class Student : public Department
  83. {
  84. protected:
  85.     string studentName;
  86.     int age, rollNo;
  87.  
  88. public:
  89.     Student(void)
  90.     {
  91.         cout << "\n\n\nEnter the Student Name: ";
  92.         cin >> studentName;
  93.         cout << "\nEnter the Students's Age: ";
  94.         cin >> age;
  95.         cout << "\nEnter the Student's Roll No.: ";
  96.         cin >> rollNo;
  97.     }
  98.     void display(){
  99.         cout<<"\n\nStudent Details:\n"
  100.             <<"College Name : "<<collegeName<<endl
  101.             <<"College Code: "<<collegeCode<<endl
  102.             <<"Department: "<<Dept<<endl
  103.             <<"Age: "<<age<<endl
  104.             <<"Student Name: "<<studentName<<endl
  105.             <<"Roll No.: "<<rollNo<<endl;
  106.     }
  107. };
  108.  
  109. int main()
  110. {
  111.     Student s1;
  112.     s1.display();
  113.     Staff s2;
  114.     s2.display();
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement