-
大小: 3.93MB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-10-29
- 語(yǔ)言: 其他
- 標(biāo)簽: 管理系統(tǒng)??景區(qū)??
資源簡(jiǎn)介
開(kāi)發(fā)景區(qū)管理系統(tǒng),對(duì)景區(qū)進(jìn)行管理。使用圖的數(shù)據(jù)結(jié)構(gòu)來(lái)保存景區(qū)景點(diǎn)信息,為用戶提供
創(chuàng)建圖、查詢景點(diǎn)信息、景點(diǎn)導(dǎo)航、搜索最短路徑、鋪設(shè)電路規(guī)劃等功能(共三次實(shí)驗(yàn))。
景點(diǎn)數(shù)據(jù):景點(diǎn)信息(附件中的Vex.txt)、道路信息(附件中的Edge.txt)

代碼片段和文件信息
#include?
#include?
#include?
#include?“Stack.h“
#include?“Graph.h“
//using?namespace?std;
void?cleanStr(char?string[]);
Graph::Graph()?{
int?i?j;
for?(i?=?0;?i?20;?i++)?{
for?(j?=?0;?j?20;?j++)?{
m_aAdjMatrix[i][j]?=?-1;
}
}
m_nVexNum?=?0;
}
//初始化圖
bool?Graph::InitGraph(char?VexFileName[]?char?EdgeFileName[])?{
ifstream?vexFile(VexFileName);
ifstream?edgeFile(EdgeFileName);
char?string[256]?=?{?0?};
Vex??tempVex;
Edge?tempEdge;
int?vexNum?=?0;
if?(!vexFile.is_open()?||?!edgeFile.is_open())?{
return?false; //文件打開(kāi)失敗
}
cleanGraph(); //建圖前清零,以免重復(fù)創(chuàng)建時(shí)出錯(cuò)
vexFile.getline(string?256);
vexNum?=?str2int(string);
for?(int?i?=?0;?i? cleanStr(string);
vexFile.getline(string?256);
tempVex.num?=?str2int(string);
vexFile.getline(tempVex.name?20);
vexFile.getline(tempVex.desc?1024);
if?(!InsertVex(tempVex))?return?false; //頂點(diǎn)插入失敗
}
cleanStr(string);
while?(!edgeFile.eof())?{
edgeFile?>>?tempEdge.vex1?>>?tempEdge.vex2?>>?tempEdge.weight;
if(!InsertEdge(tempEdge))?return?false; //插入邊失敗
}
vexFile.close();
edgeFile.close();
return?true;
}
//插入頂點(diǎn)
bool?Graph::InsertVex(Vex?sVex)?{
if?(m_nVexNum?20)?{
m_aVexs[m_nVexNum++]?=?sVex; //插入頂點(diǎn)到數(shù)組中
return?true;
}
else?{
return?false; //頂點(diǎn)已滿
}
}
//插入邊
bool?Graph::InsertEdge(Edge?sedge)?{
if?(sedge.vex1?0?||?sedge.vex1?>=?20?||?sedge.vex2?0?||?sedge.vex2?>=?20)?{
return?false; //頂點(diǎn)的編號(hào)越界了
}
else?{
m_aAdjMatrix[sedge.vex1][sedge.vex2]?=?sedge.weight;
m_aAdjMatrix[sedge.vex2][sedge.vex1]?=?sedge.weight;
return?true;
}
}
//獲取頂點(diǎn)
Vex?Graph::GetVex(int?nVex)?{
return?m_aVexs[nVex];
}
//找與指定頂點(diǎn)相連的邊
bool?Graph::FindEdge(int?nVex?int?aEdge[])?{
int?i;
if?(nVex?>?-1?&&?nVex?20)?{
for?(i?=?0;?i? aEdge[i]?=?m_aAdjMatrix[nVex][i];
}
return?true;
}
else?{
return?false; //頂點(diǎn)編號(hào)不對(duì)
}
}
//獲取頂點(diǎn)數(shù)
int?Graph::GetVexNum(void)?{
return?m_nVexNum;
}
//將圖清零
void?Graph::cleanGraph(void)?{
int?i?j;
for?(i?=?0;?i?20;?i++)?{
for?(j?=?0;?j?20;?j++)?{
m_aAdjMatrix[i][j]?=?-1;
}
}
m_nVexNum?=?0;
}
struct?De?{
int?vex;
int?i;
De()?{?vex?=?-1;?i?=?0;?}
};
//獲取所有路徑,用鏈表返回
Path?*Graph::DFSAll(int?v)?{
bool?isVisited[20]?=?{?false?}flag=true;
Path?*pathList=new?Path;
Path?*tempPath?=?NULL*pTail=pathList;
int?i?n=0;
Stack?stack;
De?tempDe;
if?(v?0?||?v?>=?m_nVexNum)?return?NULL; //輸入的頂點(diǎn)超過(guò)邊界
tempDe.vex?=?v;
tempDe.i?=?0;
tempPath?=?new?Path;
tempPath->vexs[n++]?=?v;
tempPath->next?=?NULL;
isVisited[v]?=?true;
while(true)?{
for?(i?=?tempDe.i;?i? if?(m_aAdjMatrix[tempDe.vex][i]?>?0?&&?!isVisited[i])?{
isVisited[i]?=?true;
tempDe.i?=?i+1;
stack.push(tempDe);
tempDe.vex?=?i;
tempPath->vexs[n++]?=?i;
i?=?-1; //f
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????3922??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\cl.command.1.tlog
?????文件??????57524??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\CL.read.1.tlog
?????文件???????4220??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\CL.write.1.tlog
?????文件?????????91??2017-04-28?15:12??實(shí)驗(yàn)2-4\GraphCPro\Debug\Edge.txt
?????文件?????204336??2017-05-16?14:05??實(shí)驗(yàn)2-4\GraphCPro\Debug\Graph.obj
?????文件??????94208??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.exe
?????文件????????406??2017-05-09?15:24??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.exe.em
?????文件????????472??2017-05-09?15:26??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.exe.em
?????文件????????381??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.exe.intermediate.manifest
?????文件????1007180??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.ilk
?????文件?????????86??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.lastbuildstate
?????文件???????2320??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.log
?????文件????1068032??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.pdb
?????文件???????1449??2017-05-09?15:21??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.vcxprojResolveAssemblyReference.cache
?????文件??????????0??2017-05-09?15:24??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro.write.1.tlog
?????文件????????208??2017-05-09?15:24??實(shí)驗(yàn)2-4\GraphCPro\Debug\GraphCPro_manifest.rc
?????文件??????????2??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件??????????2??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件??????????2??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件??????????2??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件??????????2??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件??????????2??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件???????3698??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件???????7562??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件???????2098??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\li
?????文件??????46218??2017-05-16?14:02??實(shí)驗(yàn)2-4\GraphCPro\Debug\Main.obj
?????文件????????790??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\mt.command.1.tlog
?????文件????????650??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\mt.read.1.tlog
?????文件????????326??2017-05-16?14:10??實(shí)驗(yàn)2-4\GraphCPro\Debug\mt.write.1.tlog
?????文件???????1094??2017-05-09?15:26??實(shí)驗(yàn)2-4\GraphCPro\Debug\rc.command.1.tlog
............此處省略30個(gè)文件信息
- 上一篇:darwin.iso 8.5.8
- 下一篇:基本Qt的一筆畫小游戲
評(píng)論
共有 條評(píng)論