Commit 0e980f54 authored by Andrew Binder's avatar Andrew Binder

Working versions and comments

parent 4f63ceb4
......@@ -7,20 +7,31 @@
ofstream fout;
ifstream fin;
Teacher::Teacher() {}
// Default Constructor
// Input: none
// Output: object with teacher username of NULL
Teacher::Teacher() {
userName = "NULL";
}
// Default Constructor
// Input: Username for teacher
// Output: object with teacher username of whatever is input
Teacher::Teacher(string userNameIn) {
userName = userNameIn;
}
// Runs Teacher Menu
// Input: A user's menu selection
// Output: Changes are made based on users input
void Teacher::displayMenu() {
teacherMenuActive = true;
int menu, levelIn;
string stringIn;
cout << endl << "Teacher Menu" << endl << endl;
cout << "1. Display Class Progress" << endl;
cout << "2. Export Class Progress" << endl;
cout << "1. Display Class Gradebook" << endl;
cout << "2. Export Class Gradebook" << endl;
cout << "3. Enroll Students" << endl;
cout << "4. Adjust Student Progress" << endl;
cout << "5. Change Username" << endl;
......@@ -31,14 +42,14 @@ void Teacher::displayMenu() {
cin >> menu;
if (cin) {
switch(menu) {
case 1:
case 1: // Display Class Gradebook
displayProgress();
break;
case 2:
case 2: // Exports Class Gradebook
exportProgress();
cout << "Gradebook exported succesfully." << endl;
break;
case 3:
case 3: // Enroll Student
{
cout << "Please enter a username (no spaces): ";
cin >> stringIn;
......@@ -46,24 +57,24 @@ void Teacher::displayMenu() {
enrollStudent(studentIn);
break;
}
case 4:
case 4: // Adjust Student Progress
cout << "Please enter the student's username followed by a level: ";
cin >> stringIn >> levelIn;
adjustProgress(stringIn, levelIn);
break;
case 5:
case 5: // Change Teacher Username
cout << "Your username is currently " << userName << "." << endl;
cout << "Please input a new username: ";
cin >> stringIn;
setUserName(stringIn);
break;
case 6:
case 6: // Change Exit Code
cout << "The exit code is currently " << exitCode << "." << endl;
cout << "Please input a new exit code: ";
cin >> stringIn;
setExitCode(stringIn);
break;
case 7:
case 7: // Log Out
saveProgress();
cout << "Goodbye." << endl;
teacherMenuActive = 0;
......@@ -80,6 +91,9 @@ void Teacher::displayMenu() {
}
}
// Display Class Gradebook
// Input: none
// Output: text to console of each student and their level
void Teacher::displayProgress() {
cout << userName << "'s Class Progress Report" << endl << endl;
cout.width(10);
......@@ -91,6 +105,9 @@ void Teacher::displayProgress() {
}
}
// Export Class Gradebook
// Input: none
// Output: Exports a file with each student username and their level
void Teacher::exportProgress() {
fout.open(progressFileName);
......@@ -106,6 +123,9 @@ void Teacher::exportProgress() {
fout.close();
}
// Export roster/levels
// Input: none
// Output: File with each field seperated with a space or line break
void Teacher::saveProgress() {
fout.open(rosterFileName);
......@@ -113,39 +133,56 @@ void Teacher::saveProgress() {
for (int i = 0; i < roster.size(); i++) {
fout << roster.at(i).getUserName() << " " << roster.at(i).getLevel() << endl;
}
// Marks the end of the file for importer
fout << "END_OF_FILE";
fout.close();
}
// Import roster/levels
// Input: file from saveProgress()
// Output: Sets teacher username and exit code, also populates vector with student username/progress
void Teacher::importProgress() {
string parseName;
int parseLevel;
fin.open(rosterFileName);
// First line is Teacher username and exit code seperated by space
fin >> userName >> exitCode;
while (true) {
// Checks next line to see if there's a student
fin >> parseName;
if (parseName == "END_OF_FILE") {
// If there isn't a student, end import
break;
} else {
// If there is student, read its level
fin >> parseLevel;
}
// If there is a student, create a student and add it to the studen vector
Student studentIn(parseName, parseLevel);
roster.push_back(studentIn);
}
fin.close();
}
// Enroll a new student
// Input: student username
// Output: success or not
void Teacher::enrollStudent(Student studentIn) {
bool validName = 1;
bool validName = 1; //Assume name is valid
// Determine if the username already exists in the vector
// If it does, set validName to false
for (int i = 0; i < roster.size(); i++) {
if (roster.at(i).getUserName() == studentIn.getUserName()) {
validName = 0;
}
}
// If the name is valid, enroll the student, otherwise output an error
if (validName) {
roster.push_back(studentIn);
cout << "Student succesfully enrolled." << endl;
......@@ -154,12 +191,16 @@ void Teacher::enrollStudent(Student studentIn) {
}
}
// Change Student's Progress
// Input: Student's username and new level
// Output: Changed student within the roster vector and success or not
void Teacher::adjustProgress(string studentUserNameIn, int level) {
int
lastLevel = -1,
studentNumber = -1;
bool validName = 0;
// Find if username exists, save student position
for (int i = 0; i < roster.size(); i++) {
if (roster.at(i).getUserName() == studentUserNameIn) {
validName = 1;
......@@ -167,6 +208,8 @@ void Teacher::adjustProgress(string studentUserNameIn, int level) {
}
}
// If the username exists, change the level and output success to console
// Otherwise, output an error
if (validName) {
lastLevel = roster.at(studentNumber).getLevel();
roster.at(studentNumber).setLevel(level);
......@@ -177,8 +220,10 @@ void Teacher::adjustProgress(string studentUserNameIn, int level) {
}
// Saves and ends program safely and gracefully
void Teacher::endProgram() {
saveProgress();
exit(0);
}
// Accessors
......
......@@ -13,14 +13,14 @@ class Teacher {
Teacher(string userNameIn); // Default constructor
// Teacher Functions
void displayMenu();
void displayMenu(); // Runs menu
void displayProgress(); // Opens menu, teacher get get all (gradebook style) or a student
void exportProgress(); // outputProgress() in UML
void saveProgress();
void importProgress();
void enrollStudent(Student studentIn);
void adjustProgress(string studentUserNameIn, int level);
void endProgram();
void saveProgress(); // Exports roster/progress to a file; this is run whenever log out is selected from menu
void importProgress(); // Imports roster/progress from a file
void enrollStudent(Student studentIn); // Enrolls a new student; includes error checking
void adjustProgress(string studentUserNameIn, int level); // Changes a students level; includes error checking for student username
void endProgram(); // saves and ends program gracefully
// Accessors
const string getUserName();
......@@ -37,8 +37,10 @@ class Teacher {
string exitCode = "Quit";
vector<Student> roster;
// Strings for file I/O
// If a file location needs to be changed, this is the place to do it!
string rosterFileName = "classRoster.txt"; // Used for use by program as import/export
string progressFileName = "classProgress.txt"; // Used for teacher
string progressFileName = "classProgress.txt"; // Used for teacher export
};
......
......@@ -9,12 +9,9 @@
using namespace std;
int main() {
string teacherUserName;
Teacher testTeacher;
testTeacher.importProgress();
testTeacher.importProgress(); // This should probably be called whenever the main file is run.
cout << "The test teachers name is " << testTeacher.getUserName() << ".\n";
......
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