Commit 9a99c93c authored by Eddy Marinez's avatar Eddy Marinez

Merge branch 'master' of gitlab.cs.wallawalla.edu:sextja/cptr142_group_project

parents c5979a6a 5a95ed60
// ***********************************************************************
// NOTE: I had to put this together to get the Teacher class working.
// Feel free to use this file or not, but please note that the
// Teacher.h/.cpp files depend on these exact functions and
// function names, so please use these names in the final class.
//
// Thanks! -Andrew
// ***********************************************************************
#include <string>
using namespace std;
#ifndef STUDENT_H
#define STUDENT_H
class Student {
public:
//Default constructor for only a username
Student(string userNameIn) {
userName = userNameIn;
}
// Default constructor for a username and level
Student(string userNameIn, int levelIn) {
userName = userNameIn;
level = levelIn;
}
// Accessors
int getLevel() {
return level;
}
string getUserName() {
return userName;
}
// Mutators
void setLevel(int levelIn) {
level = levelIn;
}
void setUserName(string userNameIn) {
userName = userNameIn;
}
private:
string userName;
int level = 1;
};
#endif //STUDENT_H
\ No newline at end of file
// *****************************************************************************
// Author: Andrew Binder
// Implemenation file for Teacher class
// Comments should explain everything
// *****************************************************************************
#include "Teacher.h"
#include <iostream>
#include <fstream>
ofstream fout;
ifstream fin;
// 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 Gradebook" << endl;
cout << "2. Export Class Gradebook" << endl;
cout << "3. Enroll Students" << endl;
cout << "4. Adjust Student Progress" << endl;
cout << "5. Change Username" << endl;
cout << "6. Change Exit Code" << endl;
cout << "7. Log Out" << endl;
cout << endl << "Enter Selection: ";
cin >> menu;
if (cin) {
switch(menu) {
case 1: // Display Class Gradebook
displayProgress();
break;
case 2: // Exports Class Gradebook
exportProgress();
cout << "Gradebook exported succesfully." << endl;
break;
case 3: // Enroll Student
{
cout << "Please enter a username (no spaces): ";
cin >> stringIn;
Student studentIn(stringIn);
enrollStudent(studentIn);
break;
}
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: // Change Teacher Username
cout << "Your username is currently " << userName << "." << endl;
cout << "Please input a new username: ";
cin >> stringIn;
setUserName(stringIn);
break;
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: // Log Out
saveProgress();
cout << "Goodbye." << endl;
teacherMenuActive = 0;
// exit(0);
break;
default:
cout << "Invalid choice.\n";
break;
}
} else {
cin.clear();
cin.ignore(100,'\n');
cout << "Invalid choice.\n";
}
}
// 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);
cout << left << "Student" << "|\t" << "Current Level\n";
cout << "-----------------------------\n";
for (int i = 0; i < roster.size(); i++) {
cout.width(10);
cout << left << roster.at(i).getUserName() << "|\t" << roster.at(i).getLevel() << endl;
}
}
// Export Class Gradebook
// Input: none
// Output: Exports a file with each student username and their level
void Teacher::exportProgress() {
fout.open(progressFileName);
fout << userName << "'s Class Progress Report" << endl << endl;
fout.width(10);
fout << left << "Student" << "|\t" << "Current Level\n";
fout << "-------------------------\n";
for (int i = 0; i < roster.size(); i++) {
fout.width(10);
fout << left << roster.at(i).getUserName() << "|\t" << roster.at(i).getLevel() << endl;
}
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);
fout << userName << " " << exitCode << endl;
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; //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;
} else {
cout << "Error: Student already exists!" << endl;
}
}
// 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;
studentNumber = i;
}
}
// 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);
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;
}
}
// Saves and ends program safely and gracefully
void Teacher::endProgram() {
saveProgress();
exit(0);
}
// Accessors
const string Teacher::getUserName() {
return userName;
}
const string Teacher::getExitCode() {
return exitCode;
}
const bool Teacher::getMenuActive() {
return teacherMenuActive;
}
// Mutators
void Teacher::setExitCode(string exitCodeIn) {
exitCode = exitCodeIn;
}
void Teacher::setUserName(string userNameIn) {
userName = userNameIn;
}
\ No newline at end of file
// *****************************************************************************
// Author: Andrew Binder
// Header file for Teacher class
// Comments should explain everything
// *****************************************************************************
#include "Student.h"
#include <vector>
#include <string>
using namespace std;
class Student {
public:
int getLevel() {
return level;
}
string getUserName() {
return userName;
}
private:
string userName;
int level = 1;
};
#ifndef TEACHER_H
#define TEACHER_H
class Teacher {
private:
string userName;
string exitCode;
//vector<Student> roster;
public:
Teacher(string userNameIn); // Default constructor
Teacher();
Teacher(string userNameIn); // Default constructor
// Teacher Functions
void displayMenu();
void displayProgress(); // Opens menu, teacher get get all (gradebook style) or a student
bool exportProgress(); // outputProgress() in UML
// bool enrollStudent(Student studentIn);
// bool adjustProgress(Student studentIn, int level);
void endProgram();
void displayMenu(); // Runs menu
void displayProgress(); // Opens menu, teacher get get all (gradebook style) or a student
void exportProgress(); // outputProgress() in UML
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();
const string getExitCode();
const bool getMenuActive();
// Mutators
bool setExitCode(string exitCodeIn);
bool setUserName(string userNameIn);
};
\ No newline at end of file
void setExitCode(string exitCodeIn);
void setUserName(string userNameIn);
private:
bool teacherMenuActive = 1;
string userName;
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 export
};
#endif //TEACHER_H
\ No newline at end of file
// *****************************************************************************
// AUTHOR: Andrew Binder
// This file is a test drive for the Teacher.h/cpp classes. It, along with the
// .h and .cpp file explain everything you should need to know about my files.
//
// Test Drive compilation instructions:
// g++ -std=c++11 Teacher_Driver.cpp Teacher.cpp -o Teacher_Driver.cpp.o && ./Teacher_Driver.cpp.o
// *****************************************************************************
#include <string>
#include <iostream>
#include "Teacher.h"
using namespace std;
int main() {
Teacher testTeacher;
testTeacher.importProgress(); // This should probably be called whenever the main file is run.
cout << "The test teachers name is " << testTeacher.getUserName() << ".\n";
do {
testTeacher.displayMenu();
if (!testTeacher.getMenuActive()) {
break;
}
} while (true);
return 0;
}
\ No newline at end of file
Andrew's Class Progress Report
Student | Current Level
-------------------------
sextsa | 1
tituja | 3
sacalu | 1
allsna | 3
sextja | 1
mamatt | 2
culvxa | 3
duerwe | 1
inghro | 2
umalno | 1
grifno | 1
levina | 4
Andrew Quit
sextsa 1
tituja 3
sacalu 1
allsna 3
sextja 1
mamatt 2
culvxa 3
duerwe 1
inghro 2
umalno 1
grifno 1
levina 4
Andrew 500
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