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,16 +194,23 @@ void Teacher::enrollStudent(string studentIn) { ...@@ -192,16 +194,23 @@ 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
// If the username exists, change the level and output success to console Student *studentLevel = new Student;
// Otherwise, output an error
if (studentNumber >= 0) { if (level > studentLevel.getMaxLevel()) {
int lastLevel = roster.at(studentNumber).getLevel(); cout << "Error: Level too high!" << endl;
roster.at(studentNumber).setLevel(level);
cout << roster.at(studentNumber).getUserName() << "'s level was changed from level " << lastLevel << " to " << roster.at(studentNumber).getLevel() << "." << endl;
} else { } else {
cout << "Error: Student not found!" << endl; // If the username exists, change the level and output success to console
// Otherwise, output an error
if (studentNumber >= 0) {
int lastLevel = roster.at(studentNumber).getLevel();
roster.at(studentNumber).setLevel(level);
cout << roster.at(studentNumber).getUserName() << "'s level was changed from level " << lastLevel << " to " << roster.at(studentNumber).getLevel() << "." << endl;
} else {
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) {
......
...@@ -55,4 +55,6 @@ class Teacher { ...@@ -55,4 +55,6 @@ class Teacher {
}; };
#endif //TEACHER_H #endif //TEACHER_H
\ No newline at end of file
//
\ 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