Question: how to implement grader.cpp #include Grader.h #include BaselineGraph.h #include Graph.h Grader::Grader(string name) { m_name = name; } bool Grader::testCSRExact(int numVert, vector edgeSeq) { return true;

how to implement grader.cpp

#include "Grader.h"

#include "BaselineGraph.h"

#include "Graph.h"

Grader::Grader(string name) {

m_name = name;

}

bool Grader::testCSRExact(int numVert, vector edgeSeq) {

return true;

}

bool Grader::testCSRUnordered(int numVert, vector edgeSeq) {

return true;

}

bool Grader::testNbIterator(int numVert, vector edgeSeq) {

return true;

}

bool Grader::testEgIterator(int numVert, vector edgeSeq) {

return true;

}

bool Grader::testExceptions(int numVert, vector edgeSeq) {

return true;

}

void Grader::resetErrorQueue() {

}

// Formatted output of Error object:

// deduction: (id) description

ostream& operator<<(ostream& outStream, const Error& err) {

if (err.m_deduction > 0) {

outStream << "-" << err.m_deduction << ": (" << err.m_id

<< ") " << err.m_description;

} else {

outStream << err.m_deduction << ": (" << err.m_id

<< ") " << err.m_description;

}

return outStream;

}

#ifndef _BASELINEGRAPH_H_

#define _BASELINEGRAPH_H_

#include // For throwing out_of_range exceptions

#include // Edges are represented as tuple

#include // m_nz, m_ci, and m_re are of type vector

class Grader; // Forward declaration needed for 'friend'

namespace Baseline {

class Graph {

public:

friend Grader; // Allows Grader class to access private variables

// Graph constructor; must give number of vertices

Graph(int n);

// return number of vertices

int numVert();

// return number of edges

int numEdge();

// add edge between u and v with weight x

void addEdge(int u, int v, int x);

// print out data structure for debugging

void dump();

// Edge Iterator inner class

class EgIterator {

public:

// Edge Iterator constructor; indx can be used to

// set m_indx for begin and end iterators.

EgIterator(Graph *Gptr = nullptr, int indx = 0);

// Compare iterators; only makes sense to compare with

// end iterator

bool operator!= (const EgIterator& rhs);

// Move iterator to next printable edge

void operator++(int dummy); // post increment

// return edge at iterator location

std::tuple operator*();

private:

Graph *m_Gptr; // pointer to associated Graph

int m_indx; // index of current edge in m_nz

int m_row; // corresponding row of m_nz[m_indx]

};

// Make an initial edge Iterator

EgIterator egBegin();

// Make an end iterator for edge iterator

EgIterator egEnd();

// Neighbor Iterator inner class

class NbIterator {

public:

// Constructor for iterator for vertices adjacent to vertex v;

// indx can be used to set m_indx for begin and end iterators

NbIterator(Graph *Gptr = nullptr, int v = 0, int indx = 0)

// Compare iterators; only makes sense to compare with

// end iterator

bool operator!=(const NbIterator& rhs);

// Move iterator to next neighbor

void operator++(int dummy);

// Return neighbor at current iterator position

int operator*();

private:

Graph *m_Gptr; // pointer to the associated Graph

int m_row; // row (source) for which to find neighbors

int m_indx; // current index into m_nz of Graph

};

// Make an initial neighbor iterator

NbIterator nbBegin(int v);

// Make an end neighbor iterator

NbIterator nbEnd(int v);

private:

std::vector m_nz; // non-zero elements array

std::vector m_ci; // column index array

std::vector m_re; // row extent array

int m_numVert; // number of vertices

int m_numEdge; // number of edges

};

}

implement the methods of Grader. Most of the work is in implementing the required test functions:

Method Description of tests
testCSRExact() 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.
testCSRUnordered() Tests 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.
testNbIterator() Tests that the NbIterator produces the correct set of neighbors for every vertex in the graph.
testEgIterator() Tests that the EgIterator produces a valid listing of the edges of the graph. All edges must be included and none may be repeated.
testExceptions() Tests that an out_of_range exception is thrown for every operations specified to do so in the Project 1 description. Must check if some other exception is thrown, or no exception at all.

Each of these test functions can generate Error objects, defined in Grader.h. Each Error object consists of a point deduction, error id, and error description. Whenever an Error is produced, it is pushed onto a queue, a private variable of the Grader class. Somewhat counter-intuitively, there are error types that correspond to passing a test (i.e. no error); this allows success messages to be pushed into the error queue and printed at the end of the test program. The complete list of errors that the test functions can produce is described in errors.txt.

Grader has three methods in addition to the test functions:

Method Description of method
Grader(string name="") The Grader constructor; accepts an optional descriptive name for the object.
printAllErrors() Print all the errors in the error queue and the total point deductions; leaves the queue empty.
resetErrorQueue() Removes all entries from the error queue.

To test your implementation of Grader, you'll need a version of Graph.cpp from Project 1. Your own submission should be sufficient to get started. It is not difficult to modify your Project 1 code to produce specific errors. However, you will be provided with some sample Graph implementations with which to test your code after the final submission deadline for Project 1.

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!