天天看點

本白癡的第一個部落格(就把自己的圖形界面加c語言的滴滴打車資訊系統傳一下吧)滴滴打車資訊系統(圖形界面+C語言)

滴滴打車資訊系統(圖形界面+C語言)

(記得在目錄下建立driver和user兩個txt檔案)

#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <graphics.h>
#include <malloc.h>
#define maxv 100
#define LIMITLESS 9999
#define speed 1;
#define M 100
typedef struct
{
	int number;
	char name[10];
}VertexType;
typedef struct
{
	int n, e;
	int edges[maxv][maxv];
	VertexType vexs[maxv];
}MGraph;  //圖
typedef struct the_users
{
	char account[10];//賬号
	char password[7];//密碼
}users;
typedef struct the_drivers
{
	char carname[10];
	char drivername[10];
	char cpassword[7];
	char location[10];
}drivers;
void CreateMGraph(MGraph *G)  //建立圖
{
	int i, j;
	G->n = 6;
	G->e = 18;
	G->vexs[0].number = 0;
	G->vexs[1].number = 1;
	G->vexs[2].number = 2;
	G->vexs[3].number = 3;
	G->vexs[5].number = 5;
	strcpy(G->vexs[0].name, "寶龍廣場");
	strcpy(G->vexs[1].name, "信号燈");
	strcpy(G->vexs[2].name, "海華");
	strcpy(G->vexs[3].name, "鹽城師範學院");
	strcpy(G->vexs[4].name, "人才較高價的電梯大廈");
	strcpy(G->vexs[5].name, "歡樂谷");
	G->vexs[4].number = 4;
	for (i = 0; i < G->n; i++)
		for (j = 0; j < G->n; j++)
		{
			if (i == j)
				G->edges[i][j] = 0;
			else
				G->edges[i][j] = LIMITLESS;
		}
	G->edges[0][1] = 2;
	G->edges[1][0] = 2;
	G->edges[1][2] = 4;
	G->edges[2][1] = 4;
	G->edges[2][3] = 1;
	G->edges[3][2] = 1;
	G->edges[3][4] = 6;
	G->edges[4][3] = 6;
	G->edges[3][0] = 10;
	G->edges[0][3] = 10;
	G->edges[4][5] = 2;
	G->edges[5][4] = 2;
	G->edges[4][0] = 7;
	G->edges[0][4] = 7;
	G->edges[4][1] = 8;
	G->edges[1][4] = 8;
	G->edges[5][0] = 3;
	G->edges[0][5] = 3;
}
void enter(); //菜單界面
void regist(); //注冊界面
void registpassenger();//乘客注冊
void registdriver(); //司機注冊
void login(); //登陸界面
void loginpassenger(); //乘客登陸界面
void logindriver();   //司機登陸界面
void menupassenger(); //乘客登陸菜單
void menudriver();    //司機登陸菜單
void carmessage(); //車輛資訊查詢
void nearcar();    //附近車輛查詢
void renew(); //修改位置資訊
void tdispath(int dist[], int path[], int s[], int n, int v);
void tdijkstra(MGraph g, int v);
void CreateMGraph(MGraph *G); //建構地圖
void timearrivalg(); //使用者使用資訊查詢
void dtimearrival();
void dijkstra(MGraph g, int v); 
void Ppath(int path[], int i, int v);
void dispath(int dist[], int path[], int s[], int n, int v); //求最近車輛
void dtdispath(int dist[], int path[], int s[], int n, int v);
void dtdijkstra(MGraph g, int v);
void dtimearrival();
void nearcar()
{
	// 繪圖環境初始化
	initgraph(1080, 810);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("near.jpg"));
	char plocation[10];
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("附近車輛查詢");
	outtextxy(310, 80, s1);
	MGraph g;
	int k = 0;
	int i;
	CreateMGraph(&g);
	InputBox(plocation, 10, "請輸入位置資訊");
	for (i = 0; i < g.n; i++)
	{
		if (strcmp(plocation, g.vexs[i].name) == 0)
			k = g.vexs[i].number;
	}
	dijkstra(g, k);
	_getch();
	closegraph();
}
void carmessage()
{
	// 繪圖環境初始化
	initgraph(1024, 735);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("乘客菜單背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("乘客資訊系統!");
	TCHAR s2[] = _T("車牌号:");
	TCHAR s3[] = _T("司機姓名:");
	TCHAR s4[] = _T("車輛位置:");
	outtextxy(430, 50, s1);
	drivers a, b;
	char n[10];
	FILE *fp= fopen("F:\\實訓程式\\drivers.txt", "rb");
		if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
		fread(&b, sizeof(struct the_drivers), 1, fp);
		InputBox(a.carname, 11, "請輸入車牌号資訊");
		while (1)
		{
			if (strcmp(a.carname, b.carname) == 0)
			{
				break;
			}
			else
			{
				if (!feof(fp))
				{
					fread(&b, sizeof(struct the_drivers), 1, fp);
				}
				else
				{
					fclose(fp);
					InputBox(n, 10, "車牌号未注冊,是否繼續:“1.繼續  2.回到首頁面”");
					int r;
					sscanf(n, "%d", &r);
					if (r == 1)
					{
						menupassenger();
					}
					else
					{
						enter();
					}
				}
			}
		}
		setbkmode(TRANSPARENT);
		settextcolor(BLACK);
		settextstyle(30, 0, _T("黑體"));
		outtextxy(430,190 ,b.carname);
		outtextxy(430, 280, b.drivername);
		outtextxy(430, 370, b.location);
		outtextxy(300, 190, s2);
		outtextxy(270, 280, s3);
		outtextxy(270, 370, s4);
		IMAGE img1;
		loadimage(&img1, _T("按鈕背景.png"));
		setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
		fillroundrect(850,630 ,930, 680, 20, 40);
		setbkmode(TRANSPARENT);
		settextcolor(BLACK);
		settextstyle(20, 0, _T("黑體"));
		TCHAR s12[] = _T("傳回");
		outtextxy(870, 650, s12);
		FlushMouseMsgBuffer();
		MOUSEMSG m;
		while (1)
		{
			m = GetMouseMsg();
			switch (m.uMsg)
			{
			case WM_LBUTTONDOWN:
			{
				if (m.x > 850 && m.x < 930&& m.y>630 && m.y < 680)
				{
					menupassenger();
				}
				break;
			}
			}
		}
		_getch();
		closegraph();
}
void enter()
{
	int f = 0;
	// 繪圖環境初始化
	initgraph(1023, 676);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("首頁面.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("歡迎來到滴滴打車資訊系統!");
	outtextxy(310, 80, s1);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(430, 200, 560, 260, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s2[] = _T("1.登入");
	outtextxy(450, 220, s2);
	setfillcolor(BLUE);
	fillroundrect(430, 330, 560, 390, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s3[] = _T("2.注冊");
	outtextxy(450, 350, s3);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (f == 0)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 430 && m.x < 560 && m.y>200 && m.y < 260)
			{
				login();
			}
			if (m.x > 430 && m.x < 560 && m.y < 390 && m.y>330)
			{
				regist();
			}
			break;
		}
		case WM_RBUTTONDOWN:
		{
			f = 0;
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void regist()
{
	int f = 0;
	// 繪圖環境初始化
	initgraph(1024, 655);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("注冊背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("歡迎來到滴滴打車資訊系統!");
	outtextxy(310, 80, s1);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(430, 200, 580, 260, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s2[] = _T("1.乘客注冊");
	outtextxy(450, 220, s2);
	setfillcolor(BLUE);
	fillroundrect(430, 330, 580, 390, 20, 40);
	fillroundrect(430, 460, 610, 520, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s3[] = _T("2.司機注冊");
	outtextxy(450, 350, s3);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s10[] = _T("3.回到主界面");
	outtextxy(450, 480, s10);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (f == 0)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 430 && m.x < 560 && m.y>200 && m.y < 260)
			{
				registpassenger();
			}
			if (m.x > 430 && m.x < 560 && m.y < 390 && m.y>330)
			{
				registdriver();
			}
			if (m.x > 430 && m.x < 560 && m.y>460 && m.y < 610)
			{
				enter();
			}
			break;
		}
		case WM_RBUTTONDOWN:
		{
			f = 0;
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void login()
{
	int f = 0;
	// 繪圖環境初始化
	initgraph(1023, 682);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("登入背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("歡迎來到滴滴打車資訊系統!");
	outtextxy(310, 80, s1);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(430, 200, 580, 260, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s2[] = _T("1.我要打車");
	outtextxy(450, 220, s2);
	setfillcolor(BLUE);
	fillroundrect(430, 330, 580, 390, 20, 40);
	fillroundrect(430, 460, 610, 520, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s3[] = _T("2.我要載客");
	outtextxy(450, 350, s3);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s10[] = _T("3.回到主界面");
	outtextxy(450, 480, s10);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (f == 0)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 430 && m.x < 560 && m.y>200 && m.y < 260)
			{
				loginpassenger();
			}
			if (m.x > 430 && m.x < 560 && m.y < 390 && m.y>330)
			{
				logindriver();
			}
			if (m.x > 430 && m.x < 610 && m.y>460 && m.y < 520)
			{
				enter();
			}
			break;
		}
		case WM_RBUTTONDOWN:
		{
			f = 0;
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void registpassenger()
{
	int f = 0;
	char n[10];
	// 繪圖環境初始化
	initgraph(1023, 676);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("注冊背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("乘客注冊頁面!");
	outtextxy(350, 130, s1);
	users a, b;//結構體 the_users 重命名定義
	FILE *fp;
	fp = fopen("F:\\實訓程式\\users.txt", "rb");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	fread(&b, sizeof(struct the_users), 1, fp); //讀入一個結構體字元塊到b
	InputBox(a.account, 10, "請輸入賬号");
	while (1)
	{
		if (strcmp(a.account, b.account) != 0) /*如果兩串不相等*/
		{
			if (!feof(fp))    /*如果未到檔案尾*/
			{
				fread(&b, sizeof(struct the_users), 1, fp);
			}
			else
				break;
		}
		else
		{
			fclose(fp);
			InputBox(n, 10, "使用者名已存在,是否繼續:“1.繼續  2.回到首頁面”");
			int r;
			sscanf(n, "%d", &r);
			if (r == 1)
			{
				registpassenger();
			}
			else
			{
				enter();
			}
		}
	}
	InputBox(a.password, 7, "請輸入六位密碼");
	fp = fopen("F:\\實訓程式\\users.txt", "ab");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	fwrite(&a, sizeof(struct the_users), 1, fp);
	fclose(fp);
	initgraph(1023, 676);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("注冊背景.png"));
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(780, 480, 930, 540, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s2[] = _T("注冊成功!");
	outtextxy(360, 130, s2);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s10[] = _T("回到主界面");
	outtextxy(800, 500, s10);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (f == 0)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 780 && m.x < 930 && m.y>480 && m.y < 540)
			{
				enter();
			}
			break;
		}
		case WM_RBUTTONDOWN:
		{
			f = 0;
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void registdriver()
{
	int f = 0;
	char n[10];
	// 繪圖環境初始化
	initgraph(1023, 676);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("注冊背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("司機注冊頁面!");
	outtextxy(350, 130, s1);
	drivers a, b;//結構體 the_users 重命名定義
	FILE *fp;
	fp = fopen("F:\\實訓程式\\drivers.txt", "rb");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	fread(&b, sizeof(struct the_drivers), 1, fp); //讀入一個結構體字元塊到b
	InputBox(a.carname, 10, "請輸入車牌号");
	while (1)
	{
		if (strcmp(a.carname, b.carname) != 0) /*如果兩串不相等*/
		{
			if (!feof(fp))    /*如果未到檔案尾*/
			{
				fread(&b, sizeof(struct the_drivers), 1, fp);
			}
			else
				break;
		}
		else
		{
			fclose(fp);
			InputBox(n, 10, "車牌号已注冊,是否繼續:“1.繼續  2.回到首頁面”");
			int r;
			sscanf(n, "%d", &r);
			if (r == 1)
			{
				registdriver();
			}
			else
			{
				enter();
			}
		}
	}
	InputBox(a.drivername, 10, "請輸入姓名");
	InputBox(a.location, 10, "請輸入位置資訊");
	InputBox(a.cpassword, 7, "請輸入六位密碼");
	fp = fopen("F:\\實訓程式\\drivers.txt", "ab");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	fwrite(&a, sizeof(struct the_drivers), 1, fp);
	fclose(fp);
	initgraph(1023, 676);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("注冊背景.png"));
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(780, 480, 930, 540, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s2[] = _T("注冊成功!");
	outtextxy(360, 130, s2);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s10[] = _T("回到主界面");
	outtextxy(800, 500, s10);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (f == 0)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 780 && m.x < 930 && m.y>480 && m.y < 540)
			{
				enter();
			}
			break;
		}
		case WM_RBUTTONDOWN:
		{
			f = 0;
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void loginpassenger()
{
	int f = 0;
	// 繪圖環境初始化
	initgraph(1023, 682);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("登入背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("使用者登陸界面!");
	outtextxy(330, 80, s1);
	users a, b;
	char n[10];
	char i_1[1];
	FILE *fp;
	fp = fopen("F:\\實訓程式\\users.txt", "rb");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	fread(&b, sizeof(struct the_users), 1, fp);
	InputBox(a.account, 10, "請輸入賬号");
	while (1)
	{
		if (strcmp(a.account, b.account) == 0)
		{
			break;
		}
		else
		{
			if (!feof(fp))
			{
				fread(&b, sizeof(struct the_users), 1, fp);
			}
			else
			{
				fclose(fp);
				InputBox(n, 10, "賬号未注冊,是否注冊:“1.注冊  2.回到首頁面”");
				int r;
				sscanf(n, "%d", &r);
				if (r == 1)
				{
					registpassenger();
				}
				else
				{
					enter();
				}
			}
		}
	}
	InputBox(a.password, 7, "請輸入密碼");
	if (strcmp(a.password, b.password) == 0)
	{
		fclose(fp);
		menupassenger();
	}
	else
	{
		fclose(fp);
		InputBox(n, 10, "密碼錯誤,是否繼續:“1.繼續  2.回到首頁面”");
		int j;
		sscanf(i_1, "%d", &j);
		if (j == 1)
		{
			loginpassenger();
		}
		else
		{
			enter();
		}
	}
}
void logindriver()
{
	// 繪圖環境初始化
	initgraph(1023, 682);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("登入背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("司機登入界面!");
	outtextxy(330, 80, s1);
	drivers a, b;
	char n[10];
	char i_2[1];
	FILE *fp;
	fp = fopen("F:\\實訓程式\\drivers.txt", "rb");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	fread(&b, sizeof(struct the_drivers), 1, fp);
	InputBox(a.carname, 10, "請輸入車牌号");
	while (1)
	{
		if (strcmp(a.carname, b.carname) == 0)
		{
			break;
		}
		else
		{
			if (!feof(fp))
			{
				fread(&b, sizeof(struct the_drivers), 1, fp);
			}
			else
			{
				fclose(fp);
				InputBox(n, 10, "車牌号未注冊,是否注冊:“1.注冊  2.回到首頁面”");
				int r;
				sscanf(n, "%d", &r);
				if (r == 1)
				{
					registpassenger();
				}
				else
				{
					enter();
				}
			}
		}
	}
	InputBox(a.cpassword, 7, "請輸入密碼");
	if (strcmp(a.cpassword, b.cpassword) == 0)
	{
		fclose(fp);
		menudriver();
	}
	else
	{
		fclose(fp);
		InputBox(n, 2, "密碼錯誤,是否繼續:“1.繼續  2.回到首頁面”");
		int j;
		sscanf(i_2, "%d", &j);
		if (j == 1)
		{
			login();
		}
		else
		{
			enter();
		}
	}
}
void menupassenger()
{
	int f = 0;
	// 繪圖環境初始化
	initgraph(1024, 735);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("乘客菜單背景.png"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("乘客資訊系統!");
	outtextxy(430, 50, s1);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(430, 150, 630, 210, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s2[] = _T("1.車輛資訊查詢");
	outtextxy(450, 170, s2);
	setfillcolor(BLUE);
	fillroundrect(430,250, 630, 310, 20, 40);
	fillroundrect(430, 350, 630, 410, 20, 40);
	fillroundrect(430, 460, 660, 520, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s3[] = _T("3.使用資訊查詢");
	outtextxy(450, 370, s3);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s10[] = _T("4.傳回主界面");
	outtextxy(450, 480, s10);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s4[] = _T("2.附近車輛查詢");
	outtextxy(450, 270, s4);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (f == 0)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 430 && m.x < 630 && m.y>150 && m.y < 210)
			{
				carmessage();
			}
			if (m.x > 430 && m.x < 630 && m.y < 310 && m.y>250)
			{
				nearcar();
			}
			if (m.x > 430 && m.x < 630 && m.y < 410 && m.y>350)
			{
				timearrivalg();
			}
			if (m.x > 430 && m.x <660 && m.y>560 && m.y < 620)
			{
				timearrivalg();
			}
			if (m.x > 430 && m.x < 660 && m.y>462 && m.y < 520)
			{
				login();
			}
			break;
		}
		case WM_RBUTTONDOWN:
		{
			f = 0;
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void dijkstra(MGraph g, int v)
{
	int dist[maxv];
	int path[maxv];
	int s[maxv];
	int mindis_1;
	int i, j, u;
	for (i = 0; i < g.n; i++)
	{
		dist[i] = g.edges[v][i];
		s[i] = 0;
		if (g.edges[v][i] < LIMITLESS)
			path[i] = v;
		else
			path[i] = -1;
	}
	s[v] = 1;
	path[v] = 0;
	for (i = 0; i < g.n; i++)
	{
		mindis_1 = LIMITLESS;
		for (j = 0; j < g.n; j++)
		{
			if (s[j] == 0 && dist[j] < mindis_1)
			{
				u = j;
				mindis_1 = dist[j];
			}
		}
		s[u] = 1;
		for (j = 0; j < g.n; j++)
		{
			if (s[j] == 0 && g.edges[u][j] < LIMITLESS&&dist[u] + g.edges[u][j] < dist[j])
			{
				dist[j] = dist[u] + g.edges[u][j];
				path[j] = u;
			}
		}
	}
	dispath(dist, path, s, g.n, v);
}
void tdijkstra(MGraph g, int v)
{
	int dist[maxv];
	int path[maxv];
	int s[maxv];
	int mindis_2;
	int i, j, u;
	for (i = 0; i < g.n; i++)
	{
		dist[i] = g.edges[v][i];
		s[i] = 0;
		if (g.edges[v][i] < LIMITLESS)
			path[i] = v;
		else
			path[i] = -1;
	}
	s[v] = 1;
	path[v] = 0;
	for (i = 0; i < g.n; i++)
	{
		mindis_2 = LIMITLESS;
		for (j = 0; j < g.n; j++)
		{
			if (s[j] == 0 && dist[j] < mindis_2)
			{
				u = j;
				mindis_2 = dist[j];
			}
		}
		s[u] = 1;
		for (j = 0; j < g.n; j++)
		{
			if (s[j] == 0 && g.edges[u][j] < LIMITLESS&&dist[u] + g.edges[u][j] < dist[j])
			{
				dist[j] = dist[u] + g.edges[u][j];
				path[j] = u;
			}
		}
	}
	tdispath(dist, path, s, g.n, v);
}
void Ppath(int path[], int i, int v)
{
	int k;
	k = path[i];
	if (k == v)
		return;
	Ppath(path, k, v);
	printf("%d", k);
}
void dispath(int dist[], int path[], int s[], int n, int v)
{
	int ccount=200;
	int ncount = 0;
	// 繪圖環境初始化
	initgraph(1080, 810);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("near.jpg"));
	char plocation[10];
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("附近車輛查詢");
	outtextxy(310, 80, s1);
	int i;
	for (i = 0; i < n; i++)
		if (s[i] == 1)
		{
			printf("從%d到%d的最短路徑長度為:%d\t路徑為:", v, i, dist[i]);
			printf("%d", v);
			Ppath(path, i, v);
			printf("%d\n", i);
		}
		else
		{
			printf("從%d到%d不存在路徑\n", v, i);
		}
	drivers  a[6];
	drivers b[M];
	strcpy(a[0].carname, "寶龍廣場");
	strcpy(a[1].carname, "信号燈");
	strcpy(a[2].carname, "海華");
	strcpy(a[3].carname, "鹽城師範學院");
	strcpy(a[4].carname, "人才較高價的電梯大廈");
	strcpy(a[5].carname, "歡樂谷");
	FILE *fp = fopen("F:\\實訓程式\\drivers.txt", "rb");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(20, 0, _T("黑體"));
	TCHAR s22[] = _T("(無車)");
	TCHAR s23[] = _T("(有車)");
	while (!feof(fp))
	{
		for (i = 0; i < M; i++)
			fread(&b[i], sizeof(struct the_drivers), 1, fp);
	}
	int k = 0;
	int j = 0;
	int k1 = 0;
	int j1 = 0;
   for (k = 0; k < i; k++)
     for(j=0;j<6;j++)
	{
		if (strcmp(b[k].location, a[j].carname) == 0)
		{
			outtextxy(750, ccount + j * 60, s23);
		}
	}
	fclose(fp);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(20, 0, _T("黑體"));
	TCHAR s2[] = _T("車輛地點:  寶龍廣場");
	TCHAR s3[] = _T("車輛地點:  信号燈");
	TCHAR s4[] = _T("車輛地點:  海華");
	TCHAR s5[] = _T("車輛地點:  鹽城師範學院");
	TCHAR s6[] = _T("車輛地點:  人才較高價的電梯大廈");
	TCHAR s7[] = _T("車輛地點:  歡樂谷");
	TCHAR s8[] = _T("最近車輛距離:");
	outtextxy(150, 200, s2);
	outtextxy(150, 260, s3);
	outtextxy(150, 320, s4);
	outtextxy(150, 380, s5);
	outtextxy(150, 440, s6);
	outtextxy(150, 500, s7);
	char c[5];
	char c1[5];
	char c2[5];
	char c3[5];
	char c4[5];
	char c5[5];
	sprintf(c, "%d", dist[0]);
	sprintf(c1, "%d", dist[1]);
	sprintf(c2, "%d", dist[2]);
	sprintf(c3, "%d", dist[3]);
	sprintf(c4, "%d", dist[4]);
	sprintf(c5, "%d", dist[5]);
	outtextxy(590, 200, s8);
	outtextxy(590, 260, s8);
	outtextxy(590, 320, s8);
	outtextxy(590, 380, s8);
	outtextxy(590, 440, s8);
	outtextxy(590, 500, s8);
	outtextxy(720, 200, c);
	outtextxy(720, 260, c1);
	outtextxy(720, 320, c2);
	outtextxy(720,380, c3);
	outtextxy(720, 440, c4);
	outtextxy(720, 500, c5);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(970, 735, 1060,780, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(20, 0, _T("黑體"));
	TCHAR s12[] = _T("傳回");
	outtextxy(1000, 750, s12);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (1)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 970 && m.x <1060 && m.y>735 && m.y < 780)
			{
				menupassenger();
			}
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void tdispath(int dist[], int path[], int s[], int n, int v)
{
	
	int k = 0;
	int i;
	// 繪圖環境初始化
	initgraph(1080, 810);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("near.jpg"));
	MGraph h;
	CreateMGraph(&h);
	char plocation[10];
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("到達目的地時間");
	outtextxy(310, 80, s1);
	InputBox(plocation, 10, "請輸入起點位址");
	for (i = 0; i < h.n; i++)
	{
		if (strcmp(plocation, h.vexs[i].name) == 0)
			k = h.vexs[i].number;
	}
	for (i = 0; i < n; i++)
		if (s[i] == 1)
		{
			printf("從%d到%d的最短路徑長度為:%d\t路徑為:", v, i, dist[i]);
			printf("%d", v);
			Ppath(path, i, v);
			printf("%d\n", i);
		}
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(20, 0, _T("黑體"));
	TCHAR s2[] = _T("目的地位址: ");
	outtextxy(150, 200, s2);
	outtextxy(350, 200, h.vexs[v].name);
	TCHAR s3[] = _T("預計到達時間 ");
	outtextxy(150, 260, s3);
	char c10[5];
	sprintf(c10, "%d", dist[k]);
	outtextxy(350, 260, c10);
	TCHAR s6[] = _T("h");
	outtextxy(380, 260, s6);
	TCHAR s7[] = _T("預計費用: ");
	outtextxy(150, 320, s7);
	int money = dist[k] * 7;
	char c11[5];
	sprintf(c11, "%d", money);
	outtextxy(350, 320, c11);
	TCHAR s9[] = _T("元");
	outtextxy(380, 320, s9);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(970, 735, 1060, 780, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(20, 0, _T("黑體"));
	TCHAR s12[] = _T("傳回");
	outtextxy(1000, 750, s12);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (1)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 970 && m.x < 1060 && m.y>735 && m.y < 780)
			{
				menupassenger();
			}
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void dtdispath(int dist[], int path[], int s[], int n, int v)
{
	
	int k = 0;
	int i;
	// 繪圖環境初始化
	initgraph(1200, 562);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("司機菜單背景.jpg"));
	MGraph h;
	CreateMGraph(&h);
	char plocation[10];
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("到達目的地時間");
	outtextxy(310, 80, s1);
	InputBox(plocation, 10, "請輸入起點位址");
	for (i = 0; i < h.n; i++)
	{
		if (strcmp(plocation, h.vexs[i].name) == 0)
			k = h.vexs[i].number;
	}
	for (i = 0; i < n; i++)
		if (s[i] == 1)
		{
			printf("從%d到%d的最短路徑長度為:%d\t路徑為:", v, i, dist[i]);
			printf("%d", v);
			Ppath(path, i, v);
			printf("%d\n", i);
		}
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(20, 0, _T("黑體"));
	TCHAR s2[] = _T("目的地位址: ");
	outtextxy(150, 200, s2);
	outtextxy(350, 200, h.vexs[v].name);
	TCHAR s3[] = _T("預計到達時間 ");
	outtextxy(150, 260, s3);
	char c10[5];
	sprintf(c10, "%d", dist[k]);
	outtextxy(350, 260, c10);
	TCHAR s6[] = _T("h");
	outtextxy(380, 260, s6);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(970, 735, 1060, 780, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(20, 0, _T("黑體"));
	TCHAR s12[] = _T("傳回");
	outtextxy(1000, 750, s12);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (1)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 970 && m.x < 1060 && m.y>735 && m.y < 780)
			{
				menupassenger();
			}
			break;
		}
		}
	}
	_getch();
	closegraph();
}
void timearrivalg()
{
	// 繪圖環境初始化
	initgraph(1080, 810);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("near.jpg"));
	char plocation[10];
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("到達目的地時間");
	outtextxy(310, 80, s1);
	MGraph g;
	int k = 0;
	int i;
	CreateMGraph(&g);
	InputBox(plocation, 10, "請輸入目的地資訊");
	for (i = 0; i < g.n; i++)
	{
		if (strcmp(plocation, g.vexs[i].name) == 0)
			k = g.vexs[i].number;
	}
	tdijkstra(g, k);
	_getch();
	closegraph();
}
void menudriver()
{
	int f = 0;
	// 繪圖環境初始化
	initgraph(1200,562);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("司機菜單背景.jpg"));
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("司機資訊系統!");
	outtextxy(430, 50, s1);
	IMAGE img1;
	loadimage(&img1, _T("按鈕背景.png"));
	setfillstyle(BS_DIBPATTERN, NULL, &img1);  //設定按鈕背景
	fillroundrect(430, 150, 630, 210, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s2[] = _T("1.使用資訊查詢");
	outtextxy(450, 170, s2);
	setfillcolor(BLUE);
	fillroundrect(430, 250, 630, 310, 20, 40);
	fillroundrect(430, 350, 630, 410, 20, 40);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s4[] = _T("2.位置修改");
	outtextxy(450, 270, s4);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(25, 0, _T("黑體"));
	TCHAR s3[] = _T("3.傳回主界面");
	outtextxy(450, 370, s3);
	FlushMouseMsgBuffer();
	MOUSEMSG m;
	while (f == 0)
	{
		m = GetMouseMsg();
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
		{
			if (m.x > 430 && m.x < 630 && m.y>150 && m.y < 210)
			{
				dtimearrival();
			}
			if (m.x > 430 && m.x < 630 && m.y < 310 && m.y>250)
			{
				renew();
			}
			if (m.x > 430 && m.x < 630 && m.y < 410 && m.y>350)
			{
				enter();
			}
			break;
		}
		case WM_RBUTTONDOWN:
		{
			f = 0;
			break;
		}
		}
	}
}
void dtdijkstra(MGraph g, int v)
{
	int dist[maxv];
	int path[maxv];
	int s[maxv];
	int mindis_3;
	int i, j, u;
	for (i = 0; i < g.n; i++)
	{
		dist[i] = g.edges[v][i];
		s[i] = 0;
		if (g.edges[v][i] < LIMITLESS)
			path[i] = v;
		else
			path[i] = -1;
	}
	s[v] = 1;
	path[v] = 0;
	for (i = 0; i < g.n; i++)
	{
		mindis_3 = LIMITLESS;
		for (j = 0; j < g.n; j++)
		{
			if (s[j] == 0 && dist[j] < mindis_3)
			{
				u = j;
				mindis_3 = dist[j];
			}
		}
		s[u] = 1;
		for (j = 0; j < g.n; j++)
		{
			if (s[j] == 0 && g.edges[u][j] < LIMITLESS&&dist[u] + g.edges[u][j] < dist[j])
			{
				dist[j] = dist[u] + g.edges[u][j];
				path[j] = u;
			}
		}
	}
	dtdispath(dist, path, s, g.n, v);
}
void dtimearrival()
{
	
	// 繪圖環境初始化
	initgraph(1200, 562);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("司機菜單背景.jpg"));
	char plocation[10];
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("使用資訊查詢");
	outtextxy(310, 80, s1);
	MGraph g;
	int k = 0;
	int i;
	CreateMGraph(&g);
	InputBox(plocation, 10, "請輸入目的地資訊");
	for (i = 0; i < g.n; i++)
	{
		if (strcmp(plocation, g.vexs[i].name) == 0)
			k = g.vexs[i].number;
	}
	dtdijkstra(g, k);
	_getch();
	closegraph();
}
void renew()
{
	initgraph(1023, 682);
	// 讀取圖檔至繪圖視窗
	loadimage(NULL, _T("登入背景.png"));
	int i = 0;
	int j = 0;
	char n[10];
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(40, 0, _T("黑體"));
	TCHAR s1[] = _T("司機登入界面!");
	outtextxy(330, 80, s1);
	FILE *fp;
	FILE *FP;
	drivers a[M];
	drivers b;
	fp = fopen("F:\\實訓程式\\drivers.txt", "rb");
	if (fp == NULL)
	{
		printf("fail to open the file! \n");
		exit(0);
	}
	while (!feof(fp))
	{
		fread(&a[i], sizeof(struct the_drivers), 1, fp);
		i++;
	}
	fclose(fp);
	InputBox(b.carname, 10, "請輸入車牌号");
	for (j = 0; j < i; j++)
	{
		if (strcmp(b.carname, a[j].carname)==0)
		{
			InputBox(a[j].location, 10, "請輸入位置資訊");
			FP = fopen("F:\\實訓程式\\drivers.txt", "wb");
			if (FP == NULL)
			{
				printf("fail to open the file! \n");
				exit(0);
			}
			for (j = 0; j < i; j++)
			{
				fwrite(&a[j], sizeof(struct the_drivers), 1, FP);
			}
			fclose(FP);
			break;
		}
	}
	InputBox(n, 10, "是否繼續 :1.繼續  2.回到首頁面");
	int r;
	sscanf(n, "%d", &r);
	if (r == 1)
	{
		renew();
	}
	else
	{
		menudriver();
	}
}
int main()
{
	enter();
	return 0;
}


           

繼續閱讀