Commit adbf6362 authored by Andrew Binder's avatar Andrew Binder

Added support for saving the roster

parent 41a2240d
#include "Teacher.h"
#include <iostream>
#include <fstream>
ofstream fout;
ifstream fin;
Teacher::Teacher() {}
Teacher::Teacher(string userNameIn) {
userName = userNameIn;
}
void Teacher::displayMenu() {
cout << "Teacher Menu" << endl;
cout << "____________" << endl;
cout << "------Teacher Menu------" << 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() {
......@@ -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) {
bool validName = 1;
for (int i = 0; i < roster.size(); i++) {
......@@ -36,9 +77,6 @@ void Teacher::enrollStudent(Student studentIn) {
} else {
cout << "Error: Student already exists!" << endl;
}
}
void Teacher::adjustProgress(string studentUserNameIn, int level) {
......
......@@ -9,6 +9,11 @@ class Student {
userName = userNameIn;
}
Student(string userNameIn, int levelIn) {
userName = userNameIn;
level = levelIn;
}
int getLevel() {
return level;
}
......@@ -31,12 +36,15 @@ class Student {
class Teacher {
public:
Teacher();
Teacher(string userNameIn); // Default constructor
// Teacher Functions
void displayMenu();
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();
......@@ -51,7 +59,7 @@ class Teacher {
private:
string userName;
string exitCode;
string exitCode = "Quit";
vector<Student> roster;
};
\ No newline at end of file
......@@ -13,31 +13,40 @@ int main() {
string teacherUserName;
cout << "First we will test the constructor: \nInput a username: ";
cin >> teacherUserName;
// cin >> teacherUserName;
Teacher testTeacher;
testTeacher.importProgress();
Teacher testTeacher(teacherUserName);
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;
cin >> studentNameIn;
Student studentIn(studentNameIn);
testTeacher.enrollStudent(studentIn);
}
//Student studentIn("Andrew");
//testTeacher.enrollStudent(studentIn);
// cout << "Now, we will enroll some students.\nEnter three students names: ";
cout << "\nNow we will test the displayProgress() function.\n";
testTeacher.displayProgress();
// for (int i = 0; i < 3; i++) {
// string studentNameIn;
// cin >> studentNameIn;
// Student studentIn(studentNameIn);
// testTeacher.enrollStudent(studentIn);
// }
// //Student studentIn("Andrew");
// //testTeacher.enrollStudent(studentIn);
// cout << "\nNow we will test the displayProgress() function.\n";
// testTeacher.displayProgress();
testTeacher.adjustProgress("Andrew",5);
// testTeacher.adjustProgress("Andrew",5);
testTeacher.displayProgress();
// testTeacher.saveProgress();
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