Menu

[Solved]Goal Assignment Reinforce Graph Concepts Algorithms Specifically Assignment Problem 7 Page Q37169003

The goal of this assignment is to reinforce graph concepts andalgorithms. Specifically, the assignment is to do problem 7 on page780 of the text. The queries that your code needs to implementare

  • list all the friends of a specified person

set<string> friends (const graph<string>&network const string& name);

  • list all the friends that 2 specified people have incommon

set<string> common_friends (const graph<string>&network, const string& name1, const string& name2);

  • list all the friends of the friends of a specified person

set<string> friends_of_friends ( constgraph<string>& network const string& my_name);

  • adding a friend

void add_friend (graph<string>& network, conststring& my_name, const string& new_friend);

  • removing a friend

void remove_friend (graph<string>& network, conststring& my_name, const string& ex_friend);

  • determine whether someone is a friend

bool is_friend (const graph<string>& network, conststring& my_name, const string& maybe_friend);

To read from a text file:

The following code will allow you to read from a text file. Thiscode assumes that the text file is of the following format. Noteyou should use a larger amount of data in your code.

4

Bob

Sally

Barbara

Steve

Bob Sally

Barbara Sally

Sally Bob

Steve Bob

Bob Steve

void tokenize (const string& s, string& first,string& second)

{

stringstream ss (s);

ss >> first;

ss >> second;

}

size_t get_index (const graph<string>& g, conststring& target)

{

size_t i = 0;

while (i < g.size() && g[i] != target)

++i;

assert (i < g.size());

return i;

}

graph<string>* create_graph (const string&file_name)

{

graph<string>* g = new graph<string>;

ifstream input(file_name.c_str());

size_t num;

input >> num;

string temp;

getline (input, temp);

assert (num <= g -> MAXIMUM);

string* names = new string[num];

for (size_t i = 0; i < num; ++i)

{

string s;

   getline (input, s);

names[i] = s;

g -> add_vertex (s);

}

string line;

while (getline (input, line))

{

string first, second;

tokenize (line, first, second);

g -> add_edge (get_index (*g, first), get_index (*g,second));

}

input.close();

return g;

}

Expert Answer


Answer to The goal of this assignment is to reinforce graph concepts and algorithms. Specifically, the assignment is to do problem… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *