-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.cpp
More file actions
119 lines (97 loc) · 2.05 KB
/
Copy pathCourse.cpp
File metadata and controls
119 lines (97 loc) · 2.05 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
#include <iostream>
#include "Course.h"
using namespace std;
Course::Course()
{
courseCode = "";
courseName = "";
instructor = nullptr;
for(int i = 0; i<30;i++)
{
studentList[i] = nullptr;
}
}
Course::~Course()
{
}
Course::Course(string _courseCode, string _courseName)
{
instructor = nullptr;//prevent crashes
for(int i = 0; i<30;i++)
{
studentList[i] = nullptr;
}
courseCode = _courseCode;
courseName = _courseName;
}
void Course::display(bool student, bool teacher)
{
cout << "courseCode: " << courseCode << endl << "courseName: " << courseName << endl;
if(teacher)
{
cout << "instructor: " << endl;
if(instructor != nullptr)
{
instructor->display(false);
cout << endl;
}
else {
cout << "N/A" << endl;
}
}
if(student)
{
cout << "Student List: " << endl;
for(int i = 0; i<30;i++)
{
if(studentList[i] != nullptr)
{
studentList[i]->display(false);
cout << endl;
}
}
}
return;
}
void Course::assignTeacher(Teacher * _instructor)
{
if(instructor != nullptr)
{
instructor->removeCourse(this);//ability to overwrite a teacher
}
instructor = _instructor;
return;
}
void Course::assignStudent(Student * _student)
{
int i = 0;
while(studentList[i] != nullptr and i != 29)
{
i++;
} //sets i to right value or exits when it reaches 29
if(studentList[i] == nullptr)
{
studentList[i] = _student;
}
else
{
cout << "Full" <<endl; //since it could be full.
}//overwriting a student would be more troublesome since due to there being multiple students, some1 could easily accidenity overwrite a student by not looking at the current number of students.
return;
}
void Course::removeTeacher()
{
instructor = nullptr;//only 1 teacher to remove;
return;
}
void Course::removeStudent(Student * _student)
{
for(int i = 0; i<30; i++)
{
if(studentList[i] == _student)
{
studentList[i] = nullptr;
}
}
return;
}