Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! Please answer Problem 2, and include any necessary classes from the previous question if they are needed. Thank you! Problem statement A Graph is

image text in transcribed

Hello! Please answer Problem 2, and include any necessary classes from the previous question if they are needed.

Thank you!

Problem statement 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 (int) and value (int) as its basic attributes. Each edge has a weight (int), 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 displays the path that contains the verte:x virtual void display (Vertex& v) const0: 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 displays the path that contains the edgo virtual void display (Edge&const D An undirected graph is a graph where the edges are bidirectional displays the whole graph with your own defined format virtual void display const 0 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. converts the whole graph to a string such as 1-2-4-5: 1-3-5 each path // ?8 8eparated by virtual string testring (? eenat- class Graph public /renove all the vertices and edges virtual bool olean-0 l: Graph virtualGraph) //adds one vertex ; returns bool ?f added successfully virtual bool addvertexiVertex& v):0; Problem l: (65 marks) 1. Create the classes Vertex and Edge to represent the vertices and edges of a graph. Test the classes (0 /Bonus question: adda in a set of vertices: returns boo i added successfully /virtual bool addVertices (Vertex vArray)- 2. Create a concrete derived class of Graph. The class can represent a directed graph, undirected grpah, or DAG, Provide full code of the derived class. Test the classes (5 13 65 Marks) renoves a vertex: the edges that have connection with this vertex need to //be removed virtual bool renov?vertex 1 Vertex & v, 0; Problem 2: Operator Overloading (5*7-35 marks) Improve the class created in Problem 1 by overloading the operators+t, ,+. These operators are defined as follows /adds an edge: returns true if the edge is added successfully virtual bol adEdge (Rdne e) -0 /Bonus question: removes a set of edges: as a result, some nades may remain //as orphan /virtual bool addRdges (Edge eArray) 1. G1-G2, retuns true if G1 and G2 have the exact same vertices and edges 2. G1 G2, assigns Graph G2 to Graph G1: 3. G+ and ++G, increases the weights of all edges by one 4. G3 G+G2, returns a graph that contains all the nodes of Gl and G2, all the edges of Gl remove the edge virtual bool remove (Edge-0 and G2: 5. G G2, returns boolean if the sum of weights of Gl's edges is greater than the sum of returna bool if a vertex exists in a graph virtual bool searchVertex Iconat Vertox& v) weights of G2's edges 6. G outputs the graph G. xeturns boo1 if an Edge exists in a geaph virtual bool searchEdge (oonst Edge& e)0 Deliverable of Problem 1 and Problem 2 together should be in one project and packed as one zip file. You also need to provide tests by creating graphs and testing the member functions of the graph. Problem statement 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 (int) and value (int) as its basic attributes. Each edge has a weight (int), 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 displays the path that contains the verte:x virtual void display (Vertex& v) const0: 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 displays the path that contains the edgo virtual void display (Edge&const D An undirected graph is a graph where the edges are bidirectional displays the whole graph with your own defined format virtual void display const 0 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. converts the whole graph to a string such as 1-2-4-5: 1-3-5 each path // ?8 8eparated by virtual string testring (? eenat- class Graph public /renove all the vertices and edges virtual bool olean-0 l: Graph virtualGraph) //adds one vertex ; returns bool ?f added successfully virtual bool addvertexiVertex& v):0; Problem l: (65 marks) 1. Create the classes Vertex and Edge to represent the vertices and edges of a graph. Test the classes (0 /Bonus question: adda in a set of vertices: returns boo i added successfully /virtual bool addVertices (Vertex vArray)- 2. Create a concrete derived class of Graph. The class can represent a directed graph, undirected grpah, or DAG, Provide full code of the derived class. Test the classes (5 13 65 Marks) renoves a vertex: the edges that have connection with this vertex need to //be removed virtual bool renov?vertex 1 Vertex & v, 0; Problem 2: Operator Overloading (5*7-35 marks) Improve the class created in Problem 1 by overloading the operators+t, ,+. These operators are defined as follows /adds an edge: returns true if the edge is added successfully virtual bol adEdge (Rdne e) -0 /Bonus question: removes a set of edges: as a result, some nades may remain //as orphan /virtual bool addRdges (Edge eArray) 1. G1-G2, retuns true if G1 and G2 have the exact same vertices and edges 2. G1 G2, assigns Graph G2 to Graph G1: 3. G+ and ++G, increases the weights of all edges by one 4. G3 G+G2, returns a graph that contains all the nodes of Gl and G2, all the edges of Gl remove the edge virtual bool remove (Edge-0 and G2: 5. G G2, returns boolean if the sum of weights of Gl's edges is greater than the sum of returna bool if a vertex exists in a graph virtual bool searchVertex Iconat Vertox& v) weights of G2's edges 6. G outputs the graph G. xeturns boo1 if an Edge exists in a geaph virtual bool searchEdge (oonst Edge& e)0 Deliverable of Problem 1 and Problem 2 together should be in one project and packed as one zip file. You also need to provide tests by creating graphs and testing the member functions of the graph

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions