Hello,

I have to create a graph based program that will validate a zip code given an expression to match eg. ddddd - dddd, where d is a digit 0 - 9. I am new to graphs and don't know how to accomplish this. I'm trying to make graph class, and this is what I have so far using my textbook as a guide. Any help would be appreciated: Thank you.

class graph
{
public:
	bool isEmpty() const;
	void createGraph();
	void ClearGraph();
	void depthFirstTravesal();

	graph( int size = 0);
	~graphType();

protected:
	int maxSize;
	int gSize;

private:
	void dft(int v, bool visited[]);
};

void graph::createGraph()
{
	int index;
	string zip;
	int vertex;
	int adjacentVertex;

	if(gSize != 0)
		clearGraph();

	cout << "Enter Zip Code + 4: ";
	cin >> zip;
	cout << endl;

}
void graph::ClearGraph()
{
	int index;
	for (index = 0; index < gSize; index++)
		graph[index].destroyList();
}
graph::graph(int size)
{
	maxSize = size;
	gSize = 0;
}
graph::graph()
{
	clearGraph();
}
void graph:: depthFirstTravesal()
{
	 bool *visited;

	 visited = new bool[gSize];

	 int index;

	 for (index = 0; index < gSize; index++)
		 visited[index] = false;

	 for(index = 0; index < gSize; index++)
		 if(!visited[index])
			 dft(index, visited);
	 delete [] visited;
}
void graph::dft

//this should be a recursive function to implement the depth first traversal, but I am not sure hot to do that.

Your request is very vague. I actually still have no clue what you are asking for. If I had to guess, you require a bar graph that will display in percent a user entry vs. proper zip-code format. For example, if a user enters 48$43-0020, 8 out of 9 characters qualify as a correct zip code format, which is 89%. A resulting bar graph could look like this:

0 10 20 30 40 50 60 70 80 90 100
**********************************


If this even close to what you are asking for, no one knows except for you. Please, enlighten us; unlock the mystery that is your c++ problem.

Edited 6 Years Ago by Clinton Portis: n/a

I am supposed to ask the user for an Zip code. Then I have to check each digit from 0-9 if it is valid or not. But I have to do this using a graph. I don't think I have to actually make a graph just use the depth first traversal method to check each digit or something. For example go to the first digit check if it 0-9, then go to the next one and so on.

Edited 6 Years Ago by emko: n/a

This question has already been answered. Start a new discussion instead.