Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iomanip>
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <cstdlib>
- #include <ctime>
- #include <cctype>
- #include <fstream>
- using namespace std;
- int main()
- {
- string strOpt, strFileName, strInfo = "";
- string strFirstName, strMiddleName, strLastName, strID, strClass, strClasses, strSearch;
- vector <string> vecName, vecFirstName, vecMiddleName, vecLastName, vecClass, vecClasses, vecData, vecID;
- ifstream FileIn;
- ofstream FileOut;
- int intStudent, intCounter, intClass;
- 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, strOpt);
- switch (toupper(strOpt[0]))
- {
- //allows you to add a student list and see how many poeple are on it
- case READING:
- //This opens the file.
- cout << "\nPlease enter the file's name you would like to open: ";
- getline(cin, strFileName);
- FileIn.open(strFileName.c_str());
- // This gives you an error if the file name typed is incorrect
- if (!FileIn)
- {
- FileIn.clear();
- cout << "Could not find file name! Please re-enter the file name: ";
- getline(cin, strFileName);
- FileIn.open(strFileName.c_str());
- }
- // This tells you if you've typed in the correct password.
- if (FileIn)
- {
- cout << "\nThat's the correct file name!";
- }
- cout << "\nOpened Successfully! \n";
- while (getline(FileIn, strFileName))
- if (strOpt == "|")
- {
- strOpt = "\t";
- strInfo += "\t\t";
- }
- cout << strFileName << endl;
- //This tells you how many students are within the list.
- cout << "\nReading is successful! \n";
- cout << "\nThe size of the list is: " << vecData.size() << endl << endl;
- break;
- // This case allows you to add more students to the list
- case ADDING:
- //asks how many students you want to add
- cout << "How many Students would you like to add:";
- cin >> intStudent;
- 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 >> intStudent;
- cin.ignore();
- }
- //allows you to add students to the list
- for (int i = 0; i < intStudent; i++)
- {
- cout << "\nStudent " << i + 1 << ":";
- cout << "\nPlease enter the Student's First Name: ";
- getline(cin, strFirstName);
- vecFirstName.push_back(strFirstName);
- cout << "\nPlease enter the Student's Middle Name: ";
- getline(cin, strMiddleName);
- vecMiddleName.push_back(strMiddleName);
- cout << "\nPlease enter the Student's Last Name: ";
- getline(cin, strLastName);
- vecLastName.push_back(strLastName);
- cout << "\nPlease enter the Student's ID: ";
- getline(cin, strID);
- vecID.push_back(strID);
- cout << "\nHow many classes for this student? ";
- getline(cin, strClass);
- vecClass.push_back(strClass);
- cout << "\nPlease enter the Studnet's class: ";
- getline(cin, strClasses);
- vecClasses.push_back(strClasses);
- vecName.push_back(strFirstName + "\t" + strMiddleName + "\t" + strLastName + "\t");
- }
- break;
- //this displays student list
- case DISPLAYING:
- if (vecData.size() == 0)
- {
- cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
- }
- for (int i = 0; i < vecData.size(); i++)
- cout << vecData[i] << endl;
- break;
- //This case sorts the students by their names.
- case SORTING:
- //If a file was not loaded, this causes an error message to occur.
- if (vecData.size() == 0)
- {
- cout << "\nThe list is empty! Please load a file.\n\n";
- }
- //This will sort the students by their names.
- else
- {
- sort(vecData.begin(), vecData.end());
- sort(vecName.begin(), vecName.end());
- cout << "This list was successfuly sorted.\n\n";
- }
- break;
- //This case allows for you to create a new save file
- case SAVING:
- cout << "\nPlease enter a file name: ";
- getline(cin, strOpt);
- FileOut.open(strOpt.c_str());
- for (int i = 0; i < vecData.size(); i++)
- FileOut << vecData[i] << endl;
- FileOut.close();
- break;
- //This case lets you search students on the list by their name
- case SEARCHING:
- char response;
- // This provides an error message if students could not be found.
- if (vecData.size() == 0)
- {
- cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
- }
- // This allows for you to search the names of students.
- else
- {
- do
- {
- cout << "\nPlease enter the name to be searched: ";
- getline(cin, strSearch);
- if (binary_search(vecName.begin(), vecName.end(), strSearch))
- {
- cout << "\nThe name: " + strSearch + " was found in the Student List.\n";
- }
- else
- {
- cout << "\nThe name: " + strSearch + " could not be 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(strOpt[0]) != EXITING);
- cout << "\nApplication is terminating. \n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment