Question
Asked by:
trying2compile
trying2compile
Rating : No Rating
Questions Asked: 1
Tutorials Posted: 0
 

$25.00 C++ Graph Program

Q:
Write a program that reads and stores the names of persons and the names of job positions in the vertices of a graph. Two vertices will be connected if one of them represents a person and the other a job position for which that person is qualified. The program should allow the user to specify one of the following options:

* Insert (a) a new applicant or (b) a new job position into the graph.
* Delete (a) an applicant or (be a job position from the graph.
* List all persons qualified for a specified job position.
* List all job positions for which a specified person is qualified.

You will need to develop the following functions to make this work:

* Insert a new vertex, given a specification of all vertices adjacent to it.
* Search the graph for a vertex that stores a given data item and retrieve information about that item and/or update the information.
* Delete a vertex containing a given data item and all edges incident to it.
* Find all vertices adjacent to a given vertex.
 


   
   
   
   
 
Available Tutorials to this Question
Posted by:
rainman
rainman
Rating (40): A+
Questions Asked: 2
Tutorials Posted: 174, earned $906.64
 

$25.00 C++ Graph Tutorial, Menu Driven, Does Everything Asked, Compiled, Tested, Commented.

  • This tutorial was purchased 1 time and rated A+ by students like you.
  • Posted on Feb 27, 2009 at 5:31:19PM
A:
Preview: ... <br>using namespace std;<br><br>//Holds the name of a person or position<br>class Vertex<br>{<br> public:<br> Vertex(string n);<br> string getName();<br><br> private:<br> string name;<br>};<br><br>Vertex::Vertex(string n)<br>{<br> name = n;<br>}<br><br>string Vertex::getName()<br>{<br> return name;<br>}<br><br>//Connection between the person and the position<br>class Edge<br>{<br> public:<br> Edge(Vertex *a, Vertex* p);<br><br> Vertex* getApplicant();<br> Vertex* getPosition();<br><br> private:<br> Vertex* applicant;<br> Vertex* position;<br>};<br><br>Edge::Edge(Vertex *a, Vertex* p)<br>{<br> applicant = a;<br> position = p;<br>}<br><br>Vertex* Edge::getApplicant()<br>{<br> return applicant;<br>}<br><br>Vertex* Edge::getPosition()<br>{<br> return position;<br>}<br><br>class Graph<br>{<br> public:<br> Graph();<br> ~Graph();<br><br> void addVertex(string position);<br> void addVertex(string name, string qualified);<br> void remove(string name);<br><br> void clear();<br> void displayAll(); //For debugging<br><br> void displayApplicants(string job);<br> void displayJobs(string applicant);<br><br> private:<br> vector<Vertex*> vertices;<br> vector<Edge*> edges;<br><br> Vertex* getVertexByName(string name);<br><br>};<br><br>Graph::Graph() {}<br><br>Graph::~Graph()<br>{<br> clear();<br>}<br><br>void Graph::clear()<br>{<br> //This will delete any allocated memory stored in the vectors.<br><br> vector<Vertex*>::iterator vertIter;<br><br> for (vertIter = vertices.begin(); vertIter != vertices.end(); ++vertIter)<br> delete *vertIter;<br><br> vertices.clear();<br><br> vector<Edge*>::iterator edgeIter;<br><br> for (edgeIter = edges.begin(); edgeIter != edges.end(); ++edgeIter)<br> delete *edgeIter;<br><br> edges.clear();<br>}<br><br>//This is to add a job position vertex, if it is not already.<br>void Gra ...

The full tutorial is about 2476 words long plus attachments.

Attachments:
main.cpp (8K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty