Write a C++ a class definition for an abstract data type called Graph that models an undirected graph. Some implementation details: Create code for a .cpp file with main function and code for a .h file with classes  • Loops are allowed but multiple edges are not allowed. • Vertices are labeled by number from 0 to n-1 where n is the number of vertices in the graph. Implement the following public member functions. • A constructor that creates an empty graph. • An appropriate destructor. • void load(char *filename): Creates the graph using the file passed into the function. The format of the file is described later. You may assume load is only called once for a graph.  • void display(): Displays the graph's adjacency matrix to the screen. • void displayDFS(int vertex): Displays the result of a depth first search starting at the provided vertex. When you have a choice between selecting two vertices, pick the vertex with the lower number. • void displayBFS(int vertex): Displays the result of a breadth first search starting at the provided vertex. When you have a choice between selecting two vertices, pick the vertex with the lower number. You are permitted to add extra member functions you feel are helpful. DFS must be implemented using recursion. You can use “queue” in STL in the implementation of BFS. Other forms of using STL are not permitted. Input File Format The function load is responsible for reading in a file corresponding to a graph. The format is as follows: • The first line contains a single integer indicating how many vertices are present in the graph. You may make no assumptions on how many vertices in the graph – this means that your constructor will have to use dynamic allocation. • All remaining lines contain two integers that indicate an edge connects the two vertices. • You can assume that the file exists and is well formed.     Test Driver Program   TEST THE PROGRAM WITH A FILE THAT CONTAINS THE SAME INPUT AS THE IMAGE I ATTACHED NAME OF FILE: graph0.txt and/or graph2.txt you  The program must accept the name of an input file as a command line argument. Create a main function that does the following: 1. Create an empty graph. 2. Loads the graph using the specified input file. 3. Display the adjacency matrix. 4. Display a depth first search starting at vertex 0. 5. Display a breadth first search starting at vertex 0.   Program Output Here is the output you should get with file containing same as image attached for graph0.txt: Adjacency Matrix 0 0 1 1 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 DFS at vertex 0: 0 2 1 3 5 4 6 BFS at vertex 0: 0 2 3 1 5 6 4   Here is the output you should get with file containing same as image attached for graph2.txt: Adjacency Matrix 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 DFS at vertex 0: 0 1 2 5 4 3 6 7 8 BFS at vertex 0: 0 1 3 2 4 6 5 7 8

Enhanced Discovering Computers 2017 (Shelly Cashman Series) (MindTap Course List)
1st Edition
ISBN:9781305657458
Author:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Chapter2: Connecting And Communicating Online: The Internet, Websites, And Media
Section: Chapter Questions
Problem 20CT
icon
Related questions
Question
Write a C++ a class definition for an abstract data type called Graph that models an
undirected graph. Some implementation details:
Create code for a .cpp file with main function and code for a .h file with classes 
• Loops are allowed but multiple edges are not allowed.
• Vertices are labeled by number from 0 to n-1 where n is the number of vertices in the
graph.
Implement the following public member functions.
• A constructor that creates an empty graph.
• An appropriate destructor.
• void load(char *filename): Creates the graph using the file passed into the
function. The format of the file is described later. You may assume load is only called
once for a graph. 
• void display(): Displays the graph's adjacency matrix to the screen.
• void displayDFS(int vertex): Displays the result of a depth first search
starting at the provided vertex. When you have a choice between selecting two vertices,
pick the vertex with the lower number.
• void displayBFS(int vertex): Displays the result of a breadth first search
starting at the provided vertex. When you have a choice between selecting two vertices,
pick the vertex with the lower number.
You are permitted to add extra member functions you feel are helpful. DFS must be
implemented using recursion. You can use “queue” in STL in the implementation of BFS.
Other forms of using STL are not permitted.

Input File Format
The function load is responsible for reading in a file corresponding to a graph. The format is as
follows:
• The first line contains a single integer indicating how many vertices are present in the
graph. You may make no assumptions on how many vertices in the graph – this means
that your constructor will have to use dynamic allocation.
• All remaining lines contain two integers that indicate an edge connects the two vertices.
• You can assume that the file exists and is well formed.
 
 
Test Driver Program
 
TEST THE PROGRAM WITH A FILE THAT CONTAINS THE SAME INPUT AS THE IMAGE I ATTACHED NAME OF FILE: graph0.txt and/or graph2.txt you 

The program must accept the name of an input file as a command line argument. Create a main
function that does the following:
1. Create an empty graph.
2. Loads the graph using the specified input file.
3. Display the adjacency matrix.
4. Display a depth first search starting at vertex 0.
5. Display a breadth first search starting at vertex 0.
 
Program Output
Here is the output you should get with file containing same as image attached for graph0.txt:

Adjacency Matrix
0 0 1 1 0 0 0
0 0 1 1 1 0 0
1 1 0 0 0 1 0
1 1 0 0 0 1 1
0 1 0 0 0 1 1
0 0 1 1 1 0 0
0 0 0 1 1 0 0
DFS at vertex 0: 0 2 1 3 5 4 6
BFS at vertex 0: 0 2 3 1 5 6 4
 
Here is the output you should get with file containing same as image attached for graph2.txt:
Adjacency Matrix
0 1 0 1 0 0 0 0 0
1 0 1 1 1 0 0 0 0
0 1 0 0 0 1 0 0 0
1 1 0 0 1 0 1 0 0
0 1 0 1 0 1 0 1 0
0 0 1 0 1 0 0 1 1
0 0 0 1 0 0 0 1 0
0 0 0 0 1 1 1 0 1
0 0 0 0 0 1 0 1 0
DFS at vertex 0: 0 1 2 5 4 3 6 7 8
BFS at vertex 0: 0 1 3 2 4 6 5 7 8
9
01
12
34
45
67
78
03
36
14
47
25
58
1 3
57
graph2.txt
Transcribed Image Text:9 01 12 34 45 67 78 03 36 14 47 25 58 1 3 57 graph2.txt
7
02
03
12
1 3
14
25
35
36
45
46
graph0.txt
Transcribed Image Text:7 02 03 12 1 3 14 25 35 36 45 46 graph0.txt
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning