Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write the definition for the following functions in c++ format #ifndef GRAPH_H #define GRAPH_H #include #include struct vertex; struct adjVertex { vertex *v; int distance;

write the definition for the following functions in c++ format

#ifndef GRAPH_H #define GRAPH_H

#include #include

struct vertex;

struct adjVertex { vertex *v; int distance; };

//this is the struct for each vertex in the graph. struct vertex { int ID; std::string name; int district; bool visited; std::vector adj; //stores edges to adjacent vertices }; class Graph { public: /* class constructor Purpose: perform all operations necessary to instantiate a class object Parameters: none */ Graph(); /* class destructor Purpose: free all resources that the object has aquired Parameters: none */ ~Graph(); /* Method Name: addEdge Purpose: Creates an edge between two vertices (using an adjVertex struct) Param: v1 - vertex at one end of edge Param: v2 - vertex at opposite end of edge */ void addEdge(std::string v1, std::string v2, int distance); /* Method Name: addVertex Purpose: Creates a vertex Param: name - name of the vertex (city name) */ void addVertex(std::string name); /* Method Name: displayEdges Purpose: print all edges in graph (see writeup for format) Parameters: none */ void displayEdges(); /* Method Name: assignDistricts Purpose: Iterate through the vertices, perform BFT to find connected components, and assign to district Parameters: none */ void assignDistricts();

private: std::vector vertices; //stores vertices /* Method Name: findVertex Purpose: Find and return the vertex of the specified city Param: name - name of the city vertex to be returned returns pointer to a vertex */ vertex * findVertex(std::string name); /* Method Name: BFTraversalLabel Purpose: Call BFTraversalLabel from within assignDistricts to label the districts. This method should implement a breadth first traversal from the startingCity and assign all cities encountered the distID value Param: name - name of starting city for breadth first traversal */ void BFTravesalLabel(std::string startingCity, int distID); };

#endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Explain the difference between stare decisis and precedent.

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago