-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
146 lines (131 loc) · 3.7 KB
/
main.cpp
File metadata and controls
146 lines (131 loc) · 3.7 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
#include "abstract.h"
#include "instructor.h"
#include "learner.h"
#include "rating.h"
#include <fstream>
#include <iostream>
using namespace std;
void regMenu(learner &l1, learner &l2, instructor &i1) {
fstream file;
file.open("Learners.dat", ios::app | ios::in | ios::out | ios::binary);
file.seekg(0, ios ::end);
int ts = file.tellg();
int serial = ts / sizeof(learner);
++serial;
int i, pos;
cout << "\n------------------------------------";
cout << "\n*********** REGISTRATION ***********\n";
cout << "------------------------------------\n";
cout << "1. Register as an Instructor." << endl;
cout << "2. Register as a Learner." << endl;
cout << "3. Return to HOMEPAGE." << endl;
cout << "4. Exit." << endl;
int option;
cout << "Choose an option: ";
cin >> option;
switch (option) {
case 1:
i1.registration();
break;
case 2:
l1.registration(serial);
file.write(reinterpret_cast<char *>(&l1), sizeof(l1));
cout << "\nRegistration is successful.\nYour ID no. is: " << serial
<< ".\nPreserve this ID number for future logins.\n"
<< endl;
l1.learnersMenu();
break;
case 3:
return;
case 4:
cout << "\nBest of Luck! Goodbye..." << endl;
exit(0);
break;
}
file.close();
}
void logMenu(learner &l1, learner &l2, instructor &i1) {
fstream file;
file.open("Learners.dat", ios::app | ios::in | ios::out | ios::binary);
file.seekg(0, ios ::end);
int ts = file.tellg();
int serial = ts / sizeof(learner);
++serial;
int i, pos;
cout << "\n--------------------------------";
cout << "\n************ LOG IN ************\n";
cout << "--------------------------------\n";
cout << "1. Login as an Instructor." << endl;
cout << "2. Login as a Learner." << endl;
cout << "3. Return to HOMEPAGE." << endl;
cout << "4. Exit." << endl;
int option;
cout << "Choose an option: ";
cin >> option;
switch (option) {
case 1:
i1.login();
break;
case 2:
i = l1.login();
pos = (i - 1) * sizeof(learner);
file.seekg(pos);
file.read(reinterpret_cast<char *>(&l2), sizeof(l2));
l1 == l2;
cout << endl;
break;
case 3:
return;
case 4:
cout << "\nBest of Luck! Goodbye..." << endl;
exit(0);
default:
cout << "Invalid Option! Please try again..." << endl;
return;
}
file.close();
}
void MainMenu(learner &l1, learner &l2, instructor &i1, abstruct *&abst) {
cout << "####################################" << endl;
cout << "# HOMEPAGE #" << endl;
cout << "####################################" << endl;
cout << "1. Register/Sign up" << endl;
cout << "2. Login / Sign in" << endl;
cout << "3. View Courses as a Guest" << endl;
cout << "4. See who rated us" << endl;
cout << "5. Exit" << endl;
int option;
cout << "Choose an option: ";
cin >> option;
switch (option) {
case 1:
regMenu(l1, l2, i1);
break;
case 2:
logMenu(l1, l2, i1);
break;
case 3:
i1.showCourses();
break;
case 4:
abst->showRatings();
break;
case 5:
cout << "\nBest of Luck! Goodbye..." << endl;
exit(0);
break;
default:
cout << "\nInvalid Option! Please try again." << endl;
break;
}
}
int main() {
learner l1, l2;
instructor i1;
abstruct *abst = new rating(); // Dynamic Binding
fstream file; // File System
while (true) {
MainMenu(l1, l2, i1, abst);
}
return 0;
}