Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <cstring>
- #include <string>
- #include <iomanip>
- #include <cstdlib>
- #include <vector>
- // Don't comment out code. It's distracting.
- //#include "student.h"
- #include "studentList.h"
- // Don't use the standard namespace. It's bad style.
- using namespace std;
- const int fileNameSize=20;
- ofstream outFile;
- //char inputFileName [fileNameSize+1];
- //char outputFilename [fileNameSize+1];
- studentList stList;
- string id, name;
- // There is a tab of excess whitespace here
- //
- // This and others should be a static function or in an anonymous
- // namespace Inconsistent and bad naming style. The standard C++
- // naming convention is foo_bar_gar.
- void showmenu()
- {
- cout << "Please type in one of the following opotions: \n";
- cout << "L or l to load the student list \n";
- cout << "D or d to display the student data \n";
- cout << "P or p to process grades\n";
- cout << "C or c to change a student \n";
- cout << "A or a to add a student. \n";
- cout << "S or s to search for a particular student's information \n";
- cout << "R or r to print the total grades and letter grade \n";
- cout << "M or m to display this menu \n";
- cout << "E or e to save and exit \n";
- }
- void loadStudents()
- {
- // I'd use a char for this.
- int dummy = 1;
- //choice='1';
- //char temp=choice;
- // The bounds here should be constants. C++ is an ugly sack of
- // shit so the best way to do this is:
- // contexpr size_t bound = 10;
- // or
- // enum { BOUND = 10 };
- int hpScores[10];
- int tScores[4];
- ifstream inFile;
- //cout << "infile flag";
- student st;
- // Use a string class instead of a bounded buffer.
- char filename[30];
- cout << "What is the file we are reading from? \n";
- cin >> filename;
- cout << "Loading students... \n";
- cout << filename << endl;
- // Windows is an ugly sack of shit and so this doesn't work
- // for Unicode filepaths.
- inFile.open(filename);
- cout << "open check" << endl;
- if (!inFile)
- {
- cout << "Error, could not load/find file.";
- // You don't need this. The destructor handles
- // this. The only point of explicitly handling this
- // would be checking for errors but there's no point
- // because this is already an error situation.
- inFile.close();
- inFile.clear();
- return;// choice;
- }
- cout << name << endl;
- st.setName(name);
- while (!inFile.eof())
- {
- cout << "open flag";
- cout << " " << name;
- inFile >> id; st.setID(id);
- cout << " " << id;
- cin >> dummy;
- for(int i=0;i<10;i++)
- {
- inFile >> hpScores[i];
- cout << " " <<hpScores[i] << endl;
- }
- st.setHPScores(hpScores);
- for(int i=0;i<4;i++)
- {
- inFile >> tScores[i];
- cout << " " <<tScores[i] << endl;
- }
- st.setTestScores(tScores);
- stList.addStudent(st);
- inFile >> name;
- st.setName(name);
- }
- //cout << "flag6";
- //return choice;
- string wastedata;
- getline(cin, wastedata);
- inFile.clear();
- inFile.close();
- }
- void displayStudentProfile()
- {
- cout << "Displaying data...\n";
- }
- void processGrades()
- {
- cout << "Processing grades... \n";
- }
- void changeGrades()
- {
- cout << "Changing student grade(s)...\n";
- }
- void addStudent()
- {
- cout << "Adding student... \n";
- }
- void searchStudent()
- {
- cout << "Searhing student...\n";
- }
- void saveInfo()
- {
- cout << "Saving data...";
- }
- void printGrades()
- {
- cout << "Printing total grades and letter grade...";
- }
- int main()
- {
- int ilchk=0;
- char choice='m';
- string wastedata;
- showmenu();
- cout << "Please indicate your choice of operation (m for menu): ";
- cin >> choice;
- while((choice!='e')&&(choice!='E') and ilchk<5)
- {
- switch(choice)
- {
- case 'l':
- case 'L': loadStudents(); cin.ignore(400, '\n'); cin.clear(); break;
- case 'd':
- case 'D': displayStudentProfile(); cin.ignore(400, '\n'); cin.clear(); break;
- case 'p':
- case 'P': processGrades(); cin.ignore(400, '\n'); cin.clear(); break;
- case 'c':
- case 'C': changeGrades(); cin.ignore(400, '\n'); cin.clear(); break;
- case 'a':
- case 'A': addStudent(); cin.ignore(400, '\n'); cin.clear(); break;
- case 's':
- case 'S': searchStudent(); cin.ignore(400, '\n'); cin.clear(); break;
- case 'r':
- case 'R': printGrades(); cin.ignore(400, '\n'); cin.clear(); break;
- case 'm':
- case 'M': showmenu(); cin.ignore(400, '\n'); cin.clear(); break;
- case 'e':
- case 'E': cin.ignore(400, '\n'); cin.clear(); break;
- default : cout << "Invalid command." << endl;
- }
- cout << "Please indicate your choice of operation (m for menu): ";
- cin >> choice;
- ilchk++;
- }
- saveInfo();
- cout << "Thank you, have a good one!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement