Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sstream>
- #include <vector>
- #include <string>
- #include <fstream>
- #include <iostream>
- #include "Instructor.h"
- #include "Student.h"
- using namespace std;
- //Global variables
- string username;
- string password;
- Instructor instructor;
- Student student;
- vector<string> studentVector;
- vector<string> instructorVector;
- vector<Student> studentList;
- vector<Instructor> instructorList;
- //The functions in the document are being declared here to resolve scope issues
- void handleFiles(int argc, char ** argv);
- void loginProcess();
- void instructorScope();
- void studentScope();
- //This is the first method called from main
- //handleFiles checks that the files passed in as command line arguments
- // and then parses the files into vectors
- void handleFiles(int argc, char ** argv) {
- if (argc != 2) {
- cout << "Usage: main [instructors_file] [students_file]";
- exit(1);
- } //if
- try {
- ifstream in;
- string line;
- in.open(argv[0]);
- while (getline(in, line)) {
- stringstream lineStream(line);
- string token;
- while(lineStream >> token) {
- instructorVector.push_back(token);
- } //while
- } //while
- in.close();
- cin.sync();
- //This for loop is initializing all of the instructor objects
- Instructor temp;
- for (int i = 0, j = 0; i < instructorVector.size() / 4; i++) {
- temp.setUsername(instructorVector[j]);
- j++;
- temp.setPassword(instructorVector[j]);
- j++;
- string fullName = instructorVector[j] + " " + instructorVector[j + 1];
- temp.setInstructorName(fullName);
- j += 2;
- instructorList.push_back(temp);
- } //for
- } catch(...) {
- cout << "Error: cannot parse instructors information from file "
- << argv[0];
- exit(1);
- } //try/catch [parsing instructors file]
- try {
- ifstream in;
- string line;
- in.open(argv[1]);
- while (getline(in, line)) {
- stringstream lineStream(line);
- string token;
- while (lineStream >> token) {
- studentVector.push_back(token);
- } //while
- } //while
- in.close();
- cin.sync();
- //This for loop is initializing all of the student objects
- Student temp;
- for (int i = 0, j = 0; i < studentVector.size() / 8; i++) {
- temp.setUsername(studentVector[j]);
- j++;
- temp.setPassword(studentVector[j]);
- j++;
- temp.setStudentName(studentVector[j] + " " + studentVector[j+1]);
- j += 2;
- temp.setProjectGrade(stoi(studentVector[j]));
- j++;
- temp.setQuizGrade(stoi(studentVector[j]));
- j++;
- temp.setMidtermGrade(stoi(studentVector[j]));
- j++;
- temp.setFinalGrade(stoi(studentVector[j]));
- j++;
- studentList.push_back(temp);
- } //for
- } catch (...) {
- cout << "Error: cannot parse students information from file "
- << argv[1];
- exit(1);
- } //try/catch [parsing students file]
- } //handleFiles
- //This handles the entire experience from the Instructor's viewpoint
- //It
- void instructorScope() {
- bool instructorBool = false;
- string instructorOption;
- while (!instructorBool) {
- cout << "\n"
- << "Query options,"
- << " 1 - view grades of a student"
- << " 2 - view stats"
- << "Enter option number:";
- cin >> instructorOption;
- if (instructorOption == "1" || instructorOption == "2") {
- instructorBool = true;
- } else {
- cout << "\n"
- << "Invalid option. Please enter a valid option.";
- } //if / else [selecting what to view]
- } //while
- if (instructorOption == "1") {
- } else if (instructorOption == "2") {
- } //if / else if [displaying the content]
- } //instructorScope
- void studentScope() {
- bool studentBool = false;
- while (!studentBool) {
- string studentOption;
- cout << "\n"
- << "Do you want to view grades (y/n)?";
- cin >> studentOption;
- if (studentOption == "y" || studentOption == "Y") {
- cout << "\n"
- << "Student name: "
- << student.getStudentName()
- << "\n"
- << "Project "
- << student.getProjectGrade()
- << "%"
- << "\n"
- << "Quiz "
- << student.getQuizGrade()
- << "%"
- << "\n"
- << "Midterm "
- << student.getMidtermGrade()
- << "%"
- << "\n"
- << "Final "
- << student.getFinalGrade()
- << "%"
- << "\n"
- << "Overall "
- << student.getOverallGrade()
- << "%"
- << "\n";
- loginProcess();
- } else if (studentOption == "n" || studentOption == "N") {
- studentBool = true;
- loginProcess();
- } //if / else if
- } //while
- } //studentScope
- void loginProcess() {
- vector<string> throwAway;
- string throwAwayString;
- while (cin) {
- cin >> throwAwayString;
- throwAway.push_back(throwAwayString);
- } //while
- cout << throwAway.size();
- cin.sync();
- //cin.ignore(256);
- string loginChoice;
- bool whileCondition = false;
- while (!whileCondition) {
- cout << "User types,"
- << "\n"
- << " 1 - Instructor"
- << "\n"
- << " 2 - Student"
- << "\n"
- << "Select a login user type or enter 3 to exit:";
- cin.sync();
- getline(cin, loginChoice);
- //cin >> loginChoice;
- //break;
- cout << "\n"
- << "Login Choice: "
- << loginChoice
- << "end"
- << "\n";
- if (loginChoice == "1" || loginChoice == "2") {
- whileCondition = true;
- } else if (loginChoice == "3") {
- exit(0);
- } //if / else if
- } //while
- bool loginSuccessful = false;
- while (!loginSuccessful) {
- cout << "\n"
- << "Enter credentials to login,"
- << "\n"
- << " Enter username:";
- cin >> username;
- cout << "\n"
- << " Enter password: ";
- break;
- cin >> password;
- if (loginChoice == "1") {
- if (instructor.login(username, password)) {
- cout << "\n"
- << "You are now logged in as instructor "
- << instructor.getInstructorName()
- << ".";
- loginSuccessful = true;
- instructorScope();
- } else {
- cout << "\n"
- << "Login as instructor failed.";
- } // if / else if [instructor login check]
- } else if (loginChoice == "2") {
- if (student.login(username, password)) {
- cout << "\n"
- << "You are now logged in as student "
- << student.getStudentName()
- << ".";
- loginSuccessful = true;
- studentScope();
- } else {
- cout << "\n"
- << "Login as student failed.";
- } //if / else if [student login check]
- } //if / else if [loginChoice check]
- } //while
- } //loginProcess
- int main(int argc, char **argv) {
- //handleFiles(argc, argv);
- loginProcess(); //I made this into its own method so I can repeatedly call it
- return 0;
- } //main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement