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.

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 //#include //#include int Graph::debug_count = 0; Graph::Graph(int n) :

Graph.cpp

using namespace std; #include "Graph.h" #include //#include //#include int Graph::debug_count = 0; Graph::Graph(int n) : m_numVert(n), m_cap(n), m_numEdge(0), m_nz(new int[n]), m_re(new int[n + 1]), m_ci(new int[n]) { if (n

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 Graph::EgIterator::operator*() { // printf("[%i]:",m_indx,m_row,m_Gptr->m_ci[m_indx],m_Gptr->m_nz[m_indx]); if (m_indx >= m_Gptr->m_numEdge

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

Method Description of tests Tests exact correctness of the m_re, m_nz, and m_ci arrays. Since m_nz and m_ci should be ordered by increasing column index, there is a single correct configuration of the arrays. The test should check correctness of the arrays after any edge is inserted. testCSRExact() testCSRUnorderedTests correctness of the m_re, m nz, and m_ci arrays, without regard to ordering within each row. That is, if the values for each row are correct but are not ordered by increasing column index this test should pass. testNbIteratorO testEgitera Tests that the EgIterator produces a valid listing of the edges of the graph. All edges must be included testExceptions) Tests that an out_ of_range exception is thrown for every operations specified to do so in the Project 1 Tests that the NbIterator produces the correct set of neighbors for every vertex in the graph. and none may be repeated. description. Must check if some other exception is thrown, or no exception at all. Method Grader(string name-"") printAllErrors () resetErrorQueue() Description of method The Grader constructor; accepts an optional descriptive name for the object. Print all the errors in the error queue and the total point deductions; leaves the queue empty. Removes all entries from the error queue. Requirement: You must use at least one STL container class in addition to vector and queue, and the the third container must be used within one of the test methods of Grader. Good candidates for the third container are set or multiset. Requirement: The testCSRExact() and testCSRUnordered () functions shall test the correctness of the arrays whenever an edge is added to the graph. If at any point, one of the arrays is incorrect, then the implementation fails the test and the appropriate Error shall be pushed onto the queue. Requirement: No error (identified by the unique error id) shall be pushed into the error queue more than once. Suppose testCSRExact() checks the correctness of m_nz after each call to addEdge() and finds that the array is incorrect after each insertion; the error with id 102 should still only be pushed onto the queue once. Requirement: Contradictory errors shall not be pushed onto the Error queue. For example, only one of errors 510, 511 and 512 can occur; only one should appear in the queue. Reirnent So umumun (eg 100 200,30rnpiate Requirement: You must use the provided operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!