[Solved]Goal Assignment Reinforce Graph Concepts Algorithms Specifically Assignment Create Social Q37290184
The goal of this assignment is to reinforce graph concepts andalgorithms. Specifically, the assignment is to create a socialnetwork using a graph. Specifically, you will need to implementsocial_network.cpp You will need to read the data for the socialnetwork from a file. The files needed to implementsocial_network.cpp are located below. Please do not use any extrafunctions, only the functions in social_network.h need to beimplemented
social_network.h
#ifndef _SOCIAL_NETWORK_H_
#define _SOCIAL_NETWORK_H_
#include “graph.h”
#include
#include
using namespace main_savitch_15;
class social_network
{
public:
social_network();
// postcondition: empty social network has been created
social_network(const std::string& file_name);
// postcondition: social network using the data in file_name hasbeen created
std::set find_friends (const std::string& name) const;
// precondition: name is in the social network
// returned: set of friends of name
std::set find_friends_of_friends (const std::string& name)const;
// precondition: name is in the social network
// returned: set of friends of friends of name
void add_friend (const std::string& my_name, conststd::string& friend_name);
// precondition: my_name and friend_name are in the socialnetwork
// postcondition: friend_name is a friend of my_name
void add_person (const std::string& name);
// postcondition: name is in the social network
void remove_person (const std::string& name);
// postcondition: name is not in the social network – there are nofriend
// relationships in the social network
void remove_friend (const std::string& my_name,
const std::string&ex_friend_name);
// precondition: name and ex_friend_name are in the socialnetwork
// postcondition: ex_friend_name is not a friend of my_name
bool is_friend (const std::string& my_name,
const std::string&maybe_friend) const;
// precondition: my_name & maybe_friend are in the socialnetwork
// returned: whether maybe_friend is a friend of my_name
std::set members () const;
// returned: set of people who are in the social network
private:
graph network;
std::set indices_to_strings (const std::set&
indices) const;
// returned: set of members of the social network associated withthe
// indices in indices
};
#endif
=================================================
graph.h
// FILE: graph.h (part of the namespace main_savitch_15)
// TEMPLATE CLASS PROVIDED: graph (a class for labeledgraphs)
// The vertices of an n-vertex graph are numbered from zero to n-1.Each vertex
// has a label of type Item. It may be any of the C++ built-intypes (int,
// char, etc.), or any class with a default constructor and anassignment
// operator. The graph may not have multiple edges.
//
// MEMBER CONSTANTS for the graph template class:
// static const size_t MAXIMUM = ______
// graph::MAXIMUM is the maximum number of vertices that a graphcan have.
//
// CONSTRUCTOR for the graph template class:
// graph( )
// Postcondition: The graph has been initialized with no verticesand no edges.
//
// MODIFICATION MEMBER FUNCTIONS for the graph templateclass:
// void add_vertex(const Item& label)
// Postcondition: The size of the graph has been increased byadding one new
// vertex. This new vertex has the specified label and no edges. Iflabel
// was already in the graph, then nothing happens.
//
// void remove_vertex (const Item& label);
// Postcondition: label and all edges involving label have beenremoved
// If label were not in the graph, then nothing happens.
//
// void add_edge(size_t source, size_t target)
// Precondition: (source < size( )) and (target < size()).
// Postcondition: The graph has all the edges that it originallyhad, and it
// also has another edge from the specified source to the specifiedtarget.
// (If this edge was already present, then the graph isunchanged.)
//
// void remove_edge(size_t soure, size_t target)
// Precondition: (source < size( )) and (target < size()).
// Postcondition: The graph has all the edges that it originallyhad except
// for the edge from the specified source to the specified target.(If this
// edge was not originally present, then the graph isunchanged.)
//
// Item& operator [ ] (size_t vertex)
// Precondition: vertex < size( ).
// Postcondition: The return value is a reference to the label ofthe
// specified vertex.
//
// CONSTANT MEMBER FUNCTIONS for the graph template class:
// size_t size( ) const
// Postcondition: The return value is the number of vertices in thegraph.
//
// bool is_edge(size_t source, size_t target) const
// Precondition: (source < size( )) and (target < size()).
// Postcondition: The return value is true if the graph has an edgefrom
// source to target. Otherwise the return value is false.
//
// set neighbors(size_t vertex) const
// Precondition: (vertex < size( )).
// Postcondition: The return value is a set that contains all thevertex
// numbers of vertices that are the target of an edge whose sourceis at
// the specified vertex.
//
// Item operator [ ] (size_t vertex) const
// Precondition: vertex < size( ).
// Postcondition: The return value is a reference to the label ofthe
// specified vertex.
// NOTE: This function differs from the other operator [ ] becauseits
// return value is simply a copy of the Item (rather than areference of
// type Item&). Since this function returns only a copy of theItem, it is
// a const member function.
//
// std::size_t find_index (const Item& label) const
// Postcondition: The return value is the index associated withlabel. If
// label is not in the graph, MAXIMUM is returned.
//
// VALUE SEMANTICS for the graph template class:
// Assignments and the copy constructor may be used with graphobjects.
#ifndef MAIN_SAVITCH_GRAPH_H
#define MAIN_SAVITCH_GRAPH_H
#include // Provides size_t
#include // Provides set
namespace main_savitch_15
{
template
class graph
{
public:
// MEMBER CONSTANTS
static const std::size_t MAXIMUM = 20;
// CONSTRUCTOR
graph( ) { many_vertices = 0; }
// MODIFICATION MEMBER FUNCTIONS
void add_vertex(const Item& label);
void remove_vertex (const Item& label);
void add_edge(std::size_t source, std::size_t target);
void remove_edge(std::size_t source, std::size_t target);
Item& operator [ ] (std::size_t vertex);
// CONSTANT MEMBER FUNCTIONS
std::size_t size( ) const { return many_vertices; }
bool is_edge(std::size_t source, std::size_t target) const;
std::set neighbors(std::size_t vertex) const;
Item operator[ ] (std::size_t vertex) const;
std::size_t find_index (const Item& label) const;
private:
bool edges[MAXIMUM][MAXIMUM];
Item labels[MAXIMUM];
std::size_t many_vertices;
};
}
#include “graph.template” // Include the implementation.
#endif
=======================================
graph.template
// FILE: graph.template (part of the namespacemain_savitch_15)
// TEMPLATE CLASS IMPLEMENTED: graph (See graph.h fordocumentation.)
// This file is included in the header file and not compiledseparately.
// INVARIANT for the graph class:
// 1. The number of vertices in the graph is stored in the membervariable
// many_vertices.
// 1. These vertices are numbered from 0 to many_vertices-1.
// 2. edges is the adjacency matrix for the graph (with true inedges[i][j]
// to indicate an edge from vertex i to vertex j).
// 3. For each i < many_vertices, labels[i] is the label ofvertex i.
#include // Provides assert
namespace main_savitch_15
{
template
const std::size_t graph::MAXIMUM;
template
void graph::add_edge(std::size_t source, std::size_t target)
// Library facilities used: cassert, cstdlib
{
assert(source < size( ));
assert(target < size( ));
edges[source][target] = true;
}
template
void graph::add_vertex(const Item& label)
// Library facilities used: cassert, cstdlib
{
std::size_t location = find_index (label);
if (location == MAXIMUM)
{
std::size_t new_vertex_number;
std::size_t other_number;
assert(size( ) < MAXIMUM);
new_vertex_number = many_vertices;
many_vertices++;
for (other_number = 0; other_number < many_vertices;++other_number)
{
edges[other_number][new_vertex_number] = false;
edges[new_vertex_number][other_number] = false;
}
labels[new_vertex_number] = label;
}
}
template
bool graph::is_edge(std::size_t source, std::size_t target)const
// Library facilities used: cassert, cstdlib
{
assert(source < size( ));
assert(target < size( ));
return edges[source][target];
}
template
Item& graph::operator[ ] (std::size_t vertex)
// Library facilities used: cassert, cstdlib
{
assert(vertex < size( ));
return labels[vertex]; // Returns a reference to the label
}
template
Item graph::operator[ ] (std::size_t vertex) const
// Library facilities used: cassert, cstdlib
{
assert(vertex < size( ));
return labels[vertex]; // Returns only a copy of the label
}
template
std::set graph::neighbors(std::size_t vertex) const
// Library facilities used: cassert, cstdlib, set
{
std::set answer;
std::size_t i;
assert(vertex < size( ));
for (i = 0; i < size( ); ++i)
{
if (edges[vertex][i])
answer.insert(i);
}
return answer;
}
template
void graph::remove_edge(std::size_t source, std::size_ttarget)
// Library facilities used: cassert, cstdlib
{
assert(source < size( ));
assert(target < size( ));
edges[source][target] = false;
}
template
void graph::remove_vertex (const Item& label)
{
std::size_t index = find_index (label);
if (index != MAXIMUM)
{
for (std::size_t i = 0; i < many_vertices; i++)
{
edges[i][index] = edges[many_vertices-1][index];
edges[index][i] = edges[index][many_vertices-1];
}
labels[index] = labels[many_vertices-1];
many_vertices–;
}
}
template
std::size_t graph::find_index (const Item& label) const
{
std::size_t i = 0;
while (i < many_vertices && labels[i] != label)
i++;
if (i == many_vertices)
i = MAXIMUM;
return i;
}
}
Expert Answer
Answer to The goal of this assignment is to reinforce graph concepts and algorithms. Specifically, the assignment is to create a s… . . .
OR

