This repository was archived by the owner on Feb 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain copy.cpp
More file actions
189 lines (167 loc) · 4.65 KB
/
Copy pathmain copy.cpp
File metadata and controls
189 lines (167 loc) · 4.65 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
#include <iostream>
using namespace std;
typedef struct Record {
struct Record *next;
int userID;
string userName;
char userAverage;
string userMajor;
int userTitle;
string userDepartment;
} Record;
Record *head = nullptr;
class Person {
public:
string userName;
int userID;
Record * addPerson() {
auto student = static_cast<Record *>(malloc(sizeof(Record)));
cout << ("Enter name: ");
cin >> userName;
cout << ("Enter ID: ");
cin >> userID;
student->userID = userID;
student->userName = userName;
if (findRecord(*student) == 1) {
student = nullptr;
}
return student;
}
void printAbout() {
printf("\nNo records found\n");
printf("\n");
}
private:
int findRecord(Record node) {
Record *student = head;
int checkStatus = 0;
while (student != nullptr) {
if (node.userID == student->userID) {
checkStatus = 1;
}
student = student->next;
}
return checkStatus;
}
};
class Student : Person {
public:
char userAverage;
string userMajor;
void addStudentRecord() {
Record *student = addPerson();
if (student == nullptr) {
printf("Record already exists\n");
printf("\n");
}
else {
cout << ("Enter average: ");
cin >> userAverage;
cout << ("Enter major: ");
cin >> userMajor;
student->userAverage = userAverage;
student->userMajor = userMajor;
student->next = head;
head = student;
}
}
void printAbout(char major, Record Student) {
cout << Student.userAverage << ", ";
cout << Student.userMajor << endl;
}
};
class Teacher : Person {
public:
int userTitle;
string userDepartment;
void addTeacherRecord() {
Record *teacher = addPerson();
if (teacher == nullptr) {
printf("Record already exists\n");
printf("\n");
}
else {
cout << ("Enter title: (1 if lecturer ; 2 if assistant professor ; 3 if associate professor.)");
cin >> userTitle;
while (userTitle < 1 || userTitle > 3) {
cout << ("That is not a valid choice\n Enter your Title: \n");
cin >> userTitle;
}
cout << ("Enter department: ");
cin >> userDepartment;
teacher->userTitle = userTitle;
teacher->userDepartment = userDepartment;
teacher->next = head;
head = teacher;
}
}
void printAbout(int title, Record Teacher) {
if (Teacher.userTitle == 1) {
cout << "Lecturer, ";
}
else if (Teacher.userTitle == 2) {
cout << "Assistant Professor, ";
}
else {
cout << "Associate Professor, ";
}
cout << Teacher.userDepartment << endl;
}
};
int displayMenu() {
int myNum;
cout << (" Welcome to RU Record Management\n\n");
cout << (" Press\n");
cout << (" 1 to create a new Student Record\n");
cout << (" 2 to create a new Teacher Record\n");
cout << (" 3 to view all records\n");
cout << (" 4 to exit\n\n");
cout << ("Enter your Choice (ONLY DIGITS): \n");
cin >> myNum;
while (myNum < 1 || myNum > 4) {
printf("That is not a valid choice\n Enter your Choice: \n");
cin >> myNum;
}
return myNum;
}
int main() {
int myNum;
Student myStudent;
Teacher myTeacher;
Person myPerson;
myNum = displayMenu();
while (myNum != 4) {
if (myNum == 3) {
Record *person = head;
char letter = 'A';
int number = 0;
printf("\n");
if (person == nullptr) {
myPerson.printAbout();
}
while (person != nullptr) {
cout << person->userName << ", ";
cout << person->userID << ", ";
if (person->userTitle == 0) {
myStudent.printAbout(letter, *person);
}
else {
myTeacher.printAbout(number, *person);
}
person = person->next;
}
printf("\n");
myNum = displayMenu();
}
else if (myNum == 1){
myStudent.addStudentRecord();
myNum = displayMenu();
}
else {
myTeacher.addTeacherRecord();
myNum = displayMenu();
}
}
free(head);
return 0;
}