Commit e755f593 authored by Andrew Binder's avatar Andrew Binder

Error checking for userrnames

parent 899b96b2
...@@ -15,7 +15,7 @@ ifstream fin; ...@@ -15,7 +15,7 @@ ifstream fin;
// Input: none // Input: none
// Output: object with teacher username of NULL // Output: object with teacher username of NULL
Teacher::Teacher() { Teacher::Teacher() {
userName = "NULL"; userName = "teacher";
} }
// Default Constructor // Default Constructor
...@@ -69,7 +69,7 @@ void Teacher::displayMenu() { ...@@ -69,7 +69,7 @@ void Teacher::displayMenu() {
cout << "Your username is currently " << userName << "." << endl; cout << "Your username is currently " << userName << "." << endl;
cout << "Please input a new username: "; cout << "Please input a new username: ";
cin >> stringIn; cin >> stringIn;
setUserName(stringIn); setUserName(stringIn); // ******* Check for student username
break; break;
case 6: // Change Exit Code case 6: // Change Exit Code
cout << "The exit code is currently " << exitCode << "." << endl; cout << "The exit code is currently " << exitCode << "." << endl;
...@@ -177,6 +177,8 @@ void Teacher::importProgress() { ...@@ -177,6 +177,8 @@ void Teacher::importProgress() {
void Teacher::enrollStudent(string studentIn) { void Teacher::enrollStudent(string studentIn) {
int validName = checkRoster(studentIn); // Check if username exists in roster int validName = checkRoster(studentIn); // Check if username exists in roster
// Check for teacher username ***********
// If the name is valid, enroll the student, otherwise output an error // If the name is valid, enroll the student, otherwise output an error
if (validName == -1) { if (validName == -1) {
roster.push_back(studentIn); roster.push_back(studentIn);
...@@ -192,6 +194,11 @@ void Teacher::enrollStudent(string studentIn) { ...@@ -192,6 +194,11 @@ void Teacher::enrollStudent(string studentIn) {
void Teacher::adjustProgress(string studentUserNameIn, int level) { void Teacher::adjustProgress(string studentUserNameIn, int level) {
int studentNumber = checkRoster(studentUserNameIn); // Check if student exists/Get student position in vector int studentNumber = checkRoster(studentUserNameIn); // Check if student exists/Get student position in vector
Student *studentLevel = new Student;
if (level > studentLevel.getMaxLevel()) {
cout << "Error: Level too high!" << endl;
} else {
// If the username exists, change the level and output success to console // If the username exists, change the level and output success to console
// Otherwise, output an error // Otherwise, output an error
if (studentNumber >= 0) { if (studentNumber >= 0) {
...@@ -201,7 +208,9 @@ void Teacher::adjustProgress(string studentUserNameIn, int level) { ...@@ -201,7 +208,9 @@ void Teacher::adjustProgress(string studentUserNameIn, int level) {
} else { } else {
cout << "Error: Student not found!" << endl; cout << "Error: Student not found!" << endl;
} }
}
delete studentLevel;
} }
// Saves and ends program safely and gracefully // Saves and ends program safely and gracefully
...@@ -244,6 +253,8 @@ void Teacher::setExitCode(string exitCodeIn) { ...@@ -244,6 +253,8 @@ void Teacher::setExitCode(string exitCodeIn) {
void Teacher::setUserName(string userNameIn) { void Teacher::setUserName(string userNameIn) {
userName = userNameIn; userName = userNameIn;
// Check if username exists in student vector ********
} }
void Teacher::setStudent(Student studentIn) { void Teacher::setStudent(Student studentIn) {
......
...@@ -56,3 +56,5 @@ class Teacher { ...@@ -56,3 +56,5 @@ class Teacher {
}; };
#endif //TEACHER_H #endif //TEACHER_H
//
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment