Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class College
- {
- protected:
- string collegeName;
- int collegeCode;
- public:
- College(void)
- {
- cout << "Enter the details below:\n";
- cout << "Enter the college Name: ";
- cin >> collegeName;
- cout << "Enter the college code: ";
- cin >> collegeCode;
- }
- };
- class Department : public College
- {
- protected:
- string Dept;
- public:
- int a;
- Department(void)
- {
- cout << "Select the Department:\n1--> Mechanical Department.\n2--> Electrical Department\n3--> Civil Department\n4--> CSE Department\n";
- cin >> a;
- switch (a)
- {
- case 1:
- Dept = "Mechanical Department";
- break;
- case 2:
- Dept = "Electrical Department";
- break;
- case 3:
- Dept = "Civil Department";
- break;
- case 4:
- Dept = "CSE Department";
- break;
- default:
- Dept = "Invalid";
- cout << "Please choose correct option";
- break;
- }
- }
- };
- class Staff : public Department
- {
- protected:
- string staffName;
- string task;
- int age;
- public:
- Staff(void)
- {
- cout << "\n\n\nEnter the Staff Name: ";
- cin >> staffName;
- cout << "\nEnter the Staff's task (Teaching Subject): ";
- cin >> task;
- cout << "\nEnter the Staff's Age: ";
- cin >> age;
- }
- void display(){
- cout<<"\n\nStaff Details:\n"
- <<"College Name : "<<collegeName<<endl
- <<"College Code: "<<collegeCode<<endl
- <<"Department: "<<Dept<<endl
- <<"Age: "<<age<<endl
- <<"Staff Name: "<<staffName<<endl
- <<"Teaching Subject: "<<task<<endl;
- }
- };
- class Student : public Department
- {
- protected:
- string studentName;
- int age, rollNo;
- public:
- Student(void)
- {
- cout << "\n\n\nEnter the Student Name: ";
- cin >> studentName;
- cout << "\nEnter the Students's Age: ";
- cin >> age;
- cout << "\nEnter the Student's Roll No.: ";
- cin >> rollNo;
- }
- void display(){
- cout<<"\n\nStudent Details:\n"
- <<"College Name : "<<collegeName<<endl
- <<"College Code: "<<collegeCode<<endl
- <<"Department: "<<Dept<<endl
- <<"Age: "<<age<<endl
- <<"Student Name: "<<studentName<<endl
- <<"Roll No.: "<<rollNo<<endl;
- }
- };
- int main()
- {
- Student s1;
- s1.display();
- Staff s2;
- s2.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement