www.pudn.com > XiaoYuanDaoYouTu.rar > main.cpp


#include  
#include  
#include "Graph.h" 
#include "Graphm.h" 
#include  
 
char getView(int number); 
void Floyd(Graph& G,int **D,int proV,int nextV); 
void DFS(Graph& G, int V); 
void Prim(Graph& G, int s); 
void AddEdgetoMST(int i,int j,Edge *MST,int tag); 
void Menu(); 
 
 
 
void main() 
{ 
	int isDirected;                        //标记是否有向图 
	int numVertex;                         //图的顶点个数(边数将在setEdge中被自动修改) 
	int from,to,weight;                    //读入每条边的起点,终点和权 
	ifstream GraphSou;					   //输入文件流  
	 
	/*--------从imformation里读取该图(构造阶段)-------*/ 
	 
	GraphSou.open("imformation.txt");        //从文件里读取该公园的路线图 
	GraphSou >> isDirected;                  //从文件读取判断是否有向 
	if( isDirected!=1 && isDirected != 0 ) 
	{ 
		cout << "没有找到您要的导游图!" << endl; 
		return; 
	} 
	GraphSou >> numVertex;                   //从文件读取顶点个数 
	Graph *myGraph = new Graphm(numVertex);  
	 
	while(!GraphSou.eof())                 //顺次读取边的信息 
	{ 
		GraphSou >> from >> to >> weight; 
		if( from>=0 && to>=0 && weight>0 && fromsetEdge(from,to,weight); 
			if(!isDirected) 
			{ 
				myGraph->setEdge(to,from,weight); 
			} 
		} 
		else 
		{ 
			cout << "导游图文件库出错!" << endl; 
			return; 
		}		 
	} 
	 
	/*--------构造菜单选项---------*/ 
	 
	while(true)	 
	{ 
		cout<> Flog; 
		switch(Flog) 
		{ 
		case 1: 
			{ 
				system("cls"); 
				_sleep(500); 
				 
				char introduction[3000]; 
				ifstream in("introdoction.txt"); 
				while (!in.eof()) 
				{ 
					in >> introduction; 
					cout << "               "<< introduction << endl; 
				} 
				 
				// 选择提示 
				char answer1; 
				cout << "是否想继续相关操作(Y/N)" << endl; 
				cin >> answer1; 
				if (answer1 == 'Y' || answer1 == 'y') 
				{ 
					system("cls"); 
					_sleep(500); 
				} 
				else 
				{ 
					cout << "        谢谢您的光临,欢迎下次再来!" << endl; 
					exit(1); 
				} 
			} 
			break; 
		case 2: 
			{ 
				system("cls"); 
				cout<VerticesNum(); i++) 
				{ 
					for( Edge e = myGraph->FirstEdge(i); myGraph->IsEdge(e); e = myGraph->NextEdge(e) ) 
					{ 
						cout << "起始点:"; 
						getView(e.m_nFrom); 
						cout << "      " ; 
						cout << "目的地:"; 
						getView(e.m_nTo);  
						cout << "      " ; 
						cout << "路径长度:" << e.m_nWeight; 
						cout << "    " ; 
						cout << endl; 
					} 
					cout << endl; 
				} 
				Menu(); 
				cout << endl; 
				// 选择提示 
				char answer2; 
				cout << "是否想继续相关操作(Y/n)" << endl; 
				cin >> answer2; 
				if (answer2 == 'Y' || answer2 == 'y') 
				{ 
					system("cls"); 
					_sleep(500); 
				} 
				else 
				{ 
					cout << "         谢谢您的光临,欢迎下次再来!" << endl; 
					exit(1); 
				} 
			} 
			break; 
		case 3: 
			{ 
				int **DforFloyd=(int **)new int*[myGraph->VerticesNum()]; 
				for(int i=0; iVerticesNum(); i++) 
				{ 
					DforFloyd[i]=new int[myGraph->VerticesNum()]; 
				} 
				system("cls"); 
				_sleep(500); 
				//调用地图 
Start:			Menu(); 
				cout << endl; 
				cout << endl; 
				cout << "      0.正门  1.图书馆  2.综合教学楼  3.太阳鸟报告厅" << endl; 
				cout << "      4.二号教学楼  5.运动场  6.食堂  7.学生宿舍楼群" << endl; 
				int h,k; 
				cout << "请你选择起始景点(菜单中的数字):"; 
				cin >> h; 
				cout << endl; 
				cout << "你选择的是:"; 
				getView(h); 
				cout << endl; 
				cout << endl; 
				cout << "请你选择想要去的景点(菜单中的数字):"; 
				cin >> k; 
				cout << endl; 
				cout << "你选择的是:"; 
				getView(k); 
				cout << endl; 
				if ((h<0 || h>7) || (k<0 || k>7)) 
				{ 
					cout << "你输入的景点有误!请重新输入!" << endl; 
					goto Start; 
				} 
				 
				Floyd(*myGraph,DforFloyd,h,k); 
				cout << endl; 
				 
				// 选择提示 
				char answer3; 
				cout << "是否想继续相关操作(Y/n)" << endl; 
				cin >> answer3; 
				if (answer3 == 'Y' || answer3 == 'y') 
				{ 
					system("cls"); 
					_sleep(500); 
				} 
				else 
				{ 
					cout << "         谢谢您的光临,欢迎下次再来!" << endl; 
					exit(1); 
				} 
			} 
			break; 
		case 4: 
			{ 
				cout << "这是我们为您设计的游览路线,不一定是最理想的路线,可供您游览时参考!" << endl; 
				cout << endl; 
				DFS(*myGraph,0); 
				cout << endl; 
				 
				// 选择提示 
				char answer4; 
				cout << "是否想继续相关操作(Y/n)" << endl; 
				cin >> answer4; 
				if (answer4 == 'Y' || answer4 == 'y') 
				{ 
					system("cls"); 
					_sleep(500); 
				} 
				else 
				{ 
					cout << "         谢谢您的光临,欢迎下次再来!" << endl; 
					exit(1); 
				} 
			} 
			break; 
		case 5: 
			{ 
				system("cls"); 
				_sleep(500); 
				 
				Prim(*myGraph,0); 
				 
				 
				// 选择提示 
				char answer1; 
				cout << "是否想继续相关操作(Y/N)" << endl; 
				cin >> answer1; 
				if (answer1 == 'Y' || answer1 == 'y') 
				{ 
					system("cls"); 
					_sleep(500); 
				} 
				else 
				{ 
					cout << "         谢谢您的光临,欢迎下次再来!" << endl; 
					exit(1); 
				} 
			} 
			break; 
		case 6: 
			{ 
				system("cls"); 
				_sleep(500); 
				cout << "         谢谢您的光临,欢迎下次再来!" << endl; 
				exit(1); 
			} 
			break; 
		default : 
			{ 
				cout << "你输入的选项有误!" << endl; 
				 
				// 选择提示 
				char answer5; 
				cout << "是否想继续相关操作(Y/n)" << endl; 
				cin >> answer5; 
				if (answer5 == 'Y' || answer5 == 'y') 
				{ 
					system("cls"); 
					_sleep(500); 
				} 
				else 
					exit(1); 
			} 
			break; 
		} 
	} 
}