Order Now  +1 678 648 4277 

Social Media Assignment Solution with C++


Social Networking Site Problem 

Background

A social networking site is an online platform that people use to build social networks or social relationships with other people who share similar personal or career content, interests, activities, backgrounds, or real-life connections.

For this project, we are going to create a simple social networking application for an organization with up to 100 people. Each person can then become friends with those people in the organization.

Person Data (provided in proj2_data.txt):

Emi, Carson, 23, 8370814

  • First name (string)
  • Last name (string)
  • Age (int)
  • ID (int)

Assignment Description

Initially, you should work to write the functions in the Person class. A Person is made up of the data listed above and an array of Friends. Every Person is limited to the maximum number of friends defined by the constant MAX_FRIENDS. The Person class will be used repeatedly when the roster is loaded into the Organization. An Organization is made up of a roster that is limited to the constant MAX_PEOPLE. The FriendFinder class manages the Organization and provides the menu interface for the application.

Project 2 Data

Emi,Carson,23,8370814

Mona,Le,20,9463966

Yoshio,Sexton,33,2323882

Kyra,Mcpherson,21,9592591

Quinn,Tran,25,2129671

Lucas,Bauer,21,4575126

Ira,Kinney,22,7997049

Joshua,Harvey,23,1895638

Gil,Rosario,17,1933204

Janna,Atkinson,20,3978656

Halla,Tran,18,9670083

Carter,Sexton,18,6575858

Indigo,Mayo,28,1952294

Iona,Foreman,22,3675316

Athena,Burgess,30,8569290

August,Daniels,22,7452692

Ignacia,Mckay,28,2761324

Upton,Lopez,21,5547618

Pandora,Sheppard,26,8503400

Amos,Thomas,20,1488720

Clark,Adkins,22,7919226

Aphrodite,Greer,19,4344036

Xanthus,Valencia,18,4291906

Ifeoma,Leonard,22,2608932

Keefe,Phelps,21,7686363

Yardley,Silva,19,2748189

Abbot,Carson,21,2791002

Fulton,Richard,19,3377666

Harrison,Hoffman,20,4232583

Vivian,Dillon,18,3784711

Samson,Curry,24,4751015

Graiden,Ford,22,2934261

Hakeem,Mack,26,9309717

Talon,Randall,24,7160741

Reuben,Jacobs,19,9089986

Hunter,Burton,21,8634910

Tallulah,Spencer,26,4517234

Kenyon,Holmes,21,6343599

Deacon,James,20,2698324

Dylan,Townsend,20,7469253


Solution:

FriendFinder

#include < iostream> #include < string> #include "Organization.h" //Must be implemented before FriendFinder #include "Person.h" //Must be implemented before FriendFinder using namespace std; class FriendFinder { public: // Name: FriendFinder // Desc - Default constructor for application for finding friends // Preconditions - Creates a Person and an organization // Postconditions - Welcomes user and calls Start() FriendFinder(); // Name: GetDetails // Desc - Asks user for their first name, last name, age, and ID to populate m_me // Preconditions - None // Postconditions - Populates information related to m_me void GetDetails(); // Name: DisplayMenu // Desc - Displays main menu for application // Preconditions - None // Postconditions - Called from Start updates integer passed void DisplayMenu(int &choice); // Name: Start // Desc - Main function running FriendFinder // Calls GetDetails // Populates data for organization // Continually calls DisplayMenu until someone enters 4 (exit) // Preconditions - m_me and m_organization are created but not populated // Postconditions - Runs until user enters 4. Thanks user for usage. Ends application void Start(); private: Person m_me; //Information about me Organization m_organization; //Information about my organization }; #endif

Organization:

#include < iostream> #include < string> #include < fstream> #include "Person.h" //Must be implemented before Organization using namespace std; //Constants const int MAX_PEOPLE = 40; //Maximum number of people in organization const string FILE_NAME = "proj2_data.txt"; class Organization { public: // Name: Organization // Desc - Default constructor for Organization // Preconditions - None // Postconditions - Organization is created (empty) with 0 people in the roster Organization(); // Name: SetName // Desc - Sets m_name by asking user for name // Preconditions - m_name exists // Postconditions - Asks user for the organization name and populates m_name void SetName(); // Name: LoadRoster // Desc - Sets m_fileName by asking user. Then populates all of the people loaded from file // Preconditions - m_fileName exists. m_roster empty // Postconditions - Asks user for m_fileName. Loads data from file and populates m_roster void LoadRoster(); // Name: DisplayRoster // Desc - Displays a numbered list of everyone in the roster (starts at 1) // Preconditions - m_roster is populated // Postconditions - Displays a numbered list of people void DisplayRoster(); // Name: GetPerson // Desc - Displays a list of people in m_roster and user enters number of desired person. // Returns pointer of that person in m_roster // Preconditions - m_roster is populated // Postconditions - Returns pointer for the person chosen from list Person* GetPerson(); // Getters string GetName() { return m_name; } private: string m_name; //Name of the organization string m_fileName; //Name of the input file int m_numRoster; //Number of people in roster Person m_roster[MAX_PEOPLE]; //Roster of people in the organization }; #endif

PERSON

#include < iostream> #include < string> using namespace std; //constants const int MAX_FRIENDS = 10; //Maximum number of friends a person can have class Person { public: // Name: Person // Desc - Default Constructor for a Person // Preconditions - Creates a Person with no data associated with it // Postconditions - a Person is created Person(); // Name: Person // Desc - Overloaded Constructor for a Person // Preconditions - Creates a Person with passed data // Postconditions - a Person is created Person(string, string, int, int); // Name: AddFriend // Desc - A person pointer is stored from the roster of people in an organization // Preconditions - A person pointer is passed // Postconditions - A person pointer is added to this person's m_friend's array // if not at maximum and not already in the array void AddFriend(Person*); // Name: RemoveFriend // Desc - Removes a person pointer from this person's m_friend array // Preconditions - Person pointer exists in m_friend // Postconditions - Person is removed from m_friend and all pointers are moved towards front void RemoveFriend(Person*); // Name: CheckID // Desc - Checks to see if a specific person ID exists in m_friends - Note: IDs will always be unique in proj2 // Preconditions - m_friends is populated // Postconditions - Returns true if id exists in m_friends else false bool CheckID(int); // Name: DisplayFriends // Desc - Displays information about each friend in the m_friend array // Preconditions - People are in the m_friend array // Postconditions - Displays information about person object in array void DisplayFriends(); // Name: DisplayDetails // Desc - Displays information about this person // Preconditions - Person data is populated // Postconditions - Displays information about person object void DisplayDetails(); // Name: SetDetails // Desc - Used as a setter for first name, last name, age, and id // Preconditions - Person already created // Postconditions - Member variables populated void SetDetails(string, string, int, int); // add a friend operator so it is easier to print a person friend ostream& operator<<(ostream& os, Person const& p) { return os << p.m_fName << " " << p.m_lName << " (" << p.m_age << " yrs) " << p.m_ID; } // getter for array of friends. Required for option when user wants to remove a Friend Person** GetFriends() { return m_friends; } int GetFriendsCount() { return m_friendCount; } private: string m_fName; //Person's first name string m_lName; //Person's last name int m_age; //Person's age int m_ID; //Person's ID Person* m_friends[MAX_FRIENDS]; //Person's array of friends int m_friendCount; //Person's count of friends }; #endif //Protects against multiple inclusion