COMP 142 Project 4: Facebook

Update: March 4
I've added some details on how the variables work in memory when you add people and friendships to Facebook. Here is a walkthrough and corresponding diagram.

For this project, you will write a program similar to the Facebook website. This program will let you add people to a global database of "friends" and manipulate these friendships.

Program details

You should use a struct in your program to hold each Facebook user. The declaration of the struct should be the following:
struct person
{
  string name;
  string school;
  vector<person*> friends;
};
The struct contains the following information about a person on Facebook: Inside your main() function, you should declare a vector containing pointers to each individual person on Facebook, like this:
int main()
{
  vector<person*> all_people;
  // rest of code here
  
  // very last lines should deallocate all the people in the vector (delete them)
  return 0;
}
The entire friendship network is maintained through this vector of people. All of the individual people in the network should be allocated on the heap (using new), and then you will add pointers to those people to the all_people vector. At the end of main, you should use delete to deallocate the memory for all the people in the vector. Note that you will need a loop to do this, since you will have to delete each individual person one at a time. (This is unlike a C++ array, where we could use delete[] to deallocate the entire array at once.)

Operations your program must support

How the program should work

The people.txt file

This file is a very simple encoding of all the people and friendships that your version of Facebook should be loaded with at the beginning (other people or friendships might be added later by the user as the program runs). Reading and processing this file should be straightforward. It will be even easier if you make functions for adding a new person and adding a new friendship, because you can just call these functions while processing the file, and also use the same functions later when the user needs those options.

Here is a sample people.txt file.

Coding style

Testing your program

You should test your program thoroughly to make sure it works correctly.

Sample input and output

The program's output is in normal text; what the user types is in bold. This sample output uses the people.txt file from above.
1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 1

alice at rhodes is friends with
  bob at rhodes
  carla at sewanee
  dave at sewanee
bob at rhodes is friends with
  alice at rhodes
  carla at sewanee
  erin at rhodes
carla at sewanee is friends with
  alice at rhodes
  bob at rhodes
dave at sewanee is friends with
  alice at rhodes
  erin at rhodes
erin at rhodes is friends with
  dave at sewanee
  bob at rhodes

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 2

Who to look for? bob
bob at rhodes is friends with
  alice at rhodes
  carla at sewanee
  erin at rhodes

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 3

Who to look for? bob
bob at rhodes is friends with
  alice at rhodes
  erin at rhodes

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 4

What is this person's name?  fred
What is their school?  hendrix

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 5

Name 1? bob
Name 2? fred

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 1

alice at rhodes is friends with
  bob at rhodes
  carla at sewanee
  dave at sewanee
bob at rhodes is friends with
  alice at rhodes
  carla at sewanee
  erin at rhodes
  fred at hendrix
carla at sewanee is friends with
  alice at rhodes
  bob at rhodes
dave at sewanee is friends with
  alice at rhodes
  erin at rhodes
erin at rhodes is friends with
  dave at sewanee
  bob at rhodes
fred at hendrix is friends with
  bob at rhodes

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 6

Who is changing schools? bob
Change to which school? hendrix

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 1

alice at rhodes is friends with
  bob at hendrix
  carla at sewanee
  dave at sewanee
bob at hendrix is friends with
  alice at rhodes
  carla at sewanee
  erin at rhodes
  fred at hendrix
carla at sewanee is friends with
  alice at rhodes
  bob at hendrix
dave at sewanee is friends with
  alice at rhodes
  erin at rhodes
erin at rhodes is friends with
  dave at sewanee
  bob at hendrix
fred at hendrix is friends with
  bob at hendrix

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 7

Name 1? bob
Name 2? alice

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 1

alice at rhodes is friends with
  carla at sewanee
  dave at sewanee
bob at hendrix is friends with
  carla at sewanee
  erin at rhodes
  fred at hendrix
carla at sewanee is friends with
  alice at rhodes
  bob at hendrix
dave at sewanee is friends with
  alice at rhodes
  erin at rhodes
erin at rhodes is friends with
  dave at sewanee
  bob at hendrix
fred at hendrix is friends with
  bob at hendrix

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 8

Who to remove? bob

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 1

alice at rhodes is friends with
  carla at sewanee
  dave at sewanee
carla at sewanee is friends with
  alice at rhodes
dave at sewanee is friends with
  alice at rhodes
  erin at rhodes
erin at rhodes is friends with
  dave at sewanee
fred at hendrix is friends with
  nobody

1. Print all people and friends.
2. Print the friends of a person.
3. Print the friends of a person who go to the same school.
4. Add a new person.
5. Add a new friendship.
6. Change a person's school.
7. Remove a friendship.
8. Remove a person (and all their friendships).
9. Quit.

Enter choice: 9

Hints

What to turn in

Through Moodle, turn in your code as a file called facebook_yourLastName_yourFirstName.cpp. You do not need to turn in anything other than the .cpp file; I do not need all the other files that Visual Studio creates.

Challenge Problems