Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- string sResponse, sPass, sInfo = "";
- ifstream fStream;
- ofstream oStream;
- int iStudent, iCounter, iClass;
- vector <string> vFName, vMName, vLName, vID, vData, vClass,vClasses, vName;
- string sFName, sMName, sLName, sID, sClass,sClasses, sSearch;
- const char READING = 'A', ADDING = 'B', DISPLAYING = 'C', SORTING = 'D', SAVING = 'E', SEARCHING = 'F', EXITING = 'G';
- do
- {
- //this is a reference table that allows users to view all the capabilities of the app
- cout << "\tStudent Enrollment Application\n\n";
- cout << "A. Reading an external student list\n";
- cout << "B. Adding student's informations into student list\n";
- cout << "C. Displaying student list\n";
- cout << "D. Sorting student list\n";
- cout << "E. Saving student list to a file\n";
- cout << "F. Searching from student list\n";
- cout << "G. Exit the application\n\n";
- cout << "What would you like to perform?";
- getline(cin, sResponse);
- switch (toupper(sResponse[0]))
- {
- //allows you to add a student list and see how many poeple are on it
- case READING:
- //opens file
- cout << "\nPlease enter the password:";
- getline(cin, sPass);
- fStream.open(sPass.c_str());
- if (!fStream)
- {
- fStream.clear();
- cout << "Wrong password! Please re-enter the password: ";
- getline(cin, sPass);
- fStream.open(sPass.c_str());
- }
- cout << "\nOpened Successfully! \n";
- while (getline(fStream, sPass))
- if (sResponse == "|")
- {
- sResponse = "\t";
- sInfo += "\t\t";
- }
- else
- {
- if (iCounter % 5 == 0)
- cout << endl;
- sInfo += sResponse;
- iCounter++;
- vData.push_back(sPass);
- }
- cout << sPass << endl;
- //tells you how many students are on the list
- cout << "\nReading is successful! \n";
- cout << "\nThe size of the list is: " << vData.size() << endl << endl;
- break;
- case ADDING:
- //asks how many students you want to add
- cout << "How many Students would you like to add:";
- cin >> iStudent;
- cin.ignore();
- //if you input something other than a number this will prevent the app from continuing
- while (cin.fail())
- {
- cout << "Invalid Choice. Select again: ";
- cin.clear();
- cin.ignore(std::numeric_limits<int>::max(), '\n');
- cin >> iStudent;
- cin.ignore();
- }
- //allows you to add students to the list
- for (int i = 0; i < iStudent; i++)
- {
- cout << "\nStudent " << i + 1 << ":";
- cout << "\nPlease enter the Student's First Name: ";
- getline(cin, sFName);
- vFName.push_back(sFName);
- cout << "\nPlease enter the Student's Middle Name: ";
- getline(cin, sMName);
- vMName.push_back(sMName);
- cout << "\nPlease enter the Student's Last Name: ";
- getline(cin, sLName);
- vLName.push_back(sLName);
- cout << "\nPlease enter the Student's ID: ";
- getline(cin, sID);
- vID.push_back(sID);
- cout << "\nHow many classes for this student? ";
- getline(cin, sClass);
- vClass.push_back(sClass);
- cout << "\nPlease enter the Studnet's class: ";
- getline(cin, sClasses);
- vClasses.push_back(sClasses);
- vName.push_back(sFName + "\t" + sMName + "\t" + sLName + "\t");
- }
- break;
- //this displays student list
- case DISPLAYING:
- if (vData.size() == 0)
- {
- cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
- }
- for (int i = 0; i < vData.size(); i++)
- cout << vData[i] << endl;
- break;
- //sorts student list
- case SORTING:
- //if no information is avalible this will be displayed
- if (vData.size() == 0)
- {
- cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
- }
- //otherwise the list wil be sorted
- else
- {
- sort(vData.begin(), vData.end());
- sort(vName.begin(), vName.end());
- cout << "Sorting successfully the list.\n\n";
- }
- break;
- //creates a new saved file
- case SAVING:
- cout << "\nPlease enter a file name: ";
- getline(cin, sResponse);
- oStream.open(sResponse.c_str());
- for (int i = 0; i < vData.size(); i++)
- oStream << vData[i] << endl;
- oStream.close();
- break;
- //allows you to search for a student by name
- case SEARCHING:
- char response;
- // if no students are present on the list this wil be displayed
- if (vData.size() == 0)
- {
- cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
- }
- // if students are present you will then be able to search by name
- else
- {
- do
- {
- cout << "\nPlease enter the name to be searched: ";
- getline(cin, sSearch);
- if (binary_search(vName.begin(), vName.end(), sSearch))
- {
- cout << "\nThe name: " + sSearch + " was found in the Student List.\n";
- }
- else
- {
- cout << "\nThe name: " + sSearch + " was not found in the Student List.\n";
- }
- cout << "\nWould you like to search more?\nPlease enter Y for Yes, and N for No: ";
- cin >> response;
- cin.ignore();
- } while (response == 'Y' || response == 'y');
- }
- break;
- //exiting lab section that allows you to terminate the app or continue
- case EXITING:
- cout << "\nExiting application!";
- cout << "\nAre you sure to exit this application? Yes or No: ";
- cin >> response;
- cin.ignore();
- while (response == 'Y' || response == 'y');
- break;
- default:
- cout << "\nInvalid Input! \n\n";
- break;
- }
- } while (toupper(sResponse[0]) != EXITING);
- cout << "\nApplication is terminating. \n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment