Ever heard of the game Six Degrees of Kevin Bacon? (Play the game online; it's fun and counts as serious academic work.) Your program will play the game, too: it will accept queries in the form of the names of two actors, and then it will output (1) the "costar distance" and (2) a shortest path to get from the first actor to the second.
Your program can run in two modes:
The starter code includes ADTs for several auxiliary data structures: Queue, Stack, and Linked List.
The Six Degrees program relies on an undirected, unweighted graph whose vertices are Actor objects and edges are strings. Every actor from the input file actors.txt becomes a vertex of the graph. If two actors have appeared in a movie together, they are connected by an edge whose value is the name of the movie.
A snapshot of the undirected, unweighted graph that connects actors and movies. see image.
There is an edge between two actors if they've been in a movie together. If the actors have appeared in multiple movies together, only one edge exists, and it doesnt matter which movie is represented on the edge.
Make all adjustments you need to the existing starter code for this to work with our setup.
You'll also need to write the following Graph functions:
And modify the Graph function report_path.
You can add or modify any other functions or attributes to the Graph class that you need. Any functions that do not modify attributes of the class should be const.
You'll also write a simple Actor class. It has two attributes:
Write the following member functions for the Actor class:
Overload the following operators:
You can add any other functions or attributes to the Actor class that you need. Any functions that do not modify attributes of the class should be const. If your Actor class uses dynamic memory allocation, then also include a copy constructor, assignment operator, and destructor.
This class is responsible for the Graph itself, and for interacting with the user. It should have a Graph of Actor objects as its only attribute.
The Graph's default constructor doesnt do much, so youll need to have the SixDegrees class call the initialize_graph() function before it begins populating vertices and edges.
You'll need to write the following functions:
The input file actors.txt has the following format:
Actor name
Movie
Movie
Movie
*
Actor name
Movie
Movie
*
You do not know in advance how many movies a given actor has appeared in. Instead, use the delimiter '*' to distinguish between one actor and the next. Youll want to use getline for reading from this file, because actors and movies have varying-length names.
If the user runs in interactive mode, i.e., they provide no command-line arguments other than the name of the executable, then the names of two actors to look for comes via stdin:
Enter two actor names separated by a new line.
Press ctrl-D to quit
John Goodman
Meryl Streep
John Goodman and Meryl Streep have a costar distance of 4
John Goodman was in The Big Lebowski with Sam Elliott
Sam Elliott was in Ghost Rider with Wes Bentley
Wes Bentley was in The Hunger Games with Stanley Tucci
Stanley Tucci was in Julie & Julia with Meryl Streep
If the user provides one command-line argument in addition to the name of the executable, then that is an input file of queries. Your program should still print its results to standard out. We've provided one such file, test_input.txt. It contains several pairs of actors, which are consumed by the run function in SixDegrees.cpp.
When you run your program against this input file, you can redirect the output from standard out to your own output file, like this:
./sixdegrees test_input.txt > myoutput.txt
The output file here might match our expected_output.txt file that was included in the starter code. But remember -- that file is only one possible output sequence. It's most important that the "costar distances" in your output and our output are the same. If the actual sequence of movies varies, thats totally OK as long as its valid.
We've provided a simple driver that creates an instance of the SixDegrees class and calls its run function with cin and cout as arguments. For this assignment, well ask you to modify the provided driver to accept 0 or 1 command line arguments in addition to the name of the executable.
As part of your grade for this assignment, you'll write and submit unit tests for the Graph class. Since the Graph data structure is templated, you can test your Graph with ints, chars, Actors, or strings.
The most challenging functions, and thus the most important to test, are (1) populating the graph from the input file, and (2) Breadth-First Search. You should test both of these with really, really small input files before you use actors.txt.
Write your own testing main called test-graph.cpp that tests each function and writes reasonable output about success or failure of tests to standard out. Look at the linked handout on testing for inspiration! As an example, consider the bfs function. To make sure this function works, you'll want to test its behavior if:
Make sure to think carefully about the expected behavior for each test case!
Another important function to test is the copy constructor (and assignment operator). It should work on an empty Graph, a Graph with some vertices, a Graph with a lot of edges, etc.
Your Makefile should be set up so that make graphtest compiles your Graph with your Graph tests to produce an executable called graphtest.