Created
July 27, 2022 13:52
-
-
Save bllaude/6c547f63b1f80cb71e3f2f6822f651c1 to your computer and use it in GitHub Desktop.
Database Program with Vectors (STL)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <sstream> | |
| using namespace std; | |
| string temp; | |
| int num; | |
| bool run = true; | |
| stringstream ss; | |
| int main() | |
| { | |
| vector<string> names; | |
| cout<<"Please enter names:\n"; | |
| while(temp != "done") | |
| { | |
| getline(cin, temp); | |
| if(temp != "done") | |
| { | |
| names.push_back(temp); | |
| } | |
| } | |
| while(run) | |
| { | |
| cout << "\n>> "; | |
| ss.clear(); | |
| temp.clear(); | |
| getline(cin, temp); | |
| ss << temp; | |
| ss >> temp; | |
| if(temp == "add" || temp == "enter") | |
| { | |
| ss >> temp; | |
| names.push_back(temp); | |
| } | |
| if(temp == "exit") | |
| { | |
| run = false; | |
| return 0; | |
| } | |
| if(temp == "print") | |
| { | |
| for(int i = 0; i != names.size(); i++) | |
| { | |
| cout<<"\n" << names[i]; | |
| } | |
| } | |
| if(temp == "size") | |
| { | |
| cout<<"\nSize of database is " << names.size() << endl; | |
| } | |
| if(temp == "search") | |
| { | |
| ss >> temp; | |
| bool recFound = false; | |
| cout << "Searching for " << temp << ".\n"; | |
| for (int i = 0; i != names.size(); i++) | |
| { | |
| if(names[i] == temp) | |
| { | |
| cout << "Match found in position " << i + 1<< ".\n"; | |
| recFound = true; | |
| } | |
| } | |
| if(recFound == false) | |
| { | |
| cout << "No instances of "<<temp<<" was found in the database.\n"; | |
| } | |
| } | |
| } | |
| cin.ignore(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment