2019
Social Network in C++
Related Links
A simple C++ example of a social network.
How to run the program (Ubuntu)
- Open terminal.
-
Install
gcc(g++), the C++ compiler.
Or install$ sudo apt install g++build-essential, which also installs libraries as well as the gcc compiler.$ sudo apt-get install build-essential -
Check the gcc version.
$ gcc --version -
Go to the folder of the program.
$ cd /path_to_folder/folder -
Compile the C++ program (
main.cpp).$ sudo g++ main.cpp -
Run the C++ program.
$ ./main
Folders and Files
Folders
The only folder that exists is the folder of the header files (header_files). More details about the header files later.
User files
Each user file has as its file name the name of the corresponding user, and contains the other users with whom they are friends. For example, the file named kostas contains all friends of user kostas.
The following files have already been created for easier understanding and use of this social network:
kostasmariatomgeorgeannajohn
Network files
-
conversations — Contains conversations between users and their friends.
Logged_in_user : post_of_logged_in_user reply_from_friend_user (name_of_friend) -
database — Contains pairs of usernames and passwords from all registered users in the Social Network.
user1 password_of_user1 user2 password_of_user2 -
likes — Contains posts of users and likes from friends and their names.
Logged_in_user : post_of_logged_in_user LIKE! (name_of_friend) -
posts — Contains posts from all registered users in the Social Network.
user_name_1 post_of_user_name_1 user_name_2 post_of_user_name_2 -
Requests — Contains friend requests that have been sent from a user to another user with whom they are not friends.
user_sent_request -> user_to_accept/reject_request - TempReq — A temporary file used in the program.
- users — Contains only the names of all registered users in the Social Network.
Basic header files
The main header files used in the program are:
iostream, fstream, sstream, unistd.h
Local header files
The header files contained in the header files folder, used in the program, are:
mainmenu.hregistration.hlogin.hmenu2.hviewposts.hviewfriendposts.hmenu3.hfriendrequest.hfriends.hdeletefriends.hlistusers.hgoback.hexxit.h
mainmenu.h
The very first menu that the user sees. The user can select one of the 3 available choices by pressing the corresponding number:
- Register
- Log In
- Exit the program
If the user presses a number different from the given ones, he goes back to the first menu.
registration.h
The user types their desired username and password. If either already exists, the user is asked to repeat the process. If the process is done correctly, he can choose from 3 options:
- Log In
- Return to main menu
- Exit the program
login.h
Initially a check is made whether the user is already registered or not. Then the user enters his username and password and goes to the second menu.
menu2.h
After the user logs in successfully, he enters the Social Network menu where he can choose one of the following options:
- My wall
- Friend’s wall
- Send friend request
- Accept/Reject friend request
- My friends
- Delete friend
- Back
- Log out
- Exit the program
viewposts.h
By choosing My wall from the above menu, the user can see one of the following:
- His own posts
- His friends’ posts
- Conversations with friends
- Likes from friends on his own posts
Finally he is asked whether to return to the Social Network menu or not.
viewfriendposts.h
By selecting Friend’s wall from the menu, the user can choose one of the following options:
- Post a message on his wall
- Reply to a post
- Leave a Like
- Main Menu
- If he chooses the first one (i), he can write the post that he wants, and this will be added to the
postsfile at the end after the login name is added above. - If he chooses the second option (ii), he can choose one of his friends, view the friend’s posts, and choose the post he wants to reply to. The user then writes the reply, which is stored in the
conversationsfile as a reply to the friend’s post, saved with his name in brackets at the end. Finally, the logged-in user can reply to another post of the same friend if he wants. - If he chooses the third option (iii), the process is exactly the same as before, but instead of a reply, the user leaves a
LIKE!which is stored in thelikesfile under the selected friend’s post, before the older likes. - If he chooses the 4th option (iv), he returns to the Social Network menu.
menu3.h
By selecting Send friend request, the logged-in user can send a friend request to one of the registered users with whom he is not already friends. By pressing the number that corresponds to the desired friend-user, the request is saved in the Requests file as:
user_to_sent_request -> user_to_accept/reject_request
Finally, the user can also choose whether to send a friend request to other non-friend users or not.
friendrequest.h
By selecting Accept/Reject friend request, the logged-in user can check all the requests he has received and press the number corresponding to the name of the user whose request he wants to accept. When a request is accepted, the two users are added to each other’s file as friends, and the request is deleted from the Requests file. If there are additional friend requests but the user exits the Accept/Reject friend request menu, this is equivalent to rejecting the rest of the requests.
friends.h
By selecting My friends, the logged-in user can check the other registered users with whom he is friends, and then return to the Social Network menu if he wants.
deletefriends.h
By selecting Delete friend, the logged-in user can see a list of his friends and, if he wants, delete one of them by typing the number corresponding to that friend. The two involved users are then removed from each other’s file. Finally, the user can delete more friends if he wants.
listusers.h
Counts the number of all registered users by reading the pairs (username, password) from the database file.
goback.h
By selecting Back, the logged-in user can return to the menu or leave the Social Network and the program. If the user selects the Log out option, he returns to the first menu of the program.
exxit.h
By selecting Exit the program, the logged-in user leaves the Social Network. The program terminates and a message appears, like the following:
Program termination
Thanks for your visit logged_in_user_name !
