Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- vector <string> vName, vID, vClass;
- string sName, sID, sClass;
- string sTemp;
- string sNameSearch;
- int iStudent;
- // Displays text stating the starting size of the student list
- cout << "\nThe student list starts with the size of: " << vName.size() << endl;
- // Displays text to the user requesting to input an amount of students to add to the list
- cout << "\nHow many students would you like to add: ";
- // Gathers the amount of students requesting to be added
- cin >> iStudent;
- //
- cin.ignore();
- //
- for (int i = 0; i < iStudent; i++)
- {
- // Displays the student number
- cout << "\nStudent " << i + 1 << ":";
- // Displays text requesting for the student's name
- cout << "\nPlease enter the student's name:\t";
- // Gathers the name submited
- getline(cin, sName);
- //
- vName.push_back(sName);
- // Displays text requsting the student's ID
- cout << "\nPlease enter the student's ID:\t\t";
- // Gathers the ID submited
- getline(cin, sID);
- //
- vID.push_back(sID);
- // Displays text requesting the student's class
- cout << "\nPlease enter the student's class:\t";
- // Gathers the class submited
- getline(cin, sClass);
- //
- vClass.push_back(sClass);
- }
- // Displays a line of text stating the size of the class, and the information for each student
- cout << "\nThe student list has a size of: " << vName.size() << "\n";
- cout << "\nThe student list is:\n\ ";
- cout << "\nName: \t\t ID: \t\t Enrolled classes";
- cout << "\n--------------------------------------------------------------------------------\n";
- for (int i = 0; i < vName.size(); i++)
- {
- cout << endl << vName[i] << "\t\t" << vID[i] << "\t\t" << vClass[i];
- }
- cout << " \n\nThe student list after sorting: \n";
- for (int i = 0; i < vName.size(); i++)
- {
- cout << endl << vName[i];
- }
- cout << "\n\nPlease enter the name to be searched: ";
- cin >> (vName.begin(), vName.end(), sTemp);
- if (binary_search(vName.begin(), vName.end(), sTemp))
- {
- cout << "The name was found!";
- }
- else
- {
- cout << "This name was not found.";
- }
- do
- {
- cout << "\n\nPlease enter the name to be searched: ";
- getline(cin, sTemp);
- if (binary_search(vName.begin(), vName.end(), sTemp))
- {
- cout << "The name was found!";
- }
- else
- {
- cout << "This name was not found.";
- }
- cout << "\nWould you like to do this again: Y for Yes, N for No?\n";
- getline(cin, sTemp);
- cout << endl;
- } while (sTemp[0] == 'Y' || sTemp[0] == 'y');
- if (sTemp[0] == 'N' || sTemp[0] == 'n')
- cout << "\nThanks for using this program!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement