C++實(shí)現(xiàn)車票管理系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)車票管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一車站每天有n個(gè)發(fā)車班次,每個(gè)班次都有一班次號(hào)(1、2、3…n),固定的發(fā)車時(shí)間,
固定的路線(起始站、終點(diǎn)站),大致的行車時(shí)間,固定的額定載客量。如
班次 發(fā)車時(shí)間 起點(diǎn)站 終點(diǎn)站 行車時(shí)間 額定載量 已定票人數(shù)
1 8:00 郫縣 廣漢 2 45 30
2 6:30 郫縣 成都 0.5 40 40
3 7:00 郫縣 成都 0.5 40 20
4 10:00 郫縣 成都 0.5 40 2
…
功能要求:
(1)錄入班次信息(信息用文件保存),可不定時(shí)地增加班次數(shù)據(jù)
(2)瀏覽班次信息,可顯示出所有班次當(dāng)前狀總(如果當(dāng)前系統(tǒng)時(shí)間超過了某班次的發(fā)車時(shí)間,則顯示“此班已發(fā)出”的提示信息)。
(3)查詢路線:可按班次號(hào)查詢 ,可按終點(diǎn)站查詢
(4)售票和退票功能
A:當(dāng)查詢出已定票人數(shù)小于額定載量且當(dāng)前系統(tǒng)時(shí)間小于發(fā)車時(shí)間時(shí)才能售票,自動(dòng)更新已售票人數(shù)
B:退票時(shí),輸入退票的班次,當(dāng)本班車未發(fā)出時(shí)才能退票,自動(dòng)更新已售票人數(shù)
下面是 代碼。
工具是VS2019、MySQL8.0
注意:請(qǐng)?zhí)崆霸O(shè)置好VS 的環(huán)境,否則運(yùn)行不出來。本人是個(gè)菜鳥,代碼可能比較復(fù)雜比較low,輕噴。
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <WinSock2.h> #include <mysql.h> #include <Windows.h> #include <time.h> #include <iostream> using namespace std; //包含附加依賴項(xiàng),也可以在工程--屬性里面設(shè)置 //#pragma comment(lib,"wsock32.lib") //#pragma comment(lib,"libmysql.lib") MYSQL mysql; //mysql連接 MYSQL_FIELD* fd; ?//字段列數(shù)組 char field[32][32]; ?//存字段名二維數(shù)組 MYSQL_RES* res; //這個(gè)結(jié)構(gòu)代表返回行的一個(gè)查詢結(jié)果集 MYSQL_ROW column,row; //一個(gè)行數(shù)據(jù)的類型安全(type-safe)的表示,表示數(shù)據(jù)行的列 char query[150]; //查詢語句 bool ConnectDatabase(); ? ? //函數(shù)聲明 void FreeConnect(); bool read(); ?//查詢1 bool search(); ?//查詢2 bool input(); bool piao(); void mainmenu(); bool readtest(); int main(int argc, char** argv) { ? ? int m; ? ? int k = 1; ? ? ConnectDatabase(); ? ? mainmenu(); ? ? while(k==1) ? ? { ? ? ? ? printf("\n"); ? ? ? ? printf(" 請(qǐng)選擇功能:"); ? ? ? ? cin >> m; ? ? ? ? switch (m) ? ? ? ? { ? ? ? ? case ?1 :input(); break;//錄入車票信息 ? ? ? ? case ?2 :read(); break;//瀏覽車票信息 ? ? ? ? case ?3 :search(); break;// 查詢車票信息 ? ? ? ? case ?4 :piao(); break;//售票和退票 ? ? ? ? case ?5 : k = 0; break;//退出系統(tǒng) ? ? ? ? } ? ? } ? ? FreeConnect(); ? ? system("pause"); ? ? return 0; } //連接數(shù)據(jù)庫 bool ConnectDatabase() { ? ? //初始化mysql ? ? mysql_init(&mysql); ?//連接mysql,數(shù)據(jù)庫 ? ? //返回false則連接失敗,返回true則連接成功 ? ? if (!(mysql_real_connect(&mysql, "localhost", "root", "123456", "chepiao", 3306, NULL, 0))) //中間分別是主機(jī),用戶名,密碼,數(shù)據(jù)庫名,端口號(hào),可以先寫成參數(shù)再傳進(jìn)去 ? ? { ? ? ? ? printf("Error connecting to database:%s\n", mysql_error(&mysql)); ? ? ? ? return false; ? ? } ? ? else ? ? { ? ? ? ? printf("Connected ?success\n"); ? ? ? ? return true; ? ? } } void mainmenu() { ? ? cout << "\n\n--------歡迎使用車票管理系統(tǒng)----------" << endl << endl; ? ? cout << "===========================================" << endl; ? ? cout << "||========================================||" << endl; ? ? cout << "|| ? ? ? ? ? ?1.錄入車票信息 ? ? ? ? ? ? ?||" << endl; ? ? cout << "|| ? ? ? ? ? ?2.瀏覽車票信息 ? ? ? ? ? ? ?||" << endl; ? ? cout << "|| ? ? ? ? ? ?3.查詢車票信息 ? ? ? ? ? ? ?||" << endl; ? ? cout << "|| ? ? ? ? ? ?4.售票和退票 ? ? ? ? ? ? ? ?||" << endl; ? ? cout << "|| ? ? ? ? ? ?5.退出系統(tǒng) ? ? ? ? ? ? ? ? ?||" << endl; ? ? cout << "||========================================||" << endl; ? ? cout << "============================================" << endl; } //釋放資源 void FreeConnect() { ? ? //釋放資源 ? ? mysql_free_result(res); ? ? mysql_close(&mysql); } //數(shù)據(jù)庫操作 //其實(shí)所有的數(shù)據(jù)庫操作都是先寫個(gè)sql語句,然后用mysql_query(&mysql,query)來完成,包括創(chuàng)建數(shù)據(jù)庫或表,增刪改查 bool readtest() { ? ? struct tm* local; ? ? time_t t; ? ? t = time(NULL); ? ? sprintf(query, "select * from testTable"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //返回0 查詢成功,返回1查詢失敗 ? ? mysql_query(&mysql, query); ? ? //執(zhí)行SQL語句 ? ? //獲取結(jié)果集 ? ? if (!(res = mysql_store_result(&mysql))) ? ?//獲得sql語句結(jié)束后返回的結(jié)果集 ? ? { ? ? ? ? printf("Couldn't get result from %s\n", mysql_error(&mysql)); ? ? ? ? return false; ? ? } ? ? local = localtime(&t);//獲取當(dāng)前系統(tǒng)時(shí)間 ? ? int num = local->tm_hour; ? ? int num1 = local->tm_min; ? ? char str1[25], str2[25]; ? ? sprintf(str1, "%d", num); ? ? sprintf(str2, "%d", num1); ? ? char a[5] = ":"; ? ? char s[1000]; ? ? int n; ? ? strcpy(s, str1); ? ? strcat(s, a); ? ? strcat(s, str2); ? ? cout << endl; ? ? //printf(" 當(dāng)前系統(tǒng)時(shí)間為:%10s\t\n", s); ? ? //cout << endl; ? ? char* str_field[32]; ?//定義一個(gè)字符串?dāng)?shù)組存儲(chǔ)字段信息 ? ? for (int i = 0; i < 8; i++) ? //在已知字段數(shù)量的情況下獲取字段名 ? ? { ? ? ? ? str_field[i] = mysql_fetch_field(res)->name; ? ? } ? ? /*for (int i = 0; i < 8; i++) ? //打印字段 ? ? ? ? printf("%10s\t", str_field[i]); ? ? printf("\n");*/ ? ? while (column = mysql_fetch_row(res)) ? //在已知字段數(shù)量情況下,獲取并打印下一行 ? ? { ? ? ? ? char test[1000]; ? ? ? ? char co[1000]; ? ? ? ? char abc[5] = "'"; ? ? ? ? int j = 0; ? ? ? ? strcpy(co, column[1]); ? ? ? ? while (co[j] != ':') ? ? ? ? { ? ? ? ? ? ? if ((co[j] > 47) && (co[j] < 58)) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? test[j] = co[j]; ? ? ? ? ? ? ? ? j++; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? if (j == 2) ? ? ? ? ? ? n = (test[0] - '0') * 10 + (test[1] - '0'); ? ? ? ? else if (j == 1) ? ? ? ? ? ? n = (test[0] - '0'); ? ? ? ? if ((local->tm_hour) < n) ? ? ? ? { ? ? ? ? ? ? sprintf(query, "update testtable set 當(dāng)前狀況='此車未發(fā)出' where 發(fā)車時(shí)間='"); ? ? ? ? ? ? strcat(query, column[1]); ? ? ? ? ? ? strcat(query, abc); ? ? ? ? ? ? mysql_query(&mysql, query); ? ? ? ? } ? ? ? ? else ? ? ? ? { ? ? ? ? ? ? sprintf(query, "update testtable set 當(dāng)前狀況='此車已發(fā)出'where 發(fā)車時(shí)間='"); ? ? ? ? ? ? strcat(query, column[1]); ? ? ? ? ? ? strcat(query, abc); ? ? ? ? ? ? mysql_query(&mysql, query); ? ? ? ? } ? ? ? ? //打印獲取的數(shù)據(jù) ? ? ? ? printf("%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\n", column[0], column[1], column[2], column[3], column[4], column[5], column[6], column[7]); ?//column是列數(shù)組 ? ? } ? ? return true; } //瀏覽數(shù)據(jù) bool read() { ? ? struct tm* local; ? ? time_t t; ? ? t = time(NULL); ? ? sprintf(query, "select * from testTable"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //返回0 查詢成功,返回1查詢失敗 ? ? mysql_query(&mysql, query); ? ? //執(zhí)行SQL語句 ? ? ? ? ? //獲取結(jié)果集 ? ? if (!(res = mysql_store_result(&mysql))) ? ?//獲得sql語句結(jié)束后返回的結(jié)果集 ? ? { ? ? ? ? printf("Couldn't get result from %s\n", mysql_error(&mysql)); ? ? ? ? return false; ? ? } ? ? local = localtime(&t);//獲取當(dāng)前系統(tǒng)時(shí)間 ? ? int num = local->tm_hour; ? ? int num1 = local->tm_min; ? ? char str1[25], str2[25]; ? ? sprintf(str1, "%d", num); ? ? sprintf(str2, "%d", num1); ? ? char a[5] = ":"; ? ? char s[1000]; ? ? int n; ? ?? ? ? strcpy(s, str1); ? ? strcat(s, a); ? ? strcat(s, str2); ? ? cout << endl; ? ? printf(" 當(dāng)前系統(tǒng)時(shí)間為:%10s\t\n", s); ? ? cout << endl; ? ? char* str_field[32]; ?//定義一個(gè)字符串?dāng)?shù)組存儲(chǔ)字段信息 ? ? for (int i = 0; i < 8; i++) ? //在已知字段數(shù)量的情況下獲取字段名 ? ? { ? ? ? ? str_field[i] = mysql_fetch_field(res)->name; ? ? } ? ? for (int i = 0; i < 8; i++) ? //打印字段 ? ? ? ? printf("%10s\t", str_field[i]); ? ? printf("\n"); ? ? ? ? while (column = mysql_fetch_row(res)) ? //在已知字段數(shù)量情況下,獲取并打印下一行 ? ? { ? char test[1000]; ? ? ? ? char co[1000]; ? ? ? ? char abc[5]="'"; ? ? ? ? int j = 0; ? ? ? ? strcpy(co, column[1]); ? ? ? ? while (co[j] != ':') ? ? ? ? { ? ? ? ? ? ? if ((co[j] > 47) && (co[j] < 58)) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? test[j] = co[j]; ? ? ? ? ? ? ? ? j++; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? if (j == 2) ? ? ? ? ? ? n = (test[0] - '0') * 10 + (test[1] - '0'); ? ? ? ? else if (j == 1) ? ? ? ? ? ? n = (test[0] - '0'); ? ? ? ? if ((local->tm_hour )<n) ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? sprintf(query, "update testtable set 當(dāng)前狀況='此車未發(fā)出' where 發(fā)車時(shí)間='"); ? ? ? ? ? ? strcat(query,column[1]); ? ? ? ? ? ? strcat(query,abc); ? ? ? ? ? ? mysql_query(&mysql, query); ? ? ? ? } ? ? ? ? else? ? ? ? ? { ? ? ? ? ? ? sprintf(query, "update testtable set 當(dāng)前狀況='此車已發(fā)出'where 發(fā)車時(shí)間='"); ? ? ? ? ? ? strcat(query, column[1]); ? ? ? ? ? ? strcat(query, abc); ? ? ? ? ? ? mysql_query(&mysql, query); ? ? ? ? } ? ? ? ? ? ? ? ? ?? ? ? } ? ? readtest(); ? ? return true; } //查詢數(shù)據(jù) bool search() { ? ? int y; ? ? int m; ? ? char n[5]; ? ? char s[100]; ? ? char abc[5] = "'"; ? ? printf(" 請(qǐng)輸入查詢方式:1 按班次號(hào)查詢 ;2 按終點(diǎn)站查詢\n"); ? ? printf(" 請(qǐng)輸入您的操作: "); ? ? cin >> m; ? ? if (m == 1) ? ? { ? ? ? ? printf(" 請(qǐng)輸入您要查詢的班次號(hào): ?"); ? ? ? ? cin >> n; ? ? ? ? sprintf(query, "select * from testtable where 班次='"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? ? ? strcat(query, n); ? ? ? ? strcat(query, abc); ? ? ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? mysql_query(&mysql, query); ? ?//執(zhí)行SQL語句 ? ? ? ? //獲取結(jié)果集 ? ? ? ? if (!(res = mysql_store_result(&mysql))) ? ?//獲得sql語句結(jié)束后返回的結(jié)果集 ? ? ? ? { ? ? ? ? ? ? printf("Couldn't get result from %s\n", mysql_error(&mysql)); ? ? ? ? ? ? return false; ? ? ? ? } ? ? ? ? for (int i = 0; fd = mysql_fetch_field(res); i++) ?//獲取字段名 ? ? ? ? ? ? strcpy(field[i], fd->name); ? ? ? ? int j = mysql_num_fields(res); ?// 獲取列數(shù) ? ? ? ? printf("\n"); ? ? ? ? for (int i = 0; i < j; i++) ?//打印字段 ? ? ? ? ? ? printf("%10s\t", field[i]); ? ? ? ? printf("\n"); ? ? ? ? while (column = mysql_fetch_row(res)) ? ? ? ? { ? ? ? ? ? ? printf("%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\n", column[0], column[1], column[2], column[3], column[4], column[5], column[6], column[7]); ?//column是列數(shù)組 ? ? ? ? } ? ? } ? ? else if (m == 2) ? ? { ? ? ? ? printf(" 請(qǐng)輸入您要查詢的終點(diǎn)站: ?"); ? ? ? ? cin >> s; ? ? ? ? sprintf(query, "select * from testTable where 終點(diǎn)站='"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? ? ? strcat(query, s); ? ? ? ? strcat(query, abc); ? ? ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? mysql_query(&mysql, query); ? ?//執(zhí)行SQL語句 ? ? ? ? //獲取結(jié)果集 ? ? ? ? if (!(res = mysql_store_result(&mysql))) ? ?//獲得sql語句結(jié)束后返回的結(jié)果集 ? ? ? ? { ? ? ? ? ? ? printf("Couldn't get result from %s\n", mysql_error(&mysql)); ? ? ? ? ? ? return false; ? ? ? ? } ? ? ? ? for (int i = 0; fd = mysql_fetch_field(res); i++) ?//獲取字段名 ? ? ? ? ? ? strcpy(field[i], fd->name); ? ? ? ? int j = mysql_num_fields(res); ?// 獲取列數(shù) ? ? ? ? printf("\n"); ? ? ? ? for (int i = 0; i < j; i++) ?//打印字段 ? ? ? ? ? ? printf("%10s\t", field[i]); ? ? ? ? printf("\n"); ? ? ? ? while (column = mysql_fetch_row(res)) ? ? ? ? { ? ? ? ? ? ? printf("%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\n", column[0], column[1], column[2], column[3], column[4], column[5], column[6], column[7]); ?//column是列數(shù)組 ? ? ? ? } ? ? } ? ? printf("\n"); ? ? printf(" ?1 繼續(xù)查詢;2 返回主界面\n"); ? ? printf(" 請(qǐng)輸入您的操作: "); ? ? cin >> y; ? ? if (y == 1) ? ? { ? ? ? ? search(); ? ? } ? ? else if (y == 2) ? ? { ? ? ? ? mainmenu(); ? ? } ? ? return true; } //錄入數(shù)據(jù) bool input() { ? ? sprintf(query, "insert into testtable values (6, '18:00', '青島','濟(jì)南',3,20,10,'NULL')"); ?//可以想辦法實(shí)現(xiàn)手動(dòng)在控制臺(tái)手動(dòng)輸入指令 ? ? mysql_query(&mysql, query); ? ? ?//執(zhí)行SQL語句 ? ? ? ? printf(" Insert success\n"); ? ? ? ? read(); ? ? ? ? return true; ? ?? } //售票和退票 bool piao() { ? int y; ? ? int m,a,b; ? ? char n[5]; ? ? char k[5]; ? ? char abc[5] = "'"; ? ? char cc[100] = " where 班次='"; ? ? printf(" 請(qǐng)選擇操作:1 售票;2 退票"); ? ? cout << endl; ? ? printf(" 請(qǐng)輸入: "); ? ? cin >> m; ? ? if (m == 1)//售票 ? ? { ? ? ? ? printf(" 請(qǐng)輸入您要購買的車票班次: ?"); ? ? ? ? cin >> k; ? ? ? ? sprintf(query, "select * from testtable where 班次='"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? ? ? strcat(query, k); ? ? ? ? strcat(query, abc); ? ? ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? mysql_query(&mysql, query); ? ?//執(zhí)行SQL語句 ? ? ? ? //獲取結(jié)果集 ? ? ? ? if (!(res = mysql_store_result(&mysql))) ? ?//獲得sql語句結(jié)束后返回的結(jié)果集 ? ? ? ? { ? ? ? ? ? ? printf("Couldn't get result from %s\n", mysql_error(&mysql)); ? ? ? ? ? ? return false; ? ? ? ? } ? ? ? ? for (int i = 0; fd = mysql_fetch_field(res); i++) ?//獲取字段名 ? ? ? ? ? ? strcpy(field[i], fd->name); ? ? ? ? int j = mysql_num_fields(res); ?// 獲取列數(shù) ? ? ? ?? ? ? ? ? column = mysql_fetch_row(res); ? ? ? ? a = atoi(column[6]); ? ? ? ? b = atoi(column[5]); ? ? ? ? if ((a < b) && (!strcmp(column[7],"此車未發(fā)出"))) ? ? ? ? { ? ? ? ? ? ? printf("\n"); ? ? ? ? ? ? printf("售票成功\n"); ? ? ? ? ? ? printf("\n"); ? ? ? ? for (int i = 0; i < j; i++) ?//打印字段 ? ? ? ? ? ? printf("%10s\t", field[i]); ? ? ? ? printf("\n"); ? ? ? ? ? ? a = a + 1; ? ? ? ? ? ? itoa(a,column[6],10); ? ? ? ? ? ? sprintf(query, "update testtable set 已訂票人數(shù)='"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? ? ? ? ? strcat(query, column[6]); ? ? ? ? ? ?strcat(query, abc); ? ? ? ? ? ?strcat(query, cc); ? ? ? ? ? ? ?strcat(query, k); ? ? ? ? ? ? ?strcat(query, abc); ? ? ? ? ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? ? ? mysql_query(&mysql, query); ? ?//執(zhí)行SQL語句 ? ? ?? ? ? ? ? ? ? ? ? printf("%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\n", column[0], column[1], column[2], column[3], column[4], column[5], column[6], column[7]); ?//column是列數(shù)組 ? ? ? ? } ? ? } ? ? else if (m == 2)//退票 ? ? { ? ? ? ?? ? ? ? ? printf(" 請(qǐng)輸入您要退訂的車票班次: ?"); ? ? ? ? cin >> n; ? ? ? ? sprintf(query, "select * from testtable where 班次='"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? ? ? strcat(query, n); ? ? ? ? strcat(query, abc); ? ? ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? mysql_query(&mysql, query); ? ?//執(zhí)行SQL語句 ? ? ? ? //獲取結(jié)果集 ? ? ? ? if (!(res = mysql_store_result(&mysql))) ? ?//獲得sql語句結(jié)束后返回的結(jié)果集 ? ? ? ? { ? ? ? ? ? ? printf("Couldn't get result from %s\n", mysql_error(&mysql)); ? ? ? ? ? ? return false; ? ? ? ? } ? ? ? ? ? ? ? ? for (int i = 0; fd = mysql_fetch_field(res); i++) ?//獲取字段名 ? ? ? ? ? ? strcpy(field[i], fd->name); ? ? ? ? int j = mysql_num_fields(res); ?// 獲取列數(shù) ? ? ? ?? ? ? ? ? column = mysql_fetch_row(res); ? ? ? ? a = atoi(column[6]); ? ? ? ? if (!strcmp(column[7], "此車未發(fā)出")) ? ? ? ? { ? ? ? ? ? ? printf("\n"); ? ? ? ? ? ? printf("退票成功\n"); ? ? ? ? ? ? printf("\n"); ? ? ? ? for (int i = 0; i < j; i++) ?//打印字段 ? ? ? ? ? ? printf("%10s\t", field[i]); ? ? ? ? printf("\n"); ? ? ? ? ? ? a = a - 1; ? ? ? ? ? ? itoa(a, column[6], 10); ? ? ? ? ? ? sprintf(query, "update testtable set 已訂票人數(shù)='"); //執(zhí)行查詢語句,這里是查詢所有,user是表名,不用加引號(hào),用strcpy也可以 ? ? ? ? ? ? strcat(query, column[6]); ? ? ? ? ? ? strcat(query, abc); ? ? ? ? ? ? strcat(query, cc); ? ? ? ? ? ? strcat(query, n); ? ? ? ? ? ? strcat(query, abc); ? ? ? ? ? ? mysql_query(&mysql, "set names gbk"); //設(shè)置編碼格式(SET NAMES GBK也行),否則cmd下中文亂碼 ? ? ? ? ? ? mysql_query(&mysql, query); ? ?//執(zhí)行SQL語句 ? ? ? ? ? ? printf("%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\n", column[0], column[1], column[2], column[3], column[4], column[5], column[6], column[7]); ?//column是列數(shù)組 ? ? ? ? } ? ? ? ? ? ?? ? ? ? ?? ? ? } ? ? printf("\n"); ? ? printf(" ?1 繼續(xù)售票/退票;2 返回主界面\n"); ? ? printf(" 請(qǐng)輸入您的操作: "); ? ? ? ? cin >> y; ? ? ? ? if (y == 1) ? ? ? ? { ? ? ? ? ? ? piao(); ? ? ? ? } ? ? ? ? else if (y == 2) ? ? ? ? { ? ? ? ? ? ? mainmenu(); ? ? ? ? } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Objective-C的內(nèi)省(Introspection)用法小結(jié)
這篇文章主要介紹了Objective-C的內(nèi)省(Introspection)用法,這是面向?qū)ο笳Z言和環(huán)境的一個(gè)強(qiáng)大特性,需要的朋友可以參考下2014-07-07C++中的動(dòng)態(tài)規(guī)劃子序列問題分析探討
可能有些讀者有接觸過動(dòng)態(tài)規(guī)劃,可能也有一些讀者以前完全不知道動(dòng)態(tài)規(guī)劃這個(gè)東西,別擔(dān)心,我這篇文章會(huì)為讀者做一個(gè)入門,好讓讀者掌握這個(gè)重要的知識(shí)點(diǎn)2023-03-03C++實(shí)現(xiàn)LeetCode(44.外卡匹配)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(44.外卡匹配),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07