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

solce in C++ language 3. The popular social network Facebook was founded by Mark

ID: 3915433 • Letter: S

Question

solce in C++ language

3. The popular social network Facebook was founded by Mark Zuckerberg and his classmates at Harvard University in 2004. At the time, he was a sophomore 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

#include<iostream>

using namespace std;

class person{

string name;

string image;

string current_status;

int total_friend;

int friends[20];

public:

person(){

name="";

image="";

current_status="";

total_friend=0;

}

person(string nam,string img,string status){

name=nam;

image=img;

current_status=status;

total_friend=0;

}

void set_name(string nam){

name=nam;

}

void set_image(string img){

name=img;

}

void set_status(string status){

current_status=status;

}

void add_friend(int p){

friends[total_friend++]=p;

}

string get_name(){

return name;

}

string get_image(){

return image;

}

string get_status(){

return current_status;

}

int no_friend(){

return total_friend;

}

};

int main(){

person p[100];

int count=0;

int choice;

int index,id;

string name,img,status;

do{

cout<<"1:join network 2:create_profile 3:update profile 4:add friend 5:leave network 6:search for other 7:quit ";

cin>>choice;

switch(choice){

case 1:{cout<<"welcome to network! ";

cout<<"your id is : "<<count<<" ";

count++;

break;

}

case 2:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id ";

break;

}

cout<<"Enter name : ";

cin>>name;

cout<<"Enter image file name : ";

cin>>img;

cout<<"Enter current_status : ";

cin>>status;

p[id]=person(name,img,status);

break;

}

case 3:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id ";

break;

}

int another_choice;

do{

cout<<"1:change name 2:change image 3:change status 4:quit";

cin>>another_choice;

switch(another_choice){

case 1:{

cout<<"Enter name : ";

cin>>name;

p[id].set_name(name);

break;

}

case 2:{

cout<<"Enter image file name : ";

cin>>img;

p[id].set_image(img);

break;}

case 3:{

cout<<"Enter current status : ";

cin>>status;

p[id].set_status(status);

break;}

}}while(another_choice!=4);

break;

}

case 4:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id ";

break;

}

cout<<"enter id of friend : ";

int id2;

cin>>id2;

if(id2<0||id2>count){

cout<<"invalid id ";

break;

}

p[id].add_friend(id2);

break;

}

case 5:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id ";

break;

}

for(int i=id;i<count-1;i++)

p[i]=p[i+1];

count--;

break;

}

case 6:{

cout<<"Enter your id to be searched: ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id ";

break;

}

cout<<" name : "<<p[id].get_name();

cout<<" image : "<<p[id].get_image();

cout<<" current status : "<<p[id].get_status();

cout<<" number of friends : " <<p[id].no_friend();

cout<<" ";

break;

}

case 7:{

cout<<"Thank You! ";

break;

}

}

}while(choice!=7);

return 0;

}

/*for any query please comment.

please upvote if find it helpful.

Thank you!./**/