Commit adbf6362 authored by Andrew Binder's avatar Andrew Binder

Added support for saving the roster

parent 41a2240d
#include "Teacher.h" #include "Teacher.h"
#include <iostream> #include <iostream>
#include <fstream>
ofstream fout;
ifstream fin;
Teacher::Teacher() {}
Teacher::Teacher(string userNameIn) { Teacher::Teacher(string userNameIn) {
userName = userNameIn; userName = userNameIn;
} }
void Teacher::displayMenu() { void Teacher::displayMenu() {
cout << "Teacher Menu" << endl; cout << "------Teacher Menu------" << endl;
cout << "____________" << endl; cout << "1. Display Class Progress" << endl;
cout << "2. Export Class Progress" << endl;
cout << "3. Enroll Students" << endl;
cout << "4. Adjust Student Progress" << endl;
cout << "5. Change Username" << endl;
cout << "6. Change Exit Code" << endl;
} }
void Teacher::displayProgress() { void Teacher::displayProgress() {
...@@ -22,6 +33,36 @@ void Teacher::exportProgress() { ...@@ -22,6 +33,36 @@ void Teacher::exportProgress() {
} }
void Teacher::saveProgress() {
fout.open("classRoster.txt");
fout << userName << " " << exitCode << endl;
for (int i = 0; i < roster.size(); i++) {
fout << roster.at(i).getUserName() << " " << roster.at(i).getLevel() << endl;
}
fout << "END_OF_FILE";
fout.close();
}
void Teacher::importProgress() {
string parseName;
int parseLevel;
fin.open("classRoster.txt");
fin >> userName >> exitCode;
while (true) {
fin >> parseName;
if (parseName == "END_OF_FILE") {
break;
} else {
fin >> parseLevel;
}
Student studentIn(parseName, parseLevel);
roster.push_back(studentIn);
}
fin.close();
}
void Teacher::enrollStudent(Student studentIn) { void Teacher::enrollStudent(Student studentIn) {
bool validName = 1; bool validName = 1;
for (int i = 0; i < roster.size(); i++) { for (int i = 0; i < roster.size(); i++) {
...@@ -36,9 +77,6 @@ void Teacher::enrollStudent(Student studentIn) { ...@@ -36,9 +77,6 @@ void Teacher::enrollStudent(Student studentIn) {
} else { } else {
cout << "Error: Student already exists!" << endl; cout << "Error: Student already exists!" << endl;
} }
} }
void Teacher::adjustProgress(string studentUserNameIn, int level) { void Teacher::adjustProgress(string studentUserNameIn, int level) {
......
...@@ -8,6 +8,11 @@ class Student { ...@@ -8,6 +8,11 @@ class Student {
Student(string userNameIn) { Student(string userNameIn) {
userName = userNameIn; userName = userNameIn;
} }
Student(string userNameIn, int levelIn) {
userName = userNameIn;
level = levelIn;
}
int getLevel() { int getLevel() {
return level; return level;
...@@ -31,12 +36,15 @@ class Student { ...@@ -31,12 +36,15 @@ class Student {
class Teacher { class Teacher {
public: public:
Teacher();
Teacher(string userNameIn); // Default constructor Teacher(string userNameIn); // Default constructor
// Teacher Functions // Teacher Functions
void displayMenu(); void displayMenu();
void displayProgress(); // Opens menu, teacher get get all (gradebook style) or a student void displayProgress(); // Opens menu, teacher get get all (gradebook style) or a student
void exportProgress(); // outputProgress() in UML void exportProgress(); // outputProgress() in UML
void saveProgress();
void importProgress();
void enrollStudent(Student studentIn); void enrollStudent(Student studentIn);
void adjustProgress(string studentUserNameIn, int level); void adjustProgress(string studentUserNameIn, int level);
void endProgram(); void endProgram();
...@@ -51,7 +59,7 @@ class Teacher { ...@@ -51,7 +59,7 @@ class Teacher {
private: private:
string userName; string userName;
string exitCode; string exitCode = "Quit";
vector<Student> roster; vector<Student> roster;
}; };
\ No newline at end of file
...@@ -13,31 +13,40 @@ int main() { ...@@ -13,31 +13,40 @@ int main() {
string teacherUserName; string teacherUserName;
cout << "First we will test the constructor: \nInput a username: "; cout << "First we will test the constructor: \nInput a username: ";
cin >> teacherUserName; // cin >> teacherUserName;
Teacher testTeacher(teacherUserName); Teacher testTeacher;
testTeacher.importProgress();
cout << "The test teachers name is " << testTeacher.getUserName() << ".\n\n"; cout << "The test teachers name is " << testTeacher.getUserName() << ".\n\n";
cout << "Now, we will enroll some students.\nEnter three students names: "; cout << "Display Menu:\n";
//testTeacher.displayMenu();
for (int i = 0; i < 3; i++) {
string studentNameIn; // cout << "Now, we will enroll some students.\nEnter three students names: ";
// for (int i = 0; i < 3; i++) {
// string studentNameIn;
cin >> studentNameIn; // cin >> studentNameIn;
Student studentIn(studentNameIn); // Student studentIn(studentNameIn);
testTeacher.enrollStudent(studentIn); // testTeacher.enrollStudent(studentIn);
} // }
//Student studentIn("Andrew"); // //Student studentIn("Andrew");
//testTeacher.enrollStudent(studentIn); // //testTeacher.enrollStudent(studentIn);
cout << "\nNow we will test the displayProgress() function.\n"; // cout << "\nNow we will test the displayProgress() function.\n";
testTeacher.displayProgress(); // testTeacher.displayProgress();
testTeacher.adjustProgress("Andrew",5); // testTeacher.adjustProgress("Andrew",5);
testTeacher.displayProgress(); testTeacher.displayProgress();
// testTeacher.saveProgress();
return 0; return 0;
} }
\ No newline at end of file
Andrew Quit
Andrew 1
Asher 3
Joe 1
John 3
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