Question
Need help with Grader.cpp file. In this project, you will complete a program to grade implementation of the Graph class. Graph.cpp using namespace std; #include
Need help with Grader.cpp file. In this project, you will complete a program to grade implementation of the Graph class.
Graph.cpp
using namespace std; #include "Graph.h" #include Graph::Graph(const Graph &G) : m_cap(G.m_cap), m_numEdge(G.m_numEdge), m_numVert(G.m_numVert), m_nz(new int[G.m_cap]), m_re(new int[G.m_numVert + 1]), m_ci(new int[G.m_cap]) { for (int i = 0; i Graph::~Graph() { } const Graph &Graph::operator=(const Graph &rhs) { m_numEdge = rhs.m_numEdge; m_numVert = rhs.m_numVert; m_cap = rhs.m_cap; m_ci = new int[m_cap]; m_re = new int[m_numVert + 1]; m_nz = new int[m_cap]; for (int i = 0; i int Graph::numVert() { return m_numVert; // return the number of vertices in graph } int Graph::numEdge() { return m_numEdge; // return number of edges in graph } void Graph::addEdge(int u, int v, int x) { // Determine which index is higher int max = u, min = v; if (u // Determine if vertices are in graph if (max >= m_numVert || min int i = m_re[min]; // Loop through to see if the edge is already in the graph for (; i // If the edge is already in the graph change the weight and do the same for the transposed coordinates if (m_ci[i] == max) { m_ci[i] = x; for (int j = m_re[max]; j m_numEdge++; // Increment the total number of edges // Expand column index and nonzero arrays if necessary if (m_numEdge m_cap) { m_cap // First element in Graph, special case if (m_numEdge == 1) { m_nz[0] = m_nz[1] = x; m_ci[0] = max; m_ci[1] = min; // return; } else { // Update the column index and non-zero arrays // i--; bool max_added = false; // Prevent adding value multiple times for (int j = m_numEdge * 2 - 1, slider = 2; j > i; j--) { cout m_re[max] && j - 1 // Update the row extent array for (int j = min; j = max ? 2 : 1; } } void Graph::dump() { cout // Print out row extent array cout // Print out nonzero array cout // Print out column index array cout Graph::EgIterator::EgIterator(Graph *Gptr, int indx) : m_Gptr(Gptr), m_indx(indx) { if (Gptr) { for (m_row = 0; (indx >= Gptr->m_re[m_row + 1] || (indx == Gptr->m_re[m_row] && indx == Gptr->m_re[m_row + 1])) && m_row m_numVert; m_row++); } } bool Graph::EgIterator::operator!=(const EgIterator &rhs) { return m_Gptr != rhs.m_Gptr || m_row != rhs.m_row || m_indx != rhs.m_indx; } void Graph::EgIterator::operator++(int dummy) { for (m_indx++; m_indx m_numEdge = m_Gptr->m_ci[m_indx]; m_indx++); for (; (m_indx >= m_Gptr->m_re[m_row + 1] || (m_indx == m_Gptr->m_re[m_row] && m_indx == m_Gptr->m_re[m_row + 1])) && m_row m_numVert; m_row++); } std::tuple return make_tuple(m_row, m_Gptr->m_ci[m_indx], m_Gptr->m_nz[m_indx]); } Graph::EgIterator Graph::egBegin() { return EgIterator(this); } Graph::EgIterator Graph::egEnd() { return EgIterator(this, m_numEdge * 2); } Graph::NbIterator::NbIterator(Graph *Gptr, int v, int indx) : m_Gptr(Gptr), m_indx(indx || !Gptr ? indx : Gptr->m_re[v]), m_row(v) { } bool Graph::NbIterator::operator!=(const NbIterator &rhs) { return m_Gptr != rhs.m_Gptr || m_row != rhs.m_row || m_indx != rhs.m_indx; } void Graph::NbIterator::operator++(int dummy) { if (++m_indx > m_Gptr->m_re[m_row + 1]) m_indx--; } int Graph::NbIterator::operator*() { if (m_indx == m_Gptr->m_re[m_row + 1]) throw out_of_range("NbIterator is already at end of row"); return m_Gptr->m_ci[m_indx]; } Graph::NbIterator Graph::nbBegin(int v) { return NbIterator(this, v); } Graph::NbIterator Graph::nbEnd(int v) { return NbIterator(this, v, m_re[v + 1]); } Driver.cpp https://userpages.umbc.edu/~cmarron/cs341.s19/projects/proj2files/driver.cpp Grade.h https://userpages.umbc.edu/~cmarron/cs341.s19/projects/proj2files/Grader.h
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started