OOP ASSIGNMENT 2
NAME: ZOHA RASHID
SEC: 3B
SAP ID: 70182584
SUBMITTED TO: SIR MAJID
QUESTION NO.1:
CODE:
#include <iostream>
using namespace std;
class Person{
protected:
string name;
int age;
public:
void input(){
cout<<"Enter name: ";
[Link]();
getline(cin,name);
cout<<"Enter age: ";
cin>>age;
}
void display(){
cout<<"Name: "<<name<< ", Age: "<<age<<endl;
}
};
class Qualification{
string degree;
int experience;
public:
void input(){
cout <<"Enter degree: ";
[Link]();
getline(cin,degree);
cout<<"Enter years of experience: ";
cin>>experience;
}
void display(){
cout<<"Degree: "<<degree<< ", Years of Experience: "<<experience<<"\n";
}
};
class Teacher:public Person{
Qualification q;
public:
void inputTeacher(int num){
cout<<"Enter details for teacher #"<<num<<":\n";
Person::input();
[Link]();
}
void displayTeacher(int num){
cout<<"Teacher #"<<num <<":\n";
Person::display();
[Link]();
}
};
class Student:public Person{
int studentID;
public:
void inputStudent(int num){
cout<<"Enter details for student #"<<num<<":\n";
Person::input();
cout<<"Enter student ID: ";
cin>>studentID;
}
void displayStudent(int num){
cout<<"Student #"<<num<<":\n";
cout<<"Student ID: "<<studentID<<", Name: "<<name<<", Age: "<<age<<endl;
}
};
class Course{
string courseName,courseCode;
public:
void inputCourse(int num){
cout<<"Enter details for course #"<<num<<":\n";
cout<<"Enter course name: ";
[Link]();
getline(cin,courseName);
cout<<"Enter course code: ";
cin>>courseCode;
}
void displayCourse(int num){
cout<<"Course #"<<num << ":\n";
cout<<"Course: "<<courseName<<", Code: "<<courseCode<<endl;
}
};
class Department {
string deptName;
Teacher teachers[10];
Student students[10];
Course courses[10];
int tCount=0,sCount=0,cCount=0;
public:
void setName(string name){
deptName=name;
}
string getName(){
return deptName;
}
void menu(){
int choice;
do{
cout<<"\n--- "<<deptName<<" Department Menu ---\n";
cout<<"1. Add Teacher\n2. Add Student\n3. Add Course\n";
cout<<"4. Display All Teachers\n5. Display All Students\n6. Display All
Courses\n";
cout<<"0. Go Back\n";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice){
case 1:
if(tCount<10){
teachers[tCount].inputTeacher(tCount+1);
tCount++;
cout<<"Teacher added successfully!\n";
}else cout<<"Limit reached!\n";
break;
case 2:
if(sCount<10){
students[sCount].inputStudent(sCount+1);
sCount++;
cout<<"Student added successfully!\n";
} else cout<<"Limit reached!\n";
break;
case 3:
if(cCount<10){
courses[cCount].inputCourse(cCount+1);
cCount++;
cout<<"Course added successfully!\n";
}else cout<<"Limit reached!\n";
break;
case 4:
if(tCount==0){
cout<<"No teachers available.\n";
}else{
cout<<"Teachers in "<<deptName<<" Department:\n";
for(int i=0;i<tCount; i++)
teachers[i].displayTeacher(i+1);
}
break;
case 5:
if(sCount==0){
cout<<"No students available.\n";
}else{
cout<<"Students in "<<deptName<<" Department:\n";
for(int i=0;i<sCount;i++)
students[i].displayStudent(i+1);
}
break;
case 6:
if(cCount==0){
cout<<"No courses available.\n";
}else{
cout<<"Courses in "<<deptName<<" Department:\n";
for(int i=0;i<cCount;i++)
courses[i].displayCourse(i+1);
}
break;
case 0:
cout<<"Going back to main menu\n";
break;
}
} while(choice!=0);
}
};
class University{
Department departments[10];
int dCount=0;
public:
void mainMenu(){
int choice;
do{
cout<<"\n--- University of Lahore Main Menu ---\n";
cout<<"1. Add Department\n2. Show Departments\n3. Enter Department\n0.
Exit\n";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice){
case 1:{
if(dCount<10){
string name;
cout<<"Enter department name: ";
[Link]();
getline(cin, name);
departments[dCount].setName(name);
dCount++;
cout<<"Department added successfully!\n";
}else cout<<"Limit reached!\n";
break;
}
case 2:
if(dCount==0){
cout<<"No departments available.\n";
}else{
for(int i=0;i<dCount;i++)
cout<<i+1<<". "<<departments[i].getName()<<endl;
}
break;
case 3:{
if(dCount==0){
cout<<"No departments available.\n";
break;
}
for(int i=0;i<dCount;i++)
cout<<i+1<<". "<<departments[i].getName()<<endl;
int num;
cout<<"Enter department number to manage: ";
cin>>num;
if(num>0&&num<=dCount)
departments[num-1].menu();
else
cout<<"Invalid choice!\n";
break;
}
}
} while(choice!=0);
}
};
int main() {
University u;
[Link]();
return 0;
}
OUTPUT: