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
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
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Write a C++ a class definition for an abstract data type called Graph that models an
undirected graph. Some implementation details:
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.
• 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:
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
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
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 6 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY