Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ConsoleUI::run() // Display "Listi", where you can get information about actions you can make
- {
- //vector<CompScientist>listi;
- _service.getDatabase();
- //vector<CompScientist>listi;
- //_service.saveToList(); //reading from file
- cout << "Please enter one of the following commands:" << endl;
- cout << "Add - This will add a new computer scientist." << endl;
- cout << "List - This will display all computer scientists in the system." << endl;
- cout << "Sort - This will sort the list according to your choice" << endl;
- cout << "Search - This will search and display a computer scientist or computer." << endl;
- cout << "Help - This will display all commands and keywords you need for full function." << endl;
- cout << "Quit - This will end the program." << endl;
- string user_input, search_name, search_option;
- do
- {
- cin >> user_input;
- if(user_input == "add" || user_input == "Add" || user_input == "ADD")
- {
- string pressed;
- cout << "To what table do you want to add?" << endl;
- cout << "Input '1' to add Scientist" << endl;
- cout << "Input '2' to add Computer" << endl;
- cout << "Input '3' to add connections" << endl;
- //todo dowhile
- cin >> pressed;
- if(pressed == "1")
- { string name;
- string sex;
- int birthyear;
- int deathyear;
- cout << "Input name: ";
- cin.ignore();
- getline(cin,name);
- cout << "Input sex: ";
- cin.ignore();
- getline(cin,sex);
- cout << "Input birthyear: ";
- cin >>birthyear;
- cout << "Input deathyear: ";
- cin >>deathyear;
- _service.addScientistToDatabase(name, sex, birthyear, deathyear);
- }
- else if(pressed == "2")
- {
- cout << "Input name: ";
- string name;
- cin.ignore();
- getline(cin,name);
- int year;
- cout << "Input year: ";
- cin >> year;
- cout << "Input type: ";
- string type;
- cin.ignore();
- getline(cin, type);
- cout << "Was it built? (Yes/No): ";
- string built;
- cin >> built;
- _service.addComputerToDatabase(name, year, type, built);
- }
- else if(pressed == "3")
- {
- int Scientist_ID;
- int Computer_ID;
- cout << "Input Scientist ID: " << endl;
- cin >> Scientist_ID;
- cout << "Input Computer ID: " << endl;
- cin >> Computer_ID;
- _service.addConnectionToDatabase(Scientist_ID, Computer_ID);
- }
- }
- else if(user_input == "list"|| user_input == "List" || user_input == "LIST")
- {
- string tableDisplay;
- do
- {
- cout << "What table to display?" << endl;
- cout << "Input '1' for Scientist table" << endl;
- cout << "Input '2' for Computer table" << endl;
- cout << "Input '3' for Connections table" << endl;
- cin >> tableDisplay;
- if(!(tableDisplay == "1") && !(tableDisplay == "2") && !(tableDisplay == "3"))
- {
- cout << "Invalid sort input. Please try again." << endl;
- }
- }while(!(tableDisplay == "1") && !(tableDisplay == "2") && !(tableDisplay == "3"));
- if(tableDisplay == "1")
- {
- vector <CompScientist> temp = _service.getScientistsListi();
- displayListOfScientists(temp);
- _service.getScientistsListi().clear();
- }
- else if(tableDisplay == "2")
- {
- vector <Computer> temp = _service.getComputersListi();
- displayListOfComputers(temp);
- _service.getComputersListi().clear();
- }
- }
- else if(user_input == "sort"|| user_input == "Sort"|| user_input == "SORT")
- {
- string sort_input;
- do
- {
- cout << "Input 1 to sort computer scientist list" << endl;
- cout << "Input 2 to sort computer list" << endl;
- cin >> sort_input;
- if(!(sort_input == "1") && !(sort_input == "2"))
- {
- cout << "Invalid sort input. Please try again." << endl;
- }
- }while(!(sort_input == "1") && !(sort_input == "2"));
- Sortingfoo(sort_input);
- }
- else if(user_input == "search"|| user_input == "Search"|| user_input == "SEARCH")
- {
- cout << "Input 1 to search for a computer scientist" << endl;
- cout << "Input 2 to search for a computer" << endl;
- string pressed;
- cin >> pressed;
- if(pressed == "1")
- {
- cout << "Search by name or birthyear? " << endl;
- cin >> search_option;
- if(search_option == "name" || search_option == "Name" || search_option == "NAME")
- {
- cout << "Input the name of desired scientist: ";
- cin.ignore();
- getline(cin,search_name);
- SortingPrint(search_name,search_option);
- }
- else if(search_option == "birthyear" || search_option == "Birthyear" || search_option == "BIRTHYEAR")
- {
- cout << "Input a birthyear: ";
- cin.ignore();
- getline(cin,search_name);
- SortingPrint(search_name,search_option);
- }
- else
- {
- cout << "Invalid search command! Returned to main menu." << endl;
- }
- }
- else if(pressed == "2")
- {
- cout << "Search by name or year?" << endl;
- cin >> search_option;
- if(search_option == "name" || search_option == "Name" || search_option == "NAME")
- {
- cout << "Input the name of desired computer: ";
- cin.ignore();
- getline(cin,search_name);
- sortingComputerPrint(search_name,search_option);
- }
- else if(search_option == "year" || search_option == "year" || search_option == "year")
- {
- cout << "Input a year: ";
- cin.ignore();
- getline(cin,search_name);
- sortingComputerPrint(search_name,search_option);
- }
- else
- {
- cout << "Invalid search command! Returned to main menu." << endl;
- }
- }
- else
- {
- cout << "Invalid search command! Returned to main menu." << endl;
- }
- }
- else if(user_input =="Help" || user_input == "help" || user_input == "HELP")
- {
- Help();
- }
- else if(!(user_input == "quit"||user_input == "Quit" || user_input == "QUIT"))
- {
- cout << "Invalid command!" << endl;
- }
- ReAdd(); //display input options for user
- }while( !(user_input == "quit"||user_input == "Quit" || user_input == "QUIT") );
- exit(1);
- }
- void ConsoleUI::Help() // This contains keyword for every command you need to know for this program
- {
- cout << " This file contains keywords for every command input you need for this program." << endl;
- cout <<"-----------------------------------------------------------------------------------------------------"<< endl;
- cout << " Add - With this command you can add scientists, computers or connections to their appropriate table." << endl;
- cout <<"-----------------------------------------------------------------------------------------------------"<< endl;
- cout << " List - Displays desired table." << endl;
- cout <<"-----------------------------------------------------------------------------------------------------"<< endl;
- cout << " Sort - With this command you can sort the 'Scientists' and 'Computers' table by name, year and type " << endl;
- cout << " in ascending order or descending order." << endl;
- cout <<"----------------------------------------------------------------------------------------------------"<< endl;
- cout << " Search - Input '1' to search for computer scientists, input '2' to search for computers."<<"\n"
- << "\t" << "Then you can input '1' to search by name, input '2' to search by year or input '3' to search" << endl;
- cout << "\t" << "by type in Computers table." << endl;
- cout <<"-----------------------------------------------------------------------------------------------------"<< endl;;
- }
- void ConsoleUI::ReAdd() // This is the main menu after you have used any action
- {
- cout << "This is a main menu, add any of the following commands." << "\n"
- << "\t" << "Add - To add scientist to list." << "\n"
- << "\t" << "List - To display a table." << "\n"
- << "\t" << "Sort - To sort list."<< "\n"
- << "\t" << "Search - To search list."<< "\n"
- << "\t" << "Help - To get a review of all commands available." << "\n"
- << "\t" << "Quit - To quit program." << endl;
- cout << endl;
- }
- void ConsoleUI::displayListOfComputers(vector <Computer> listi) // Here you display the list of every computer that has been added to the program
- {
- vector <Computer> temp = listi;
- cout << left << setw(30) << "Name" << setw(7) << "Year" << setw(14) << "Type" << setw(27) << "Built" << endl;
- cout << setfill('-') << setw(71) << "-" << setfill(' ') << endl;
- for(size_t k = 0; k < temp.size(); k++)
- {
- cout << left << setw(30) << temp[k].getName() << setw(7) << temp[k].getYear() << setw(14) << temp[k].getType() << temp[k].getBuilt() << endl;
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement