-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.cpp
More file actions
211 lines (202 loc) · 7.9 KB
/
Project.cpp
File metadata and controls
211 lines (202 loc) · 7.9 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
Name: Fares Elbermawy.
Project description: Simulating a university which has three courses that they offer. Each course has its
own lecturer and students. But there are some conditions for students. First, if the student is from
another university they are only allowed to enroll in one course. Second, there cannot be two students
with the same email enrolled in the same course. Each course has a max of 10 participants and minimum of
3. If it is less than 3 it won't be conducted. After enrolling all students, We print out all the courses
and the participants including a message if the course won't be conducted. Then printing the courses which
are not fully booked with their name, number of free places, and the name of the lecturer and their title.
Lastly, print the data of participants who should be notified that their course would not be conducted.
*/
#include <iostream>
#include <vector>
using namespace std;
//A universal variable stating the name of the university we are in.
string universityName = "THD";
//Making the parent class person which includes child classes who are students and lecturers.
class PERSON
{
protected:
//Each person has their own Surname,first name, and email address.
string surname;
string firstName;
string email;
public:
PERSON(string surname, string firstName, string email)
{
this -> surname = surname;
this -> firstName = firstName;
this -> email = email;
}
};
//Making the child class Lecturer
class LECTURER: public PERSON
{
//Each lecturer has their academic title in addition.
string academic_title;
public:
LECTURER(string surname, string firstName, string email, string academic_title): PERSON(surname, firstName, email)
{
this -> academic_title = academic_title;
}
//Getting the lecturer full name and academic title
string lecturerName()
{
return this -> academic_title + ' ' + this -> firstName + ' ' + this -> surname;
}
} ;
//Making the child class student.
class STUDENT: public PERSON
{
//Each student has their own matriculation number, university which they are enrolled in, and the number of courses they are enrolled in.
int matriculationNumber;
string university;
int coursesTaken = 0;
public:
STUDENT(string surname, string firstName, string email, int matriculationNumber, string university): PERSON(surname, firstName, email)
{
this -> matriculationNumber = matriculationNumber;
this -> university = university;
}
//Checking if the student is allowed to take another course or not.
bool isAllowed()
{
if (coursesTaken > 0 && university != universityName)
{
return false;
}
return true;
}
//Getting the email of the student to check with it if there is duplicate emails in the same course.
string getEmail()
{
return this -> email;
}
//Printing all the data of the student.
void printData()
{
cout << "Name: " << this -> firstName << " " << this -> surname << endl;
cout << "email: " << getEmail() << endl;
cout << "matriculation Number: " << this -> matriculationNumber << endl;
cout << "University: " << this -> university << endl;
}
} ;
//Making a course class.
class COURSE
{
//Each course has its own name, lecturer, and list of students participating in it.
string courseName;
LECTURER lecturer;
vector <STUDENT> participants;
public:
COURSE(string courseName, LECTURER lecturer): lecturer(lecturer)
{
this -> courseName = courseName;
}
string getName()
{
return courseName;
}
//Method to add a student to the course
void addParticipant(STUDENT student)
{
//Checking if the course has reached the limit and if the student is allowed to take the course.
if (participants.size() < 10 && student.isAllowed())
{
//Checking if there is another student registered with the same email in the same course.
for (int i = 0; i < participants.size(); i++)
{
if (participants[i].getEmail() == student.getEmail())
{
cout << "Error! Duplicate email has been found." << endl;
return;
}
}
participants.push_back(student);
}
else
{
cout << "Error! Maximum participants reached or this student has the max limit of courses." << endl;
}
}
//Checking if the number of participants is enough to start the course.
bool takesPlace()
{
if (participants.size() >= 3)
return true;
return false;
}
//Printing our the course name and the data of the participants in it.
void participantsData()
{
cout << "Course name: " << courseName << endl;
for (int i = 0; i < participants.size(); i++)
{
participants[i].printData();
}
}
//Checking if the course is not fully booked.
void notFullyBooked()
{
//Making the condition here to spare lines from the main function
if (participants.size() < 10)
{
cout << "Name of the course: " << courseName << endl;
cout << "The number of free places are: " << 10 - participants.size() << endl;
cout << "Name of the lecturer: " << lecturer.lecturerName() << endl;
}
}
};
int main()
{
int coursesNumber = 3;
//Making objects of the lecturer class for the three programs.
LECTURER programmingLecturer("Doe", "John", "[email protected]", "Dr.");
LECTURER databasesLecturer("Smith", "Mike", "[email protected]", "Prof.");
LECTURER softwareLecturer("Lee", "Sarah", "[email protected]", "Prof.Dr.");
//Making objects of the three courses and storing them in an array.
vector <COURSE> courses = {COURSE("Programming", programmingLecturer), COURSE("Databases", databasesLecturer), COURSE("Software Engineer", softwareLecturer)};
//Making objects of students.
STUDENT student1("Dean", "Lina", "[email protected]", 12345, "THD");
STUDENT student2("Mueller", "Liza", "[email protected]", 12335, "THD");
STUDENT student3("Bauer", "Marko", "[email protected]", 34012, "TUM");
STUDENT student4("Patel", "Mila", "[email protected]", 4519, "FAU");
STUDENT student5("Smith", "Alex", "[email protected]", 122345, "THD");
//Enrolling students to courses.
courses[0].addParticipant(student1);
courses[0].addParticipant(student2);
courses[0].addParticipant(student3);
courses[1].addParticipant(student4);
courses[2].addParticipant(student5);
courses[2].addParticipant(student4); //this should give an error because this student isn't allowed to take more than one course.
//Outputting all the courses with the participants.
cout << "Courses that are available: " << endl;
for(int i = 0; i < coursesNumber; i++)
{
courses[i].participantsData();
if (!courses[i].takesPlace())
{
cout << "Course will not take place." << endl;
}
cout << endl;
}
//Printing the courses that are not fully booked yet
cout << "Courses that are not fully booked: " << endl;
for(int i = 0; i < coursesNumber; i++)
{
courses[i].notFullyBooked();
cout << endl;
}
//Printing the participants data which should be notified that their course will not take place
cout << "These participants should be notified that their course will not take place: " << endl;
for (int i = 0; i < coursesNumber; i++)
{
if (!courses[i].takesPlace())
{
courses[i].participantsData();
cout << endl;
}
}
return 0;
}