Hi c++ experts, I am having trouble with an assignment in which I need to create
ID: 3572362 • Letter: H
Question
Hi c++ experts, I am having trouble with an assignment in which I need to create a function that determines if the number of edges of a graph is even or odd. The requirements are that the function must take in a multidimensional array as an argument, and return boolean values according to this post condition: returns true if every switch in a network(the graph) is of even degree. Otherwise, returns false.
The assignment uses graph.h and graph.template files, with these two functions used to create the graph:
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 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;
}
I created the graph in my main function by creating an object and loading the vertexes and edges into the graph. Here are the created vertexes and edges:
graph1.add_vertex(0);
graph1.add_vertex(1);
graph1.add_vertex(2);
graph1.add_vertex(3);
graph1.add_vertex(4);
graph1.add_vertex(5);
graph1.add_edge(0, 1);
graph1.add_edge(0, 2);
graph1.add_edge(1, 0);
graph1.add_edge(1, 3);
graph1.add_edge(2, 0);
graph1.add_edge(2, 3);
graph1.add_edge(3, 2);
graph1.add_edge(3, 1);
graph1.add_edge(3, 4);
graph1.add_edge(3, 5);
graph1.add_edge(4, 3);
graph1.add_edge(4, 5);
graph1.add_edge(5, 3);
graph1.add_edge(5, 4);
Now, I need a boolean function that will take in this graph I just created as an argument, count the number of true values and use mod2 to return if the graph has an even or odd number of connections. I have tried many times but cant figure it out. Please help!
Explanation / Answer
//graph.template
//graph.h
==================================================================
//searches.template
===================================================================
//searches.h
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.