Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

1. Create a class Vertex and Edge to represent the vertices and edges of a graph. Provide text code of your

classes. (0 Marks, compulsory implementation)

2. 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

Explain the Alchian-Demsetz theory of the firm.

Answered: 1 week ago