-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombined_main.cpp
More file actions
212 lines (180 loc) · 5.87 KB
/
Combined_main.cpp
File metadata and controls
212 lines (180 loc) · 5.87 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
212
#include <bits/stdc++.h>
class student
{
private:
friend class Enrollment;
static int student_count;
int mobile_number;
unsigned short int courses_count = 0;
protected:
std ::vector<int> courses;
std ::string name;
std ::string roll_number;
struct dob
{
int day = 0;
int month = 0; // if we see these value 0 then we can use it for error handling
int year = 0;
} stud;
public:
student(void){/*do nothing constructor*/};
student(std::string name, std ::string roll_number, int day_dob, int month_dob, int year_dob, int mobile_number)
{
this->name = name;
this->roll_number = roll_number;
this->mobile_number = mobile_number;
stud.day = day_dob;
stud.month = month_dob;
stud.year = year_dob;
student_count++;
}
void getdata();
};
int student ::student_count = 0;
void student ::getdata()
{
std ::cout << "---------------------------------------------" << std ::endl;
std ::cout << "Student Name :: " << name << std ::endl;
std ::cout << "Student Roll number :: " << roll_number << std ::endl;
std ::cout << "Student Date of Birth is :: " << stud.day << "/" << stud.month << "/" << stud.year << std ::endl;
std ::cout << "Student Mobile number is :: " << mobile_number << std ::endl
<< std ::endl;
std::cout << "Total = " << student_count << "\n";
std ::cout << "---------------------------------------------" << std ::endl;
}
class course
{
protected:
static int course_count;
static std::set<std::pair<int, std::string>> all_courses;
};
class new_course : private course
{
private:
friend class Enrollment;
friend class professor;
std::string course_name;
int course_id;
std ::string course_password = "m", temp;
protected:
int get_course_id() { return course_id; }
std ::string get_course_name() { return course_name; }
std ::vector<std::string> enrolled_students;
public:
new_course(void)
{ /*default constructor*/
}
new_course(int id, std ::string course_name)
{
std ::cout << "This requires authentifiaction, Enter password :: ";
std ::cin >> temp;
if (temp == course_password)
{
this->course_id = id;
course_count++;
this->course_name = course_name;
// Initialize the enrolled_students vector here
enrolled_students = std::vector<std::string>();
all_courses.insert(std::make_pair(id, course_name));
}
else
{
std ::cout << "wrong password\n";
return;
}
}
void get_course_data()
{
std::cout << course_name << "\n";
std::cout << course_id << "\n";
std::cout << course_count << "\n";
}
};
int course ::course_count = 0;
std::set<std::pair<int, std::string>> course::all_courses;
// class Enrollment : private student, new_course
// {
// public:
// Enrollment(student& student1, new_course& new_course1)
// {
// student1.courses.push_back(new_course1.get_course_id());
// new_course1.enrolled_students.push_back(roll_number);
// }
// ~Enrollment(){}
// };
class Enrollment : private student, new_course
{
public:
Enrollment(student &student1, new_course &new_course1) : student(student1), new_course(new_course1)
{
student1.courses.push_back(new_course1.get_course_id());
new_course1.enrolled_students.push_back(student1.roll_number);
}
~Enrollment() {}
};
class Enroll
{
public:
Enroll(student &student1, new_course &n)
{
// Correctly enroll the student in the course
Enrollment new_student(student1, n);
}
};
class professor : private new_course
{
public:
void see_students_in_my_course(new_course &t)
{
std ::cout << "course name :: " << t.get_course_name() << std::endl;
std ::cout << "course id :: " << t.get_course_id() << std ::endl;
std ::cout << "\n\tStudents in my course are:\n";
for (int i = 0; i < t.enrolled_students.size(); i++)
{
std ::cout << t.enrolled_students[i] << std::endl;
}std::cout<<"\n\n";
}
};
// int main()
// {
// student s("john", "1858", 11, 6, 1980, 988887); // Create a student object
// s.getdata();
// new_course maths(1, "maths");
// maths.get_course_data();
// Enroll E(s, maths);
// professor p;
// // Pass the "maths" course object to the professor's method
// p.see_students_in_my_course(maths);
// return 0;
// }
int main()
{
// Create 6 students
student student1("John", "1858", 11, 6, 1980, 988887);
student student2("Alice", "1859", 12, 7, 1981, 988888);
student student3("Bob", "1860", 10, 8, 1982, 988889);
student student4("Eve", "1861", 9, 9, 1983, 988890);
student student5("Charlie", "1862", 8, 10, 1984, 988891);
student student6("Grace", "1863", 7, 11, 1985, 988892);
// Create 6 different courses
new_course course1(1, "Maths");
new_course course2(2, "Physics");
new_course course3(3, "Chemistry");
new_course course4(4, "Biology");
new_course course5(5, "History");
new_course course6(6, "Literature");
// Make students take different numbers of courses
Enroll enroll1(student1, course1);
Enroll enroll2(student2, course1);
Enroll enroll3(student3, course2);
Enroll enroll4(student4, course3);
Enroll enroll5(student5, course2);
Enroll enroll6(student6, course4);
professor p[6];
p[0].see_students_in_my_course(course1);
p[2].see_students_in_my_course(course2);
p[3].see_students_in_my_course(course3);
p[4].see_students_in_my_course(course4);
p[5].see_students_in_my_course(course5);
return 0;
}