CSC161 Homework 9: Graph parser
Contents
Requirements
For this homework, you need to write a program to read in a graph from a file and then print out the adjacency matrix. The file will have the following format: the first line contains the number of vertices in the graph. Each line there represents an edge between two vertices; these are listed as two columns, where each column is the index of a vertex. Here's an example for a graph with four vertices and an edge between vertices 0 and 2, 1 and 3, and 2 and 3:
4 0 2 1 3 2 3
The program should work with any graph file in that format. Here is an example of what the completed program should look like when run:
$ ./hw9 Enter a graph file: graph.txt 0 1 2 3 0 0 0 1 0 1 0 0 0 1 2 1 0 0 1 3 0 1 1 0
Take a look at the CSC 160 page on file I/O for some pointers on reading from a file.
(Back to top)Checklist
- the code and runs compiles (3 points)
- the graph is read into an adjacency matrix correctly (2 points)
- the graph is printed out correctly (2 points)
- the code is well documented (1 point)
- the file has the header (see the style guidelines), including who you've collaborated with (1 point)
- all code follows the style guidelines (1 point)
Extra credit
Extra credit will be capped at 5 points.
EC-1 (2 points)
Turn your assignment in a day early—by Sunday night at 11:59pm.
EC-2 (2 points)
Implement an adjacency list instead of a matrix (using the STL list).
EC-3 (2 points)
Implement an adjacency list using an array of STL sets.
(Back to top)Submissions
Everything should be uploaded to Canvas by the deadline posted.
(Back to top)