-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment-2.cpp
More file actions
154 lines (124 loc) · 4.07 KB
/
Copy pathAssignment-2.cpp
File metadata and controls
154 lines (124 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Base class Person
class Person {
protected:
string name;
int age;
string ID;
string contactInfo;
public:
Person(string name, int age, string ID, string contactInfo)
: name(name), age(age), ID(ID), contactInfo(contactInfo) {}
virtual void displayDetails() const {
cout << "Name: " << name << ", Age: " << age << ", ID: " << ID
<< ", Contact: " << contactInfo << endl;
}
virtual double calculatePayment() const { return 0.0; }
virtual ~Person() {}
};
// Derived class Student
class Student : public Person {
private:
string enrollmentDate;
string program;
float GPA;
public:
Student(string name, int age, string ID, string contactInfo,
string enrollmentDate, string program, float GPA)
: Person(name, age, ID, contactInfo), enrollmentDate(enrollmentDate),
program(program), GPA(GPA) {}
void displayDetails() const override {
Person::displayDetails();
cout << "Enrollment Date: " << enrollmentDate
<< ", Program: " << program << ", GPA: " << GPA << endl;
}
double calculatePayment() const override { return 5000.0; }
};
// Derived class Professor
class Professor : public Person {
private:
string department;
string specialization;
string hireDate;
public:
Professor(string name, int age, string ID, string contactInfo,
string department, string specialization, string hireDate)
: Person(name, age, ID, contactInfo), department(department),
specialization(specialization), hireDate(hireDate) {}
void displayDetails() const override {
Person::displayDetails();
cout << "Department: " << department
<< ", Specialization: " << specialization
<< ", Hire Date: " << hireDate << endl;
}
double calculatePayment() const override { return 80000.0; }
};
// Class Course
class Course {
private:
string code;
string title;
int credits;
string description;
public:
Course(string code, string title, int credits, string description)
: code(code), title(title), credits(credits), description(description) {}
void displayDetails() const {
cout << "Course Code: " << code << ", Title: " << title
<< ", Credits: " << credits << ", Description: " << description << endl;
}
};
// Class Department
class Department {
private:
string name;
string location;
double budget;
public:
Department(string name, string location, double budget)
: name(name), location(location), budget(budget) {}
void displayDetails() const {
cout << "Department: " << name << ", Location: " << location
<< ", Budget: $" << budget << endl;
}
};
// Class GradeBook
class GradeBook {
private:
vector<pair<string, float>> grades;
public:
void addGrade(string studentID, float grade) {
grades.push_back({studentID, grade});
}
float calculateAverageGrade() {
float sum = 0;
for (const auto& entry : grades) {
sum += entry.second;
}
return grades.empty() ? 0.0f : sum / grades.size();
}
};
// Class EnrollmentManager
class EnrollmentManager {
private:
vector<pair<string, string>> enrollments;
public:
void enrollStudent(string studentID, string courseCode) {
enrollments.push_back({studentID, courseCode});
}
int getEnrollmentCount() { return enrollments.size(); }
};
void testPolymorphism(Person* person) {
person->displayDetails();
cout << "Payment: $" << person->calculatePayment() << endl;
}
int main() {
Student s1("Karan", 20, "S123", "karan@example.com", "2023-09-01", "Computer Science", 3.8);
Professor p1("Ishatv", 25, "P456", "ishatv@example.com", "Engineering", "Data Science", "2015-06-20");
testPolymorphism(&s1);
testPolymorphism(&p1);
return 0;
}