Commit 47d0d47c authored by Andrew Binder's avatar Andrew Binder

Error checking for student enrollment/teacher username change, now a new name...

Error checking for student enrollment/teacher username change, now a new name can't already exist in the program
parent 1fa47ce4
......@@ -5,6 +5,7 @@
// *****************************************************************************
#include "Teacher.h"
#include "Questions.h"
#include <iostream>
#include <fstream>
......@@ -69,7 +70,7 @@ void Teacher::displayMenu() {
cout << "Your username is currently " << userName << "." << endl;
cout << "Please input a new username: ";
cin >> stringIn;
setUserName(stringIn); // ******* Check for student username
setUserName(stringIn);
break;
case 6: // Change Exit Code
cout << "The exit code is currently " << exitCode << "." << endl;
......@@ -178,13 +179,16 @@ void Teacher::enrollStudent(string studentIn) {
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 (validName == -1) {
roster.push_back(studentIn);
cout << "Student succesfully enrolled." << endl;
if (studentIn == userName) {
cout << "Error: Username same as teacher username!" << endl;
} else {
cout << "Error: Student already exists!" << endl;
// If the name is valid, enroll the student, otherwise output an error
if (validName == -1) {
roster.push_back(studentIn);
cout << "Student succesfully enrolled." << endl;
} else {
cout << "Error: Student already exists!" << endl;
}
}
}
......@@ -194,9 +198,9 @@ void Teacher::enrollStudent(string studentIn) {
void Teacher::adjustProgress(string studentUserNameIn, int level) {
int studentNumber = checkRoster(studentUserNameIn); // Check if student exists/Get student position in vector
Student *studentLevel = new Student;
Questions *maxLevel = new Questions;
if (level > studentLevel.getMaxLevel()) {
if (level > maxLevel->getMaxLevel()) {
cout << "Error: Level too high!" << endl;
} else {
// If the username exists, change the level and output success to console
......@@ -210,7 +214,7 @@ void Teacher::adjustProgress(string studentUserNameIn, int level) {
}
}
delete studentLevel;
delete maxLevel;
}
// Saves and ends program safely and gracefully
......@@ -252,9 +256,11 @@ void Teacher::setExitCode(string exitCodeIn) {
}
void Teacher::setUserName(string userNameIn) {
userName = userNameIn;
// Check if username exists in student vector ********
if (checkRoster(userNameIn) == -1) {
userName = userNameIn;
} else {
cout << "Error: Username exists in student roster!" << endl;
}
}
void Teacher::setStudent(Student studentIn) {
......
......@@ -28,4 +28,8 @@ int main() {
} while (true);
return 0;
}
\ No newline at end of file
}
#include "Student.cpp"
#include "Teacher.cpp"
#include "Questions.cpp"
\ 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