示例#1
0
int main(){
	int selection = 0;
	int userselection = 0;
	std::string username;
	UserList *UserListDatabase = new UserList;


		UserListDatabase->importUserDatabase();
		UserListDatabase->completeList();

		cout << "         ConnectMe v2.0          " << endl;
		cout << "*-------------------------------*" << endl;
		cout << "| 1. Login as a user.           |" << endl;
		cout << "| 2. Create a new user.         |" << endl;
		cout << "| 3. Quit the program           |" << endl;
		cout << "*-------------------------------*" << endl;

		while (selection != 3)
					{
						cout << "Selection: ";
						cin >> selection;
						if (cin.fail())
						{
							cin.clear();
							cin.ignore(1024, '\n');
							cout << "Invalid Selection." << endl;
							continue;
						}
						cin.clear();
						cin.ignore(1024,'\n');

						cout << endl;
						switch (selection)
						{
						// Login function
							case 1:
								{
									cout << "Please enter your username." << endl;
									cout << "Username: "******"Welcome back " << username << "!" << endl;
									cout << endl;

									usermenu();

									while (userselection !=11){
										cout << "Selection: ";
										cin >> userselection;
										if (cin.fail()){
											cin.clear();
											cin.ignore(1024, '\n');
											cout << "Invalid Selection." << endl;
											continue;
										}
										cin.clear();
										cin.ignore(1024,'\n');

										cout << endl;
										switch (userselection){
											case 1: // display all wall post
											{
												currentUser->getWall()->printWallPosts();
												cout << endl;
												usermenu();
												break;
											}
											case 2: // create a new wall post
											{
												string newmessage;
												char messagepost[512];
												cout << "Please enter a status update to your wall." << endl;
												cin.getline(messagepost,512);
												newmessage = messagepost;
												currentUser->addWallPost(newmessage);
												cout << endl;
												usermenu();
												break;
											}
											case 3:	// delete a wallpost
											{
												int id;
												cout << "Please enter the post ID number you wish to remove." << endl;
												cin >> id;
												currentUser->removeWallPost(id);
												break;
											}
											case 4: // edit personal information
											{
												currentUser->editInformation();
												cout << endl;
												usermenu();
												break;
											}
											case 5: // display personal information
											{
												currentUser->printInformation();
												cout << endl;
												usermenu();
												break;
											}
											case 6:
											{
												char usernamesearch[256];
												cout << "Please enter a user to search." << endl;
												cin.getline (usernamesearch, 256);
												string newusername;
												newusername = fixString(usernamesearch);

												bool searchUser = UserListDatabase->findUser(usernamesearch, currentUser);
												if (searchUser == true){
													cout << "User(s) exists." << endl;
												}
												else{
													cout << "User(s) does not exist." << endl;
												}
												cout << endl;
												usermenu();
												break;
											}
											case 7:
											{
												string friendname;
												cout << "Please enter the name of the user you'd like to add as a friend." << endl;
												cin >> friendname;
												User* friendUser = UserListDatabase->checkUser(friendname);
												bool checkUser = UserListDatabase->validUser(friendname);
												if (checkUser == true){
													if (friendUser->getusername() == currentUser->getusername()){
														cout << "You cannot add yourself as a friend! Loner." << endl;
													}
													else{
														currentUser->addFriend(friendUser);
														friendUser->addPendingFriend(currentUser);
														cout << "Success: Friend request added." << endl;
													}
												}
												else {
													cout << "No user exists." << endl;
												}
												break;
											}
											case 8:
											{
												currentUser->displayFriends();
												cout << endl;
												usermenu();
												break;
											}
											case 9:
											{
												currentUser->removeFriend();
												cout << endl;
												usermenu();
												break;
											}
											case 10:
											{
												currentUser->displayPendingFriends();
												cout << endl;
												if (currentUser->pendingEmpty() == true){
													cout << "No pending friends." << endl;
												}
												else{
													currentUser->acceptFriendRequest();
													currentUser->removePendingRequest();
												}
												usermenu();

												break;
											}
											case 11:
											{
												UserListDatabase->exportUserDatabase();
												cout << "> Database exported." << endl << endl;
												cout << ">> You have successfully been logged out." << endl;
												cout << ">> Program has exited." << endl << endl;
												break;
											}
											default:
											{
												cout << " *--------------------------------*" << endl;
												cout << " |        Invalid choice.         |" << endl;
												cout << " *--------------------------------*" << endl;
												cout << endl;
												break;
											}
										} // end switch
									} // end while
									return userselection;
								} // if statement
									else {
										cout << "*-----------------------------------------*" << endl;
										cout << "| Error: User does not exist in database. |" << endl;
										cout << "*-----------------------------------------*" << endl;
									}
									break;
								} // end case 1
						// Create user function
							case 2:
								{
									string name;
									cout << "Please enter a username." << endl;
									cin >> name;
									User* existingUser = UserListDatabase->checkUser(name);
									if (existingUser == NULL){
										User *tempUser = new User();
										tempUser->setusername(name);
										UserListDatabase->addUser(*tempUser);
									}
									else{
										cout << endl;
										cout << "! User exists already. Please choose a different username. !" << endl;
									}
									cout << endl;
									menu();
									break;
								}
						// This quits the program
							case 3:
								{
									UserListDatabase->exportUserDatabase();
									cout << "* Database has been exported successfully *" << endl;
									cout << "*-----------------------------------------*" << endl;
									cout << "| Program has been exited successfully.   |" << endl;
									cout << "*-----------------------------------------*" << endl;
									cout << endl;
								break;
								}
						// Error output
							default:
								{
									cout << "*--------------------------------*" << endl;
									cout << "|        Invalid choice.         |" << endl;
									cout << "*--------------------------------*" << endl;
									cout << endl;
								break;
								}
						}
示例#2
0
void menu(int choice, bool &goBackToFirstMenu, UserList &dataList)
{
	while(choice != 1 && choice != 2 && choice != 3 && choice != 4) //if user enters something other than 1,2,3
	{
		cout << "Please enter a correct number." << endl;
		cin >> choice;
	}

	if(choice == 1)
	{
		checkUsername(dataList);
	}
	else if(choice == 2)
	{
		bool checkIfExists;
		User newuser;
		cout << "Hi! You are about to create a new user." << endl;
		cout << endl;
		cout << "What is the user's name?" << endl;
		string newName;
		getline(cin, newName);
		getline(cin, newName);
		newuser.setName(newName);
		cout << "Make a username for yourself! (Remember, no spaces in usernames)" << endl;
		string newUserName;
		cin >> newUserName;
		newuser.setUsername(newUserName);
		checkIfExists = dataList.checkIfSame(newUserName);
		while(checkIfExists == true)
		{
			cout << "Try entering another username" << endl;
			string enterNewName;
			cin >> enterNewName;
			newuser.setUsername(enterNewName);
			checkIfExists = dataList.checkIfSame(enterNewName);
		}
		//cout << endl;
		cout << "Make your own password! (remember, no spaces!)" << endl;
		string newPassword;
		cin >> newPassword;
		cout << "For security purposes, please enter your password again." << endl;
		string checkNewPassword;
		cin >> checkNewPassword;
		while(newPassword != checkNewPassword)
		{
			cout << "Please enter your password again!" << endl;
			cin >> checkNewPassword;
		}
		newuser.setPassword(newPassword);
		//cout << endl;
		cout << "Now for the third element, please type which university you go to!" << endl;
		string newUniversity;
		getline(cin,newUniversity);
		getline(cin,newUniversity);
		cout << endl;
		newuser.setUniversity(newUniversity);
		cout << "Your university is " << newUniversity << "!" << endl;
		cout << endl;

		dataList.addUser(newuser);
		User addANewUser;
		string university = "USC";
		string password = "******";
		string username = "******";
		string comment = "COMMENT";
		string comment1 = "HEY WHATS UP";
		string randomizing;
		for(int i = 0; i < 10000; i++)
		{
			randomizing = generatingRandom();
			addANewUser.setUsername(randomizing);
			addANewUser.setPassword(password);
			addANewUser.setUniversity(university);
			//addANewUser.addPostAutomatic(username, comment);
			addANewUser.addPostAutomatic(username, comment1);
			//dataList.addUser(addANewUser);
			//addANewUser.
			for(int j = 0; j < 100; j++)
			{
				//addANewUser.addFriends()
			}
			//dataList.writeFile();
		}

	}