校园导游系统(C++实现,VC6.0编译,使用EasyX图形库)

Posted maxuewei2

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了校园导游系统(C++实现,VC6.0编译,使用EasyX图形库)相关的知识,希望对你有一定的参考价值。

//校园导游系统.cpp
1
#include <graphics.h> 2 #include <conio.h> 3 #include <stdio.h> 4 #include <io.h> 5 #include <stdlib.h> 6 #include <string> 7 #include <iostream> 8 #include <math.h> 9 #include <fstream> 10 #include "Stack.h" 11 #include "functions.h" 12 #include "Graph_List.h" 13 #define WIDTH (1000+(LEFTBORDER*2)) 14 #define HEIGHT (574+TOPBORDER+LEFTBORDER) 15 #define UP 72 16 #define DOWN 80 17 #define LEFT 75 18 #define RIGHT 77 19 #define BACKGROUND "background.jpg" 20 #define BKCOLOR RGB(240,240,240) //原RGB(240,240,240) 21 #define SELECTCOLOR RGB(255,0,0) //原RED 22 #define TEXTCOLOR RGB(7,102,198)//GREEN// //原BLUE 23 #define MENUCOLOR RGB(208,161,227)//RGB(77,197,131)//RGB(112,112,112)//RGB(117,75,144)//RGB(7,102,198) //原GREEN 24 #define CheckCancel if(iscancel){return -1;} 25 using namespace std; 26 Graph_List graph; 27 int choose; 28 int menunum = 11; 29 int menutop1 = 10; 30 int menutop = (menutop1 + 3); 31 #define left (LEFTBORDER) 32 int menuwidth = ((WIDTH - 2 * LEFTBORDER) / (menunum )); 33 int menuheight = 30; 34 int GetChoose(); 35 int FrontMenu(Graph_List &graph ); 36 int ShowAllVertex(Graph_List &graph); 37 int ShowAllPath(Graph_List &graph); 38 int printroad(int dx, int dy, int sx, int sy) { 39 LINESTYLE linestyle; 40 getlinestyle(&linestyle); 41 setlinestyle(PS_SOLID,3,NULL,0); 42 setlinecolor(BLUE); 43 line(sx,sy,dx,dy); 44 setlinestyle(&linestyle); 45 double x1 = (sx + dx) / 2; 46 double y1 = (sy + dy) / 2; 47 double x2 = ((3.0 / 8.0) * sx + (5.0 / 8.0) * dx); 48 double y2 = ((3.0 / 8.0) * sy + (5.0 / 8.0) * dy); 49 //double x1=sx,x2=(sx+dx)/2,y1=sy,y2=(sy+dy)/2; 50 double k1 = (y2 - y1) / (x2 - x1); 51 double k2 = (-1) / k1; 52 double delta = 1600; //=(y2-y1)*(y2-y1)+(x2-x1)*(x2-x1); 53 double a = sqrt((delta / 16) / (1 + k2 * k2)); 54 double b = a * fabs(k2); 55 if(((x1 > x2) && (y1 < y2)) || ((x1 < x2) && (y1 > y2))) { 56 } else { 57 b = -1 * b; 58 } 59 if(x1 == x2) { 60 a = 5; 61 b = 0; 62 } 63 if(y1 == y2) { 64 a = 0; 65 b = 3; 66 } 67 POINT pts[] = { {x1, y1}, {x2 + a, y2 + b}, {(x1 + x2) / 2, (y1 + y2) / 2}, }; 68 POINT pts1[] = { {x1, y1}, {x2 * 2 - (x2 + a), y2 * 2 - (y2 + b)}, {(x1 + x2) / 2, (y1 + y2) / 2}, }; 69 setfillcolor(BLUE); 70 solidpolygon(pts1, 3); 71 solidpolygon(pts, 3); 72 return 0; 73 } 74 int GetMouseXY(int& mousex,int& mousey) { 75 MOUSEMSG temp; 76 temp.mkLButton = false; 77 bool kick = false; 78 while(!kick) { 79 // if(MouseHit()) { 80 temp = GetMouseMsg(); 81 FlushMouseMsgBuffer(); 82 if(temp.mkLButton == false) { 83 mousex = temp.x; 84 mousey = temp.y; 85 } 86 else { 87 kick = temp.mkLButton ; 88 } 89 // } 90 } 91 return 0; 92 } 93 int AddVertex(Graph_List &graph) { 94 LOGFONT font; 95 gettextstyle(&font); 96 settextstyle(10, 0, _T("宋体")); 97 BeginBatchDraw(); 98 setlinecolor(GREEN); 99 for(int lx = LEFTBORDER; lx <= WIDTH; lx += 50) { 100 //outtextxy(lx, TOPBORDER - 10, &int_to_str(lx - LEFTBORDER)[0]); 101 line(lx, TOPBORDER, lx, HEIGHT - LEFTBORDER); 102 } 103 for(int ly = TOPBORDER; ly <= HEIGHT - LEFTBORDER; ly += 50) { 104 //outtextxy(10, ly - 5, &int_to_str(ly - TOPBORDER)[0]); 105 line(LEFTBORDER, ly, WIDTH - LEFTBORDER, ly); 106 } 107 FlushBatchDraw(); 108 setlinecolor(MENUCOLOR); 109 settextstyle(&font); 110 ::MessageBox(GetHWnd(), "请在您要添加景点的位置点击", "添加景点", MB_OK); 111 int mousex,mousey; 112 GetMouseXY(mousex,mousey); 113 char name[30]; 114 bool iscancel = false; 115 iscancel = !InputBox(&(name[0]), 30, "输入名称" , "添加景点", "0", 0, 0, 0); 116 CheckCancel 117 char describe[1000]; 118 iscancel = !InputBox(&(describe[0]), 1000, "输入简介:(按Ctrl+Enter确认输入)" , "添加景点", "0", 0, 10, 0); 119 CheckCancel 120 char mark[10]; 121 int marki; 122 while(1) { 123 iscancel = !InputBox(&(mark[0]), 10, "输入代号" , "添加景点", 0, 0, 0, 0); 124 CheckCancel 125 marki = str_to_num(mark); 126 if(marki > 0 && graph.GetIndex(marki) == -1) { 127 break; 128 } 129 ::MessageBox(GetHWnd(), "此代号已存在,请重输", "添加景点", MB_OK); 130 } 131 string namestr = "", describestr = ""; 132 graph.InsertVertex((string)(namestr + name), (string)(describestr + describe), marki, mousex, mousey); 133 ::MessageBox(GetHWnd(), "添加成功", "添加景点", MB_OK); 134 return 0; 135 } 136 int AddPath(Graph_List &graph) { 137 bool iscancel = false; 138 int v1, v2; 139 string source = "0000000000", destination = "0000000000", weightstr = "0000000000"; 140 while(1) { 141 iscancel = !InputBox(&(source[0]), 10, "输入起点代号" , "添加边", "0", 0, 0, 0); 142 CheckCancel 143 v1 = str_to_num(source); 144 if(graph.GetIndex(v1) != -1) { 145 break; 146 } 147 ::MessageBox(GetHWnd(), "该位置不存在,请重输", "添加边", MB_OK); 148 } 149 while(1) { 150 iscancel = !InputBox(&(destination[0]), 10, "输入终点代号", "添加边", "0", 0, 0, 0); 151 CheckCancel 152 v2 = str_to_num(destination); 153 if(graph.GetIndex(v2) != -1) { 154 break; 155 } 156 ::MessageBox(GetHWnd(), "该位置不存在,请重输", "添加边", MB_OK); 157 } 158 double dx = graph.GetHead()[graph.GetIndex(v2)].GetX(); 159 double sx = graph.GetHead()[graph.GetIndex(v1)].GetX(); 160 double dy = graph.GetHead()[graph.GetIndex(v2)].GetY(); 161 double sy = graph.GetHead()[graph.GetIndex(v1)].GetY(); 162 double weight = (double)sqrt(((dx - sx) * (dx - sx) + (dy - sy) * (dy - sy)) / 24250.0) * 300.0; 163 int retop=graph.InsertEdge(graph.GetIndex(v1), graph.GetIndex(v2), weight); 164 if(retop==-3){::MessageBox(GetHWnd(), "起点与终点相同!", "添加边", MB_OK);return -3;} 165 if(retop==-4){::MessageBox(GetHWnd(), "边已存在!", "添加边", MB_OK);return -4;} 166 ::MessageBox(GetHWnd(), "添加成功", "添加边", MB_OK); 167 return 0; 168 } 169 int DeleteVertex(Graph_List &graph){ 170 bool iscancel = false; 171 char v[10]; 172 int v1; 173 while(1) { 174 iscancel = !InputBox(&(v[0]), 10, "输入代号" , "删除景点", "0", 0, 0, 0); 175 CheckCancel 176 v1 = str_to_num(v); 177 178 if(graph.GetIndex(v1)!= -1) { 179 break; 180 } 181 ::MessageBox(GetHWnd(), "此代号不存在,请重输", "删除景点", MB_OK); 182 } 183 graph.DeleteVertex(graph.GetIndex(v1)); 184 return 0; 185 } 186 int DeletePath(Graph_List &graph) { 187 bool iscancel = false; 188 int v1, v2; 189 string source = "0000000000", destination = "0000000000"; 190 while(1) { 191 iscancel = !InputBox(&(source[0]), 10, "输入起点代号" , "删除边", "0", 0, 0, 0); 192 CheckCancel 193 v1 = str_to_num(source); 194 if(graph.GetIndex(v1) != -1) { 195 break; 196 } 197 ::MessageBox(GetHWnd(), "该位置不存在,请重输", "删除边", MB_OK); 198 } 199 while(1) { 200 iscancel = !InputBox(&(destination[0]), 10, "输入终点代号", "删除边", "0", 0, 0, 0); 201 CheckCancel 202 v2 = str_to_num(destination); 203 if(graph.GetIndex(v2) != -1) { 204 break; 205 } 206 ::MessageBox(GetHWnd(), "该位置不存在,请重输", "删除边", MB_OK); 207 } 208 int retop=graph.DeleteEdge(graph.GetIndex(v1), graph.GetIndex(v2)); 209 if(retop==-1){::MessageBox(GetHWnd(), "边不存在!", "删除边", MB_OK);return -1;} 210 211 ::MessageBox(GetHWnd(), "删除成功", "删除边", MB_OK); 212 return 0; 213 } 214 int DrawShortestPath(Graph_List &graph, int v1, int v2) { 215 Vertex *Head = graph.GetHead(); 216 217 int *path = new int [graph.NumberOfVertices()]; 218 graph.DShortestPath(v1, path); 219 LStack<int > stack; 220 //stack.Push(v2); 221 if(path[v2] == -1) { 222 ::MessageBox(GetHWnd(), "*** 无路径 ***", "查询路径", MB_OK); 223 return -1; 224 } 225 int i = v2; 226 while(i != path[v1]) { 227 stack.Push(i); 228 i = path[i]; 229 } 230 delete []path; 231 //stack.Push(v1); 232 int temp = v1, temppre = v1, length = 0; 233 string pathstr,tempstr; 234 BeginBatchDraw(); 235 while(!stack.IsEmpty()) { 236 stack.Pop(temp); 237 printroad(Head[temppre].GetX(), Head[temppre].GetY(), Head[temp].GetX(), Head[temp].GetY()); 238 int pathweight=graph.GetWeight(temppre, temp); 239 length += pathweight; 240 tempstr=tempstr+""+int_to_str(Head[temppre].GetMark())+""+int_to_str(Head[temp].GetMark())+" : "+int_to_str(pathweight)+""+"\n"; 241 temppre = temp; 242 } 243 244 FlushBatchDraw(); 245 setbkcolor(BKCOLOR); 246 settextcolor(TEXTCOLOR); 247 string str = "最短路径长度为:"; 248 str = str + int_to_str(length) + " 米\n"+"步行所需时间:"+int_to_str(length/90)+"分钟\n"; 249 str+=tempstr; 250 ::MessageBox(GetHWnd(), &str[0], "查询路径", MB_OK); 251 return 0; 252 } 253 int FindPath(Graph_List &graph) { 254 bool iscancel = false; 255 int v1, v2; 256 string source = "0000000000", destination = "0000000000"; 257 while(1) { 258 iscancel = !InputBox(&(source[0]), 10, "输入起点代号" , "查询路径", "0", 0, 0, 0); 259 CheckCancel 260 v1 = str_to_num(source); 261 if(graph.GetIndex(v1) != -1) { 262 break; 263 } 264 ::MessageBox(GetHWnd(), "该位置不存在,请重输", "查询路径", MB_OK); 265 } 266 while(1) { 267 iscancel = !InputBox(&(destination[0]), 10, "输入终点代号", "查询路径", "0", 0, 0, 0); 268 CheckCancel 269 v2 = str_to_num(destination); 270 if(graph.GetIndex(v2) != -1) { 271 break; 272 } 273 ::MessageBox(GetHWnd(), "该位置不存在,请重输", "查询路径", MB_OK); 274 } 275 DrawShortestPath(graph, graph.GetIndex(v1), graph.GetIndex(v2)); 276 return 0; 277 } 278 void ShowVertex(Graph_List &graph, int i) { 279 Vertex *Head = graph.GetHead(); 280 if(i < 0 || i > graph.NumberOfVertices() - 1) { 281 ::MessageBox(GetHWnd(), "查询位置不存在", "景点查询", MB_OK); //GetHWnd()获得窗口句柄 282 return ; 283 } 284 string str = "代号:" +int_to_str(Head[i].GetMark()) + "\n" + "简介: " + Head[i].GetDescribe(); 285 str = "名称:" + Head[i].GetVerName() + "\n" + str; 286 ::MessageBox(GetHWnd(), &str[0], "景点查询", MB_OK); //GetHWnd()获得窗口句柄 287 } 288 int ModifyMenu() { 289 int choose1 = 1; 290 char temp = 0, key; 291 while(temp != \r) { 292 if(kbhit()) { 293 key = getch(); 294 fflush(stdin); 295 switch(key) { 296 case UP: { 297 choose1--; 298 }; 299 break; 300 case DOWN: { 301 choose1++; 302 }; 303 } 304 } 305 if(choose1 == 6) { 306 choose1 = 5; 307 } 308 if(choose1 == 0) { 309 choose1 = 1; 310 } 311 cleardevice(); 312 outtextxy((WIDTH / 2) - 80, 120, "修改景点"); 313 outtextxy((WIDTH / 2) - 180, 230, "按↑和↓选择选项"); 314 outtextxy((WIDTH / 2) - 180, 250, "按ENTER键确定选择"); 315 outtextxy(300, 300, "请选择选项:"); 316 outtextxy(420, 350, "修改名称"); 317 outtextxy(420, 380, "修改简介"); 318 outtextxy(420, 410, "修改代号"); 319 outtextxy(420, 440, "修改坐标"); 320 outtextxy(420, 470, "返回"); 321 outtextxy(390, 350 + (choose1 - 1) * 30, ""); 322 FlushBatchDraw(); 323 temp = getch(); 324 } 325 return choose1; 326 } 327 int ModifyVertex(Graph_List &graph) { 328 bool iscancel = false; 329 int v1; 330 char v1str[10] = {a}; 331 while(1) { 332 iscancel = !InputBox(&(v1str[0]), 10, "输入代号" , "修改景点", "0", 0, 0, 0); 333 CheckCancel 334 v1= str_to_num(v1str); 335 if(graph.GetIndex(v1) != -1) { 336 break; 337 } 338 ::MessageBox(GetHWnd(), "该位置不存在,请重输", "修改景点", MB_OK); 339 } 340 int v=graph.GetIndex(v1); 341 Vertex *Head = graph.GetHead(); 342 string name=Head[v].GetVerName(); 343 string describe=Head[v].GetDescribe(); 344 int marki=Head[v].GetMark(),x=Head[v].GetX()-LEFTBORDER,y=Head[v].GetY()-TOPBORDER; 345 bool isreturn = false; 346 while(!isreturn ) { 347 int in = ModifyMenu(); 348 switch(in) { 349 case 1: { 350 iscancel = !InputBox(&(name[0]), 30, "输入名称" , "修改景点", "0", 0, 0, 0); 351 以上是关于校园导游系统(C++实现,VC6.0编译,使用EasyX图形库)的主要内容,如果未能解决你的问题,请参考以下文章

VC++6.0安装教程。

关于Code Blocks无编译器版本及VC6.0插入打开报错

Visual Studio 2010中的Visual C++如何编译、连接和运行?

win7中vc6.0的兼容性问题解决

c++ 多文件在CMD中怎么编译得到.exe文件??

用VC6.0编译程序总出现错误:无法启动工具,系统找不到指定文件。重装了一遍软件,还是没有解决。