Question: C++ Plz . Include the run result also A Graph is formally define as G=(N,E) consisting of the set N of vertices (or nodes) and

C++ Plz . Include the run result also A Graph

is formally define as G=(N,E) consisting of the set N of vertices (or nodes) and the set E of

edges, which are ordered pairs of the starting vertex and the ending vertex. Each vertex has ID and

value as its basic attributes. Each edge has weight, starting vertex and ending vertex.

A Graph can be a directed graph where vertices are connected by edges, and all the edges are directed

from one vertex to another.

A Directed Acyclic Graph (DAG) is a finite directed graph with directed cycles. This means from any

vertex v, there is no way to follow a sequence of edge that eventually loops back to v again.

An undirected graph is a graph where the edges are bidirectional.

The definition of the abstract class Graph is provided below. Note that all its member functions are pure

virtual. This is because the implementation of these functions is different from one graph to another. You

are allowed to slightly modify this class by adding new member functions.

class Graph{

public:

Graph();

virtual ~Graph();

//add in one vertex; bool returns if it is added successfully.

virtual bool addVertex(Vertex& v)=0;

//Bonus question: add in a set of vertices; bool retruns if it is

added successfully

//virtual bool addVertices(Vertex* vArray) = 0;

//the edges that has connection with this vertex need to be removed;

virtual bool removeVertex() = 0;

//remove a edge; as a result, some node may remain as orphan.

virtual bool addEdge(Edge& e) = 0;

//Bonus question : remove a set of edge; as a result, some node may

remain as orphan.

//virtual bool addEdges(Edge* eArray) = 0;

// remove the edge

virtual bool remove

// return bool if a vertex exists in a graph;

virtual bool searchVertex(const Vertex& v) = 0;

// return bool if a Edge exists in a graph;

virtual bool searchEdge(const Edge& e) =0;

// display the path that contains the vertex;

virtual void display(Vertex& v) const = 0;

// display the path that contains the edge;

virtual void display(Edge& e) const = 0;

// display the whole graph with your own defined format

virtual void display() const = 0;

// convert the whole graph to a string such as 1-2-4-5; 1-3-5; each

path is separated by ';'

// define your own format of a string representation of the graph.

virtual string toString () const = 0;

//remove all the vertices and edges;

virtual bool clean() = 0;

};

Problem 1: (65 marks)

Create a concrete derived class of Graph. It can be directed, undirected or DAG. Provide full code of the

derived class. Provide text code of your class. (5*13 = 65 Marks)

C++ Plz . Include the run result also

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!