int main(int argc, char *argv[]) { //establish network //check for error in command line arguements Network myNetwork; if( argc != 2) { return 1; } int x = myNetwork.read_friends(argv[1]); if (x == -1) { cout << "Error" << endl; } int n; //loop while commands are correct or until exited while(true) { cout << "Enter a 1 if you would like to add a user" << endl; cout << "Enter a 2 if you would like to add a friend connection" << endl; cout << "Enter a 3 if you would like to remove friend connection" << endl; cout << "Enter a 4 if you would like to list users" << endl; cout << "Enter a 5 if you would like to list friends" << endl; cout << "Enter a 6 if you would like a write to file" << endl; cout << "Enter a 7 if you would like to know the distance between two users" << endl; cout << "And anything else if you would like to exit" << endl; cin >> n; if(n==1) { string firstname; string lastname; string name; int year; int zip; cin >> firstname >> lastname >> year >> zip; name += '\t'; name += firstname; name += ' '; name += lastname; User newuser(0, name, year, zip); myNetwork.add_user(newuser); } else if(n==2)
int main(int argc, char *argv[]) { //ifstream ifile(argv[1]); Network n; n.read_friends(argv[1]); char filename[100]; // n.write_friends("hello.out"); int choice; //User* user1; //User *user2; int user1id, user2id; while (true) { cout << "Enter the number for the option you wish to choose:" << endl; cout << "1. Add a user" << endl; cout << "2. Add friend connection" << endl; cout << "3. Remove friend connection" << endl; cout << "4. Print users" << endl; cout << "5. List friends" << endl; cout << "6. Write to file" << endl; cout << "7. Find relational distance between 2 users" << endl; cout << "8. Find groups sets" << endl; cout << "9. Find friend suggestions" << endl; cout << "Enter any other number to exit program" << endl; cin >> choice; string name, first_name, last_name; string name1, name2, first_name1, last_name1,first_name2, last_name2; int birthdate, zipcode; if (choice==1) { cin >> first_name >> last_name >> birthdate >> zipcode; name= first_name+" " + last_name; User* user1=new User(name,birthdate,zipcode); //user id provided by network n.add_user(user1); }//if else if (choice==2) {
int main(int argc, char *argv[]) { if (argc != 2) //check to see if usage is correct { cerr << "ERROR: Usage: ./social_network input.txt" << endl; return -1; } Network net; if (net.read_friends(argv[1]) == -1) //check to see if reading file failed { return -1; } int option = 1; //keep track of what option the user last inputted while (option <= 9 && option >= 1) //as long as the last option was valid, loop { BEGIN: cout << "Input a number:" << endl; //return place when error occurs cout << '\t' << "Option 1. Add a user" << endl; cout << '\t' << "Option 2. Add a friend connection" << endl; cout << '\t' << "Option 3. Remove a friend connection" << endl; cout << '\t' << "Option 4. Print users" << endl; cout << '\t' << "Option 5. List a user's friends" << endl; cout << '\t' << "Option 6. Write user database to file" << endl; cout << '\t' << "Option 7. Find shortest relational distance between two people" << endl; cout << '\t' << "Option 8. Assess groups in the network" << endl; cout << '\t' << "Option 9. Suggest friends for a person" << endl; cout << "Input any other number to exit the program" << endl; cin >> option; //ask for user's selection of options vector<User> network_users = net.return_userlist(); //ADD USER if (option == 1) { string fname, lname, username; int birth, zip; vector<int> friends; cin >> fname >> lname >> birth >> zip; if (cin.fail()) //check if input usage was correct { cerr << "ERROR: Usage: first_name last_name birthyear zipcode"; cerr << endl << endl; goto BEGIN; //go back to the menu if usage was wrong } username = fname + " " + lname; //combine first name and last name into a string net.add_user(network_users.size(), username, birth, zip, friends); cout << "User " << username << " added!" << endl << endl; } //ADD CONNECTION if (option == 2) { string fname1, lname1, fname2, lname2, username1, username2; cin >> fname1 >> lname1 >> fname2 >> lname2; username1 = fname1 + " " + lname1; //combine first pair of names username2 = fname2 + " " + lname2; //combine second pair of names int id1 = net.get_id(username1); int id2 = net.get_id(username2); if (id1 == -1) //check if id1 exists { cerr << "ERROR: Usage: first_name1 last_name1 first_name2 last_name2" << endl; cerr << "Username 1 does not exist" << endl << endl; goto BEGIN; } else if (id2 == -1) //check if id2 exists { cerr << "ERROR: Usage: first_name1 last_name1 first_name2 last_name2" << endl; cerr << "Username 2 does not exist" << endl << endl; goto BEGIN; } net.add_connection(id1, id2); cout << "Connection added between " << username1 << " and "; cout << username2 << "!" << endl << endl; }