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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education