Its a c ++ programming question
Question Description
Data Structures and Analysis of Algorithms, akk5
Objectives
•
To strengthen student’s knowledge of C++ programming
•
To give student experience reading and parsing strings of commands
•
To give
student experience using one or more STL’s in combination
•
To give student experience in writing Data Structures for data types
Instructions
For this assignment you must write a program that implements a
nd
manages
an
adjacency
list for a
weighted
directed graph
. Th
is program will be used
later in the semester to generate the adjacency
matrix files for the final
p
art of the project.
A full understanding of graphs is
n
’
t n
ecessary for this p
art of
the
project;
I will in
tr
oduce them briefly
while explaini
ng w
hat the progr
am does.
A graph is a collection of vertices and edges.
A vertex is singular poi
nt a graph and
often
stores
additional data; the data st
ored in
each vertex is unimpor
tant for this program
. An edge
connects two
ve
rtices and represents a relationship/path between th
e involved ve
rtices.
Different types of graphs
place varying restrict
ions on edges
;
we will be
using a graph that is both weight and
directed.
In a
weighted graph, every edge has
an associat
ed value called a w
eight. These weights
represent
the cost of
traversing
between the
edges it connects.
Edges in a directed
graph
are one
–
way; this directionality is
represented by specif
ying an initial and final vertex for each edge.
This is
probably best
seen
in the figure b
elow. The grap
h on the left is undirected
, the graph o
n the
right
is
directed.
Both graphs are weighted.
This is an individual assignment. Seeking direct
help from students, tutors, and websites
such as chegg or stack overflow will be construed as a violation of the honor code.
Besides
the
above
visual depictions
, each of the
se gr
aphs can be
re
presented
in a computer
using one of
several
formats.
T
wo of the more common representations ar
e the adjacency
list and the adjacency
mat
r
ix.
An adjacency list
is
a collection of
lists that are used to describ
e
a
graph. E
a
ch
list in the collection
de
sc
ribes the
neighbors for a given vertex in the graph
.
Vertices A and B are neigh
bors if they a
connected by an edge
; we modify the neighbor relationship in a directed graph
as follows:
B is a
neig
hbor of A if
an edge exists
with A as the initial vertex and B a
s the final vertex.
Each entry in ou
r
adjacency
list
shoul
d also s
tore the weight associated with the given edge.
A
n
adjacency
matrix is probably the most ubiquitous representation of graphs in all of computing and
mathem
atics. It is also on
e of
the
sim
ple
st
. An adjacency mat
rix
for a
n unweighted
graph with n vertices
is a
n
n x
n matrix constructed using the following rules:
I
f an ed
ge exists from edge
j
to edge
k
, then the
(
j
,
k
) cell of
the
matrix will contain a value of
1
If the
re is no
edge
from edge
j
to edge
k
, the
n
the
(
j
,
k
) cell of the ma
trix
will contain a value o
f 0
.
Th
ese rules of con
s
truction are modified when the graph is
w
eighted
:
if an edge exists from edge
j
to edge
k
, then the (
j
,
k
)
cell of the matrix will contain the
edge
’
s
weight instead of a 1.
The foll
owing figure contains a
simple
weighted directed graph
, its adjacency list,
and its adjacency
matrix.
The purpose o
f this program is to
describe a graph using an adjacency list and output the resulting graph
into
a f
ile
containing a list of vertices
involved and the
associated adjacency
matrix
.
As an e
xample
, the
user
would
i
nput the following commands to con
str
uct the above graph:
a
dd
0
a
dd
1
a
dd
2
a
dd
3
a
dd
0 to 3 weight 1
a
dd 1 to 0 weight 5
a
dd
1 to 2 weight 3
a
dd
2 to 3 weight
8
a
dd 3 to 0 weight 3
a
dd 3 to 1 w
eight 2
This is an individual assignment. Seeking direct
help from students, tutors, and websites
such as chegg or stack overflow will be construed as a violation of the honor code.
Your
program should
implement a command line (text
–
based interface) capable of handling the
following commands
:
e
xit
–
exits the program
output
<file>
–
saves
the
adjacency list currently stored in memory
to the specified file
as a
vertex list and an adjacency matrix
load
<file>
–
parses the contents of the file as if they were entered from the command line
d
isplay
list
–
displays the
current adjacency list
display vertices
–
displays the current vertex list
display matrix
–
displays the current adjacency matrix
f
ind
<
initial
>
to
<final>
–
finds the
edge with from the specified initial vertex to the specified
final vertex and displays its weight.
Should inform the user on a failure.
r
emove
<
vertex
>
–
Removes the specified
vertex and all edges to or from that vertex.
Shoud
inform the user on a failure.
r
emove
<
initial
>
to
<
final
>
–
removes the edge with the specified initial vertex and the specified
final vertex
.
Should inform the user on a failure.
add
<
initial
>
to
<
final
>
weight
<
weight
>
–
Add an edge with the
specified weight from the
specified initial vertex to the specified final vertex
. Should inform the user if the insert fails be
cause
either initial or final vertex doesn’t exist
.
add
<
vertex
>
–
Adds the specified vertex to the vertex list.
Should inform the user if
it
fails
because
vertex already exists
.
Guidance
Parsing text
is probably still
a frustrating part of any programming assignment
;
however,
it should be
much easier now that you have a
ttempted the task once. Use that knowledge and the example code
bases I have provided to make t
he parsing easier for this assignment.
What will be more challenging
is
the
open
nature of
the development and implementation portion of
this program.
I have purposely omitted details about how to model and implement the adjacency list
and its subse
quent conversion to a vertex list and adjacency matrix. But I will give you a few suggestions.
Yo
u
can
use an
y
combination
of the following STL’s for this project: vector, list, map
as well as code from
your previous
project to
model and implement the underlying adjacency list and perhaps the
accompanying ver
tex list.
I suggest you consider using one
of the following combinations: a list of list
s
, a vector of vectors,
a map
of maps, a list of vectors
,
a vector of lists, a map of
lists, a map of vectors, a vector of
maps, or a list of
maps.
This is an individual assignment. Seeking direct
help from students, tutors, and websites
such as chegg or stack overflow will be construed as a violation of the honor code.
Grading Breakdown
Point Breakdown
Structure
12 pts
The program has a header comment with the
required information.
3 pts
The overall readability of
the program.
3 pts
Program uses separate files for main and class
definitions
3 pts
Program includes meaningful comments
3 pts
Syntax
2
8
pts
Implements Class
AdjacencyList correctly
28
pts
Behavior
6
0
pts
Program
handles all command inputs properly
•
E
xit
the program
6
pts
•
D
isplay
the
vertex
list
correctly
6
pts
•
Display the adjacency lists correctly
6 pts
•
Display the adjacency matrix correctly
6 pts
•
Outputs the matrix to
file
6
pts
•
Find a
n
edge
in the list
6
pts
•
Remove a v
ertex
from the list
6
pts
•
Remove an edge from the list
6 pts
•
Add
a vertex to the list
6
pts
•
Add an edge to the list
6
pts
Total Possible Points
100pts
Penalties
Program does NOT compile
–
100
Late up to 24 hrs
–
30
Late more than 24hrs
–
100
This is an individual assignment. Seeking direct
help from students, tutors, and websites
such as chegg or stack overflow will be construed as a violation of the honor code.
Header Comment
At the top of each program, type in the following comment:
/*
Student Name: <student name>
Student NetID: <student NetID>
Compiler Used: <Visual Studio, GCC, etc.>
Program Description:
<Write a short
description of the program.>
*/
Example:
/*
Student Name: John Smith
Student NetID: jjjs123
Compiler Used: Eclipse using MinGW
Program Description:
This program prints lots and lots of strings!!
*/
Assignment Information
Due Date:
1/26/2020
Files
Expected:
1.
Main.cpp
–
File containing function main
2.
List
.h
–
File containing the
AdjacencyList
class
defin
i
tions
.
3.
List.cpp
–
File containing the code for the
Adjacency
List
methods.
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."