-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearner.cpp
More file actions
136 lines (126 loc) · 3.34 KB
/
learner.cpp
File metadata and controls
136 lines (126 loc) · 3.34 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
#include "learner.h"
#include <ctime>
#include <fstream>
#include <ios>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
void learner::getID(int serial) { ID = serial; }
void learner::rateUs() {
double rate;
cout << "\nRate something out of 5: ";
cin >> rate;
rate *= 1.00;
if (rate < 0 || rate > 5) {
cout << "I\nnvalid rating!!" << endl;
return;
}
ofstream rateFile("ratings.txt", ios::app);
rateFile << ' ' << username << ' ' << rate;
cout << "\nThanks for your rating ;)" << endl;
}
void learner::enroll() {
ofstream enrollFile("enrolled.txt", ios::app);
ifstream courseFile("courses.txt", ios::app);
int courseNo, checkOTP;
std::srand(std::time(0));
int random_number = 1000 + (std::rand() % (9000));
cout << "\nYour OTP: " << random_number;
cout << "\nConfirm OTP: ";
cin >> checkOTP;
if (random_number != checkOTP) {
cout << "\nIncorrect OTP!" << endl;
return;
}
cout << "\nEnter the Course-No. you want to enroll: ";
cin >> courseNo;
string cn = to_string(courseNo);
string cnf;
bool found = false;
while (!courseFile.eof()) {
getline(courseFile, cnf, ',');
if (cnf == cn) {
found = true;
break;
}
}
if (found) {
enrollFile << ' ' << courseNo << ' ' << username;
cout << "\nEnrolled Successfully!" << endl;
} else {
cout << "\nCourse not found!!" << endl;
}
enrollFile.close();
courseFile.close();
}
void learner::learnersMenu() {
while (true) {
cout << "\n1. See the courses.\n";
cout << "2. Enroll a course.\n";
cout << "3. Rate Us.\n";
cout << "4. Log out.\n";
cout << "Select an option: ";
int option;
cin >> option;
switch (option) {
case 1:
ins.showCourses();
break;
case 2:
enroll();
break;
case 3:
rateUs();
break;
case 5:
return;
default:
cout << "\nInvalid Option!" << endl;
return;
}
}
}
void learner::registration(int serial) {
cout << "\n[N.B. Username must be a single word. You may use your "
"nickname.\n";
cout
<< "Else, use hypen(-) of underscore(_) instead of space if you have a "
"bigger name]\n"
<< endl;
cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
cin >> password;
getID(serial);
}
int learner::login() {
int id;
cout << "\nEnter your ID no: ";
cin >> id;
getID(id);
cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
cin >> password;
return id;
}
void learner::operator==(learner l2) {
if (!strcmp(username, l2.username)) {
if (!strcmp(password, l2.password)) {
cout << "\nLogin Succeeded!" << endl;
cout << "Welcome " << username << " to our platform :)" << endl;
learner::learnersMenu();
} else {
cout << "\nIncorrect Password!" << endl;
}
} else {
cout << "\nInvalid Username!";
}
return;
}
void learner::showData() const {
cout << "ID: " << ID << endl;
cout << "Name: " << username << endl;
cout << "Pass: " << password << endl;
}