Commit 899b96b2 authored by Eddy Marinez's avatar Eddy Marinez

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

parents f35c922b e7a9191f
/* ============================================================================
Main Function
g++ -std=c++11 MAIN.cpp Questions.cpp Teacher.cpp -o MAIN.cpp.o && ./MAIN.cpp.o
Student.cpp (add in when it exists)
============================================================================
*/
#include "Questions.h"
#include "Student.h"
#include "Teacher.h"
#include <iostream> // For cout and cin
using namespace std;
int main() {
Teacher teacher;
teacher.importProgress();
string currentUser;
bool keepRunning = true;
do {
cout << "Please enter your user name: ";
cin >> currentUser;
if (cin) {
if(currentUser == teacher.getExitCode()) {
keepRunning = false;
}
else if (currentUser == teacher.getUserName()) {
do {
teacher.displayMenu();
if (!teacher.getMenuActive()) {
break;
}
} while (true);
}
else if (teacher.checkRoster(currentUser) >= 0) {
int currentUserIndex = teacher.checkRoster(currentUser);
Student currentStudent;
currentStudent = teacher.getStudent(currentUserIndex);
// Current user (Student object) : currentStudent
teacher.setStudent(currentStudent);
}
else {
cin.clear();
cin.ignore(100,'\n');
cerr << "Invalid user name.\n";
}
} else {
cin.clear();
cin.ignore(100,'\n');
cerr << "Invalid user name.\n";
}
} while(keepRunning);
return 0;
}
\ No newline at end of file
......@@ -16,6 +16,10 @@ using namespace std;
class Student {
public:
// Default constructor
Student() {
userName = "NoName";
}
//Default constructor for only a username
Student();
Student(string userNameIn) {
......@@ -28,6 +32,12 @@ class Student {
level = levelIn;
}
// Copy constructor
Student(const Student& studentIn) {
userName = studentIn.userName;
level = studentIn.level;
}
// Accessors
int getLevel() {
return level;
......
......@@ -57,8 +57,7 @@ void Teacher::displayMenu() {
{
cout << "Please enter a username (no spaces): ";
cin >> stringIn;
Student studentIn(stringIn);
enrollStudent(studentIn);
enrollStudent(stringIn);
break;
}
case 4: // Adjust Student Progress
......@@ -175,19 +174,11 @@ void Teacher::importProgress() {
// 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;
}
}
void Teacher::enrollStudent(string studentIn) {
int validName = checkRoster(studentIn); // Check if username exists in roster
// If the name is valid, enroll the student, otherwise output an error
if (validName) {
if (validName == -1) {
roster.push_back(studentIn);
cout << "Student succesfully enrolled." << endl;
} else {
......@@ -199,23 +190,12 @@ void Teacher::enrollStudent(Student studentIn) {
// 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;
}
}
int studentNumber = checkRoster(studentUserNameIn); // Check if student exists/Get student position in vector
// If the username exists, change the level and output success to console
// Otherwise, output an error
if (validName) {
lastLevel = roster.at(studentNumber).getLevel();
if (studentNumber >= 0) {
int 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 {
......@@ -230,6 +210,16 @@ void Teacher::endProgram() {
exit(0);
}
// Checks the roster for a given student, and returns true if found.
int Teacher::checkRoster(string student) {
for (int i = 0; i < roster.size(); i++) {
if (roster.at(i).getUserName() == student) {
return i;
}
}
return -1;
}
// Accessors
const string Teacher::getUserName() {
return userName;
......@@ -243,6 +233,10 @@ const bool Teacher::getMenuActive() {
return teacherMenuActive;
}
const Student Teacher::getStudent(int vectorPosition) {
return roster.at(vectorPosition);
}
// Mutators
void Teacher::setExitCode(string exitCodeIn) {
exitCode = exitCodeIn;
......@@ -250,4 +244,8 @@ void Teacher::setExitCode(string exitCodeIn) {
void Teacher::setUserName(string userNameIn) {
userName = userNameIn;
}
void Teacher::setStudent(Student studentIn) {
roster.at(checkRoster(studentIn.getUserName())) = studentIn;
}
\ No newline at end of file
......@@ -24,18 +24,23 @@ class Teacher {
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 enrollStudent(string studentIn); // Enrolls a new student; includes error checking
void adjustProgress(string studentUserNameIn, int level); // Changes a students level; includes error checking for student username
int checkRoster(string student); // Returns a student's position on vector if username student exists in vector; Returns -1 if student does not exist
void endProgram(); // saves and ends program gracefully
// Accessors
const string getUserName();
const string getExitCode();
const bool getMenuActive();
const Student getStudent(int vectorPosition);
// Mutators
void setExitCode(string exitCodeIn);
void setUserName(string userNameIn);
void setStudent(Student studentIn); // I think it's safe to say that studentIn will be a student in the vector; so the function will find where the student goes in the vector by itself
// vector<Student> roster;
private:
bool teacherMenuActive = 1;
......
......@@ -56,3 +56,14 @@ _Feedback_
Grade: __M__ 3/1/2018
_Feedback_
* Included complete UML diagrams __incomplete__
* URL is incorrect.
* Included a procedural flow diagram __incomplete__
* URL is incorrect.
* Listed anticipated challenges __complete__
* Detailed project management plan __complete__
* Files (.md) should be in the root of the project. Images can be in a subdirectory.
Grade: __M__ 3/7/2018
......@@ -7,10 +7,10 @@
* ___Complete UML diagrams___
![Group Project UML Diagram](https://gitlab.cs.wallawalla.edu/sextja/cptr142_group_project/raw/master/GroupProjectUML.png)
![Group Project UML Diagram](https://gitlab.cs.wallawalla.edu/sextja/cptr142_group_project/raw/master/REFERENCES/GroupProjectUML.png)
* ___Procedural Flow Diagram___
* ![Procedure flow](https://gitlab.cs.wallawalla.edu/sextja/cptr142_group_project/raw/master/Procedural%20Flow%20Diagram.png)
* ![Procedure flow](https://gitlab.cs.wallawalla.edu/sextja/cptr142_group_project/raw/master/REFERENCES/Procedural%20Flow%20Diagram.png)
* Loads data from text file from previous runs (users, progress levels, etc.)
* Ask the user for a username (after this point the interface will be different for teacher or student)
......
......@@ -14,3 +14,4 @@ inghro | 2
umalno | 1
grifno | 1
levina | 4
Andrew | 500
......@@ -12,4 +12,7 @@ umalno 1
grifno 1
levina 4
Andrew 500
Sam 2
Jared 1
bindan 43
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