Question: Please answer in c++. I need it asap . I want graphl.h, graphl.cpp this is sample main cpp. #include #include #include graphl.h using namespace std;

Please answer in c++. I need it asap . I want graphl.h, graphl.cpp

Please answer in c++. I need it asap . I want graphl.h,

this is sample main cpp.

#include  #include  #include "graphl.h" using namespace std; int main() { // part 2 ifstream infile2("data32.txt"); if (!infile2) { cout  

data32.txt

5 Aurora and 85th Green Lake Starbucks Woodland Park Zoo Troll under bridge PCC 1 2 1 3 1 5 2 4 3 2 3 4 5 2 5 4 0 0 3 aaa bbb ccc 1 2 1 3 2 3 3 2 0 0

buildgraph method

// Uses getline from string class, included in nodedata.h . // Be sure to include nodedata.h which includes  . void GraphL::buildGraph(istream& infile) { int fromNode, toNode; // from and to node ends of edge makeEmpty(); // include if dynamic memory anywhere infile >> size; // read the number of nodes if (infile.eof()) return; // stop reading if no more data // explanation to student: when you want to read a string after an int, // you must purge the rest of the int line or the end-of-line char will // be the string read string s; // used to read to end of line holding size getline(infile, s); // read graph node information for (int i=1; i > fromNode >> toNode; if (fromNode == 0 && toNode == 0) return; // end of edge data // insert a valid edge into the adjacency edge STL list for fromNode } } 

nodedata.h

#ifndef NODEDATA_H #define NODEDATA_H #include  #include  #include  using namespace std; // simple class containing one string to use for testing // not necessary to comment further class NodeData { friend ostream & operator(const NodeData &) const; bool operator=(const NodeData &) const; private: string data; }; #endif 

nodedata.cpp

#include "nodedata.h" //---------------------------------------------------------------------------- // constructors/destructor NodeData::NodeData() { data = ""; } // default NodeData::~NodeData() { } // needed so strings are deleted properly NodeData::NodeData(const NodeData& nd) { data = nd.data; } // copy NodeData::NodeData(const string& s) { data = s; } // cast string to NodeData //---------------------------------------------------------------------------- // operator= NodeData& NodeData::operator=(const NodeData& rhs) { if (this != &rhs) { data = rhs.data; } return *this; } //---------------------------------------------------------------------------- // operator==,!= bool NodeData::operator==(const NodeData& rhs) const { return data == rhs.data; } bool NodeData::operator!=(const NodeData& rhs) const { return data != rhs.data; } //---------------------------------------------------------------------------- // operator,= bool NodeData::operator(const NodeData& rhs) const { return data > rhs.data; } bool NodeData::operator=(const NodeData& rhs) const { return data >= rhs.data; } //---------------------------------------------------------------------------- // setData // returns true if the data is set, false when bad data, i.e., is eof bool NodeData::setData(istream& infile) { getline(infile, data); return !infile.eof(); // eof function is true when eof char is read } //---------------------------------------------------------------------------- // operator 

You must comment the classes. Include ADT description and assumptions / limitation and implementation description. See sample code for examples.

To line up numbers use setw() (must #include ). For example, if n is an int, 10 chars are printed including n. Default is right justified, padding with blanks on the left: cout Part 2, Programming Graph ADT (emphasis on depth-first search) Display the graph information and implement depth-first search (using the ordering as given by the data, i.e., start at one). Display the node numbers in depth-first order. Implement the specified graph ADT functions. In the data, the first line tells the number of nodes, say n (assume a nonnegative integer). Following is a text description of each of the 1 through n nodes, one description per line (max length of 50 characters). After that, each line consists of 2 ints representing an edge. (Assume int data.) For an edge from node 1 to node 2, the data is: 1 . A zero for the first integer signifies the end of the data for that one graph. All the edges for the first node will be together first, then all the edges for the second node, etc. Take them as they come, no sorting. (They appear sorted because the data is in order. Don't assume that happens.) There are many graphs, each having at most 100 nodes. As in part1, assume the input data file has correctly formatted data. You may assume the number of nodes is a valid int, but you must error check for valid ints for the rest. Ignore invalid data, meaning don't use in the graph. E.g., Part 2 Notes -- Implement using an adjacency list (array of lists). Add any needed data, e.g., a field in the graph node can be used to mark visiting a node (used in depthFirstSearch() ). The object with the information on a graph node can either be directly stored in GraphNode as a NodeData object or as a pointer to an object (NodData*). As with part 1, start in array element one. -- You do not need to implement a complete Graph class. Normally you would have a copy constructor, etc., but you don't need to implement all of them if you promise not to do that in real life. Implement the constructor, destructor, buildGraph(), displayGraph(), and depthFirstSearch(). A driver that (partially) tests your code is given. -- To simplify things, you should always insert edges (edge nodes) at the end of the adjacency list of edges for the graph node (see the example above). An edge list may not be sorted. (They are sorted in the example output for readability.) Make sure to follow this coding simplification (and process the edges in the order they are in the list,) since it affects the depth-first ordering that you will get. -- Note that you must handle a graph with disconnected components, e.g., add graph nodes 6 and7 to the above example with an edge between them, (6,7), with no other edges added. With these added nodes and edge, the DFS ordering is 1243567

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!