0% found this document useful (0 votes)
4 views6 pages

Assignment 2 Inheritance

The document contains a C++ implementation of a class hierarchy demonstrating inheritance, including classes for Person, Student, Employee, Teacher, Coordinator, Researcher, Teaching Assistant, Admin Staff, Lab Assistant, and Account Officer. Each class has methods for inputting and displaying relevant information. Additionally, a UML diagram representation of the class relationships is provided.

Uploaded by

ykhanzada713
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Assignment 2 Inheritance

The document contains a C++ implementation of a class hierarchy demonstrating inheritance, including classes for Person, Student, Employee, Teacher, Coordinator, Researcher, Teaching Assistant, Admin Staff, Lab Assistant, and Account Officer. Each class has methods for inputting and displaying relevant information. Additionally, a UML diagram representation of the class relationships is provided.

Uploaded by

ykhanzada713
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Assignment 2: Inheritance and UML

C++ Implementation

#include <iostream>
using namespace std;

// Base Class
class Person {
public:
string name;
int age;
string gender;
int id;

void inputPerson() {
cin >> name >> age >> gender >> id;
}

void displayPerson() {
cout << "Name: " << name << "\nAge: " << age
<< "\nGender: " << gender << "\nID: " << id << endl;
}
};

// Student
class Student : public Person {
public:
string program;
int semester;
float cgpa;

void inputStudent() {
inputPerson();
cin >> program >> semester >> cgpa;
}

void displayStudent() {
displayPerson();
cout << "Program: " << program << "\nSemester: " << semester
<< "\nCGPA: " << cgpa << endl;
cout << "Scholarship Eligible: " << (cgpa >= 3.5 ? "Yes" : "No") << endl;
}
};

// Employee
class Employee : public Person {
public:
string department;
double salary;

void inputEmployee() {
inputPerson();
cin >> department >> salary;
}

void displayEmployee() {
displayPerson();
cout << "Department: " << department << "\nSalary: " << salary << endl;
}
};

// Teacher
class Teacher : public Employee {
public:
string subject;
int yearsOfExperience;

void inputTeacher() {
inputEmployee();
cin >> subject >> yearsOfExperience;
}

void displayTeacher() {
displayEmployee();
cout << "Subject: " << subject
<< "\nExperience: " << yearsOfExperience << endl;
cout << "Senior Teacher: " << (yearsOfExperience >= 10 ? "Yes" : "No") << endl;
}
};

// Coordinator
class Coordinator : public Teacher {
public:
string managedProgram;
int classes;

void inputCoordinator() {
inputTeacher();
cin >> managedProgram >> classes;
}

void displayCoordinator() {
displayTeacher();
cout << "Managed Program: " << managedProgram
<< "\nClasses Managed: " << classes << endl;
}
};

// Researcher
class Researcher {
public:
string researchArea;
int publications;

void inputResearcher() {
cin >> researchArea >> publications;
}

void displayResearcher() {
cout << "Research Area: " << researchArea
<< "\nPublications: " << publications << endl;
}
};

// Teaching Assistant (Multiple Inheritance)


class TeachingAssistant : public Student, public Researcher {
public:
int labHours;
string course;

void inputTA() {
inputStudent();
inputResearcher();
cin >> labHours >> course;
}
void displayTA() {
displayStudent();
displayResearcher();
cout << "Lab Hours: " << labHours
<< "\nCourse: " << course << endl;
cout << "Workload Heavy: " << (labHours > 10 ? "Yes" : "No") << endl;
}
};

// Hierarchical Inheritance
class AdminStaff : public Employee {
public:
string office;
string designation;

void inputAdminStaff() {
inputEmployee();
cin >> office >> designation;
}

void displayAdminStaff() {
displayEmployee();
cout << "Office: " << office << "\nDesignation: " << designation << endl;
}
};

class LabAssistant : public Employee {


public:
string labName;
string shift;

void inputLabAssistant() {
inputEmployee();
cin >> labName >> shift;
}

void displayLabAssistant() {
displayEmployee();
cout << "Lab: " << labName << "\nShift: " << shift << endl;
}
};

class AccountOfficer : public Employee {


public:
string section;
double bonus;

void inputAccountOfficer() {
inputEmployee();
cin >> section >> bonus;
}

void displayAccountOfficer() {
displayEmployee();
cout << "Section: " << section << "\nBonus: " << bonus << endl;
}
};

int main() {
Student s;
Teacher t;
Coordinator c;
TeachingAssistant ta;
AdminStaff a;
LabAssistant l;
AccountOfficer ac;

cout << "\n--- Student ---\n";


[Link]();
[Link]();

cout << "\n--- Teacher ---\n";


[Link]();
[Link]();

cout << "\n--- Coordinator ---\n";


[Link]();
[Link]();

cout << "\n--- Teaching Assistant ---\n";


[Link]();
[Link]();

cout << "\n--- Admin Staff ---\n";


[Link]();
[Link]();
cout << "\n--- Lab Assistant ---\n";
[Link]();
[Link]();

cout << "\n--- Account Officer ---\n";


[Link]();
[Link]();

return 0;
}

UML Diagram (Text Representation)

Person

Student Employee
↑ ↑
TeachingAssistant Teacher

Coordinator

Researcher → TeachingAssistant

Employee → AdminStaff
Employee → LabAssistant
Employee → AccountOfficer

You might also like