Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The popular social network Facebook was founded by Mark Zuckerberg and his class

ID: 3712595 • Letter: T

Question

The popular social network Facebook was founded by Mark Zuckerberg and his classmates at Harvard University in 2004. At the time, he was a ophomore studying computer science Design and implement an application that maintains the data for a simple social network. Each person in the network should have a profile that contains the person's name, optional image, current status, and a list of friends. Your application should allow a user to join the network, leave the network, create a profile, modify the profile, search for other profiles, and add friends. (4 points)

Explanation / Answer

project02.cpp

#include <iostream>

#include <fstream>

#include <string>

#include <cstdlib>

#include "project02.h"

using namespace std;

ofstream fout;

ifstream fin;

void LoginScreen()

{

cout << "Please select from the following options by entering the corresponding number:" << endl << endl;

cout << "1. Sign up" << endl;

cout << "2. Log in" << endl;

cout << "3. User list" << endl;

cout << "4. Exit" << endl << endl;

cout << "Please make your selection (enter 1, 2, 3, or 4): ";

}

void UserInfo::signUp()

{

int offset;

string line;

bool isTaken;

string fName;

string lName;

string bYear;

string screenName;

cout << "Enter your first name: ";

cin >> fName;

setFirstName(fName);

cout << "Enter your last name: ";

cin >> lName;

setLastName(lName);

cout << "Enter your birth year: ";

cin >> bYear;

setBirthYear(bYear);

cout << "Create your screen name (no special characters or spaces): ";

do

{

cin >> screenName;

isTaken = false;

fin.open("RegisteredUsers.txt");

while (!fin.eof())

{

getline(fin, line);

if ((offset = line.find(screenName, 0)) != string::npos)

{

isTaken = true;

cout << "The username " << screenName << " is already taken, please choose a different username: ";

}

}

fin.close();

} while (isTaken = true && isTaken != false);

setScreenName(screenName);

cout << endl;

cout << "Registered with the following information:" << endl;

cout << endl;

cout << "Full name: " << getFirstName() << " " << getLastName() << endl;

cout << "Birth year: " << getBirthYear() << endl;

cout << "Screen name: " << getScreenName() << endl;

cout << "You may now log in to your newly created account." << endl;

cout << endl;

string infoFileName = screenName + "_info.txt";

string followerFileName = screenName + "_follow.txt";

string activityFileName = screenName + "_activity.txt";

registerUser(fout, screenName);

fout.open(infoFileName.c_str());

writeUserInfo(fout, fName, lName, bYear, screenName);

fout.close();

}

void writeUserInfo(ofstream & fout, string & first, string & last, string & year, string & screen)

{

fout << first + " " + last + " " + year + " " + screen + " ";

}

void registerUser(ofstream & fout, string screen)

{

fout.open("RegisteredUsers.txt", ios::app);

fout << " " + screen;

fout.close();

}

void listUsers()

{

ifstream fin;

string screen;

cout << "The following users are registered: " << endl << endl;

fin.open("RegisteredUsers.txt");

while(!fin.eof())

{

fin >> screen;

cout << screen << endl;

}

fin.close();

}

void UserInfo::signIn()

{

int offset;

string line;

bool exists;

string screenName;

cout << "Please enter your screen name to sign in: ";

do

{

cin >> screenName;

exists = true;

fin.open("RegisteredUsers.txt");

while (!fin.eof())

{

getline(fin, line);

if ((offset = line.find(screenName, 0)) == string::npos)

{

exists = false;

cout << endl;

cout << "User " << screenName << " does not exist!" << endl << endl;

cout << "Please enter an existing username to sign in: ";

}

}

fin.close();

} while (exists = false || exists != true);

cout << "You are now logged in as " + screenName << endl;

}

void UserInfo::displayProfile()

{

}

void UserInfo::setFirstName(string fName)

{

_firstName = fName;

}

string UserInfo::getFirstName()

{

return _firstName;

}

void UserInfo::setLastName(string lName)

{

_lastName = lName;

}

string UserInfo::getLastName()

{

return _lastName;

}

void UserInfo::setBirthYear(string bYear)

{

_birthYear = bYear;

}

string UserInfo::getBirthYear()

{

return _birthYear;

}

void UserInfo::setScreenName(string screenName)

{

_screenName = screenName;

}

string UserInfo::getScreenName()

{

return _screenName;

}

project02.h

#ifndef PROJECT02_H

#define PROJECT02_H

using namespace std;

void LoginScreen();

void writeUserInfo(ofstream & fout, string & first, string & last, string & year, string & screen);

void registerUser(ofstream & fout, string screen);

void listUsers();

class UserInfo

{

public:

string getFirstName();

void setFirstName(string first);

string getLastName();

void setLastName(string last);

string getBirthYear();

void setBirthYear(string year);

string getScreenName();

void setScreenName(string sn);

void signUp();

void signIn();

void displayProfile();

private:

string _firstName;

string _lastName;

string _birthYear;

string _screenName;

};

#endif // PROJECT02_H

project02main.cpp

#include <iostream>

#include <fstream>

#include <string>

#include <cstdlib>

#include "project02.h"

using namespace std;

int main()

{

char input;

UserInfo inputInfo;

cout << "Welcome to MyFace, a social media network where you can post your thoughts and see what your friends are up to." << endl << endl;

do

{

LoginScreen();

cin >> input;

cout << endl;

if (input == '1' && input != '2' && input != '3')

{

inputInfo.signUp();

}

else if (input == '2' && input != '3')

{

inputInfo.signIn();

}

else if(input == '3')

{

listUsers();

cout << endl;

system("PAUSE");

cout << endl;

LoginScreen();

}

else if (input != '1' && input != '2' && input != '3' && input != '4')

{

cout << "Invalid choice! Redirecting to login page..." << endl << endl;

}

else if (input == '4')

{

cout << "Thank you for using MyFace." << endl;

}

} while (input != '4');

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote