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

1 Introduction This assignment will be part 1 of 2 of the culmination of your C/

ID: 3689239 • Letter: 1

Question

1 Introduction This assignment will be part 1 of 2 of the culmination of your C/C++ programming experience in this course. You will use C++ classes to model a social network, allowing users to be added, friend connections made, etc. 2 What vou will learn In this assignment you will: 1. Create your own C++ classes and learn the syntax of defining data members and methods 2. Use File I/O and stringstreams to read/write text files containing structured data (records) Understand the abstract representation of graphs (vertices-Users, edges-Friend connections) 3. 3 Background Information and Notes Graph Representation: A graph is an abstract representation of the connections between objects. Each object (known as a vertex) is connected to others via 'edges'. Visually, graphs are quite intuitive: Jane Jimmy Marci Timmy Here we see four users (vertices) and the friend connections (edges) between them. Many interesting problems in computer science can be represented as graphs and algorithms defined to extract information from the connections within the graph. For our purposes we will create a class to represent a single User which contains information about each user (name, etc.) as well as the edge connections (friend relationships) for the user. Note: In our system edges are 'undirected' meaning friend connections are reflexive (i.e. if l'm a friend with you, you are a friend with me). Other problems using graphs may require 'directed' edges (i.e non-reflexive relationships). Thus, when you add a friend connection from userl1 to user2, be sure to add the connection from user2 to user1. Defining a File Format: This program requires you to use File I/O techniques to read and write the user database from and to a file. Whenever we write a file containing structured data we need to define a file format (syntax) so we

Explanation / Answer

// Due to time, I did not develop the full code, But I hope this may give u an idea to develop the remaining code

#include <iostream> // header files
#include <string> // inclusion of string for string objects

using namespace std;

class User // user class
{
private int id, year,zip; // members in user class
private string name;
int friends[100];
public User() // default constructor
{
  
}
public User(int id1,int year1,int zip1,string name1) // perameterized constructor to set the user data
{
id=id1;
year=year1; // setting the user data
zip=zip1;
name=name1;
}
void addfriend(int id) // method to add friend
{
int count=0;
int l=sizeof(friends)/sizeof(friends[0]); // storing array current size= number of friends
for(int i=0;i<l;i++)
{
if(friends[i]==id) // checking existence of friends
{
cout<<"friend exists already";
count=1;
}
else if(i==9 && count==1)
friends[l-1]=id;
}

}
void deletefriend(int id) // deleting friend
{

int l=sizeof(friends)/sizeof(friends[0]);
for(int i=0;i<l;i++)
{
if(friends[i]==id) // checking for the required friend
{
friends[i]=0;
}
else if(i==9)
cout<<"no such friend in your list";
}
}
int getId() // individual accessor methods
{
return id;
}
int getYear()
{
return year;
}
int getZip()
{
return zip;
}
string getName()
{
return name;
}
int[] getFriends()
{
return friends;
}
};

class Network //network class
{
User u;
Network net[100]; // members in network class, array of network objects
User user[100]; // array of user objects
  
public Network() // default constructor
{
  
}
addUser(int id,int year,int zip, string name) // add user method
{
int l=sizeof(user)/sizeof[0];
user[l-1]=new User(id,year,zip,name);
}
int getId(string name)
{
return user.getId(name);
}
int add_connection(string name1,string name2) // connection add method
{
int idt=u.getId();
int idt2=u.getId();
user[idt]=u.addfriend(idt2);
}
int remove_connection(string name1,string name2) remove connection method
{
int idt=u.getId();
int idt2=u.getId();
user[idt]=u.deletefriend(idt2);
  
}
};