Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <sstream>
- #include <fstream>
- using namespace std;
- int main()
- {
- string sChoice, sTemp, sFName, sMName, sLName, sFullName, sID, sClass;
- ifstream iFile;
- ofstream oFile;
- int iTemp;
- const char READING = 'A', ADDING = 'B', DISPLAYING = 'C', SORTING = 'D', WRITING = 'E', SEARCHING = 'F', ENDING = 'G';
- vector <string> vName, vID, vClass;
- do {
- //Display menu
- cout << "\nStudent List Menu\n";
- cout << " A. Reading student list from a file \n";
- cout << " B. Adding student information into student list \n";
- cout << " C. Displaing the content of the student list \n";
- cout << " D. Sorting and displaying he content of student list \n";
- cout << " E. Writing thestudent list to a file \n";
- cout << " F. Searching for a students info from list \n";
- cout << " G. Ending program \n";
- cout << " Please select a choice: ";
- getline(cin, sChoice);
- switch (toupper(sChoice[0]))
- {
- case READING:
- cout << "\Please enter the password: ";
- getline(cin, sTemp);
- iFile.open(sTemp.c_str());
- //testfor error
- while (iFile.fail())
- {
- iFile.clear();
- iFile.ignore();
- cout << " \nOpening error! Please re enter: \n";
- getline(cin, sTemp);
- iFile.open(sTemp.c_str());
- }
- while (getline(iFile, sTemp))
- {
- istringstream isObject(sTemp);
- isObject >> sFName >> sMName >> sLName >> sID >> sClass;
- if (sMName == "|")
- {
- sMName = " ";
- sFullName = sFName + " " + sLName;
- }
- else
- {
- sFullName = sFName + " " + sLName;
- }
- cout << left << setw(30) << sFName << setw(10) << sMName << setw(10) << sLName << setw(10) << sID << setw(10) << sClass << endl;
- vName.push_back(sFullName);
- vID.push_back(sID);
- vClass.push_back(sClass);
- }
- iFile.close();
- cout << " \nReading is successful \n";
- break;
- case ADDING:
- break;
- case DISPLAYING:
- cout << "content of stident list \n";
- for (int i = 0; vName.size(); i++)
- cout << setw(30) << vName[i] << setw(10) << vID[i] << setw(10) << vClass[i] << endl;
- break;
- case SORTING:
- cout << "\n The student list after sorting: \n";
- sort(vName.begin(), vName.end());
- //sort vName.begin
- break;
- case WRITING:
- break;
- case SEARCHING:
- break;
- case ENDING:
- break;
- default:
- cout << " Invalid password";
- }
- } while (toupper(sChoice[0]) != '6');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement