Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <cstdlib>
- #include <vector>
- #include "User.h"
- #include "HashFriend.h"
- #include "HashInterest.h"
- //#include "Graph.h"
- //#include "HashInterest.h"
- //#include "HashSomethingIDK.h"
- using namespace std;
- bool logIn();
- int mainMenu();
- void viewFriends(int id);
- void searchNewFriends();
- void removeFriends(int id);
- void friendRecs();
- vector<User> userID;
- void readFile()
- {
- HashFriend hf;
- HashInterest hi;
- string firstName, lastName, userName, passWord, city, state, friendName, interest;
- string filename;
- unsigned id = 1;
- User empty;
- userID.push_back(empty); // index 0 is a empty user
- filename = "data.txt";
- ifstream inputfile;
- inputfile.open(filename);
- assert(inputfile);
- while(inputfile)
- {
- inputfile >> firstName;
- inputfile >> lastName;
- inputfile >> userName;
- inputfile >> passWord;
- inputfile.get(); // go to next line
- getline(inputfile, city, ',');
- getline(inputfile, state);
- User user(firstName, lastName, userName, passWord, city, state, id);
- getline(inputfile, friendName);
- istringstream tempF(friendName);
- while(tempF)
- {
- getline(tempF, friendName, ',');
- if(tempF.peek() == ' ')
- tempF.get();
- user.setFriends(friendName);
- }
- getline(inputfile, interest);
- istringstream tempI(interest);
- while(tempI)
- {
- getline(tempI, interest, ',');
- if(tempI.peek() == ' ')
- tempI.get();
- user.setInterests(interest);
- }
- while(inputfile.peek() == '\n')
- inputfile.get(); // go to next line
- while(inputfile.peek() == ' ')
- inputfile.get(); // go to next line
- userID.push_back(user); // insert to the id vector
- hf.insert(user);// insert to hashFriend
- hi.insert(user);// insert to hashInterest
- id ++;
- }
- inputfile.close();
- }
- int main()
- {
- string name;
- int choice;
- int id = 0;
- readFile();
- // Log in validation
- while (id <= 0)
- id = logIn();
- name = "<Name>";
- //name = user.getFirstName();
- cout << "\n\nWelcome, " << name << "!\n";
- do{
- choice = mainMenu();
- int temp = 1; //DELETE LATER, USED JUST FOR TESTING
- switch(choice)
- {
- case 1: // view friends
- viewFriends(temp);
- break;
- case 2: // search for new friends
- searchNewFriends();
- break;
- case 3: // friends rec
- friendRecs();
- break;
- case 4: //quit
- {
- /*
- ofstream outfile;
- outfile.open("userinfo.txt");
- //print to outfile
- outfile.close();
- */
- cout << " You are signed out"
- << "\n\t- GOODBYE! -" << endl;
- }
- }
- }while(choice != 4);
- return 0;
- }
- /// Returns bool for whether or not username & password combo are matched
- bool logIn()
- {
- string un, pw;
- cout << "\t- LOG IN -" << endl
- << "Username: ";
- cin >> un;
- cout << "Password: ";
- cin >> pw;
- if(1) // if un & pw combo are found
- return true;
- else
- return false;
- }
- /// Main Menu :)
- int mainMenu()
- {
- string input = "0";
- do{
- cout << "\n\t - MENU -" << endl
- << "1. View Friends" << endl
- << "2. Search for New Friends" << endl
- << "3. Friends Recommendations" << endl
- << "4. Quit\n\n"
- << "Enter choice: ";
- cin >> input;
- if(!isdigit(input[0]))
- {
- cout << "Please enter numbers only.\n";
- input = "0";
- }
- else if(!(input == "1" || input == "2" || input == "3" || input == "4"))
- {
- cout << "Invalid input.\n";
- input = "0";
- }
- }while(input == "0");
- cout << endl;
- int choice = atoi(input.c_str());
- return choice;
- }
- /// Menu option to view friends
- void viewFriends(int id)
- {
- id = 1; //temporarily assigned to spongebob
- string input = "0";
- User u = userID[1];
- cout << " - View Friends -" << endl;
- cout << "1. View all friends\n"
- << "2. View a friend's profile\n"
- << "3. Remove a friend\n\n"
- << "Enter choice or 'm' for menu: ";
- cin >> input;
- do{ if(input[0] == 'm')
- return;
- else if(!isdigit(input[0]))
- {
- cout << "Please enter numbers or 'm' only.\n\n";
- input = "0";
- }
- else if(!(input == "1" || input == "2" || input == "3"))
- {
- cout << "Invalid input.\n\n";
- input = "0";
- }
- else if (input == "3")
- {
- removeFriends(id);
- }
- else // input == 1 2 or 3
- {
- u.printFriends();
- cout << "1. View a friend's profile\n"
- << "2. Remove a friend\n\n"
- << "Enter choice or 'm' for menu: ";
- cin >> input;
- if (input == "1")
- {
- //friend profile function
- }
- else if (input == "2")
- {
- removeFriends(id);
- }
- }
- }while(input == "0");
- cout << endl;
- }
- /// Menu option to search for new friends
- void searchNewFriends()
- {
- string input = "0";
- cout << " - Search for New Friends -" << endl;
- do{
- cout << "1. Search by Name\n"
- << "2. Search by Interest\n\n"
- << "Enter choice or 'm' for menu: ";
- cin >> input;
- if(input[0] == 'm')
- return;
- else if(!isdigit(input[0]))
- {
- cout << "Please enter numbers or 'm' only.\n\n";
- input = "0";
- }
- else if(!(input == "1" || input == "2"))
- {
- cout << "Invalid input.\n\n";
- input = "0";
- }
- else // input == 1 or 2
- {
- //int choice = atoi(input.c_str());
- }
- }while(input == "0");
- cout << endl;
- }
- /// Menu option to get friend recommendations
- void friendRecs()
- {
- cout << " - Friend Recommendations -" << endl
- << "People you may know:\n\n"
- // print all the ppl using graph (?)
- << "Enter choice or 'm' for menu: ";
- cout << endl;
- }
- void removeFriends(int id)
- {
- string name, input;
- bool results;
- bool option = true;
- User u = userID[1]; // temporarily assigned to spongebob
- while (option)
- {
- bool find = true;
- while (find)
- {
- cout << "Enter the name of the friend you'd like to remove: " << endl;
- cin.ignore();
- getline(cin, name);
- results = u.searchFriend(name);
- if (results == 0)
- {
- cout << "Friend not found. Please try again. \n" << endl;
- }
- else
- {
- u.removeFriend(name);
- u.printFriends();
- find = false;
- }
- }
- bool more = true;
- while (more)
- {
- cout << "Would you like to remove more friends? ";;
- cin >> input;
- transform(input.begin(), input.end(), input.begin(), ::toupper);
- if (input == "NO")
- {
- cout << "Back to the main menu. " << endl;
- mainMenu();
- more = false;
- option = false;
- }
- else if (input == "YES")
- {
- more = false;
- }
- else
- {
- cout << "Please enter only yes or no " << endl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement