C語言實(shí)現(xiàn)車票管理系統(tǒng)
本文實(shí)例為大家分享了C語言實(shí)現(xiàn)車票管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、項(xiàng)目簡介
設(shè)計(jì)一個(gè)車票管理系統(tǒng)實(shí)現(xiàn)錄入、查看班次信息,售票,退票等基本功能。設(shè)計(jì)中要求綜合運(yùn)用所學(xué)知識,上機(jī)解決一些與實(shí)際應(yīng)用結(jié)合緊密的、規(guī)模較大的問題,通過分析、設(shè)計(jì)、編碼、調(diào)試等各環(huán)節(jié)
二、任務(wù)概述
(1)錄入班次信息(信息用文件保存),可不定時(shí)地增加班次數(shù)據(jù)
(2)瀏覽班次信息,可顯示出所有班次當(dāng)前狀總。
(3)查詢路線:可按班次號查詢 ,可按終點(diǎn)站查詢
(4)售票和退票功能
A:當(dāng)查詢出已定票人數(shù)小于額定載量且當(dāng)前系統(tǒng)時(shí)間小于發(fā)車時(shí)間時(shí)才能售票,自動更新已售票人數(shù)
B:退票時(shí),輸入退票的班次,當(dāng)本班車未發(fā)出時(shí)才能退票,自動更新已售票人數(shù)
【數(shù)據(jù)結(jié)構(gòu)】
本程序用到2個(gè)結(jié)構(gòu)體,方便信息的錄入,瀏覽,查詢,訂票與退票,等功能的實(shí)現(xiàn)。
三、功能展示
四、思維導(dǎo)圖
五、程序源碼
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <dos.h> #include <conio.h> #include <time.h> #define FALSE 0? #define TRUE 1 void mainmenu(void); //主菜單函數(shù) void InputMessage(void);//輸入信息函數(shù) void ShowMessage(void);//顯示信息函數(shù) void SearchMessage(void);//查詢信息函數(shù) void searchbynumber();//根據(jù)班次號查詢函數(shù) void searchbyaddress();//根據(jù)終點(diǎn)站查詢的函數(shù) void TicketManagement(void);//選擇訂票/退票的函數(shù) void TicketOrder();//訂票實(shí)現(xiàn)函數(shù) void TicketDelete();//退票實(shí)現(xiàn)函數(shù) int FLAG;//標(biāo)志 struct time//時(shí)間結(jié)構(gòu)體 { int hour; int minutes; }; struct ticket//車票的結(jié)構(gòu)體 { int carnumber;//車次 struct time setout; char beginpoint[20];//起點(diǎn)站 char endpoint[20];//終點(diǎn)站 float lasttime;//行車時(shí)間 int fixnumber;//額定載量 int fixednumber;//已定票的人數(shù) }car[4]; int main() {int FLAG=FALSE; do{mainmenu(); }while(FLAG=FALSE); } void mainmenu() {char functioNnumber; printf(" 車票管理系統(tǒng)\n\n"); printf("=============================================================\n"); printf(" 1.錄入班次信息\t\n"); printf(" 2.瀏覽班次信息\t\n"); printf(" 3.查詢行車路線\t\n"); printf(" 4.售票與退票系統(tǒng)\t\n"); printf(" 5.退出該系統(tǒng)\t\n"); printf("=============================================================\n"); printf("請選擇你所需要的功能:"); scanf("%s",&functioNnumber);switch(functioNnumber) { case '1': {system("cls");InputMessage(); printf("\n按任意鍵返回主菜單\n"); getchar(); getchar(); mainmenu(); };break; case '2':{ system("cls");ShowMessage(); printf("\n按任意鍵返回主菜單\n"); getchar(); getchar(); mainmenu(); };break; case '3': { system("cls");SearchMessage(); printf("\n按任意鍵返回主菜單\n"); getchar(); getchar(); mainmenu(); };break; case '4': {system("cls");TicketManagement(); printf("\n按任意鍵返回主菜單\n"); getchar(); getchar(); mainmenu(); };break; case '5':FLAG=TRUE; printf("*****************************感謝使用本系統(tǒng)***********************************************"); exit(0); break; default: { printf("對不起你的輸入有誤,請確保你的輸入為1-5.\n"); printf("按任意鍵返回主菜單\n"); getchar(); getchar();? mainmenu(); }; }; FLAG=FALSE; } void InputMessage() {int i; for(i=0;i<4;i++)//一次錄入四班車 {printf("請輸入班次號:\n"); scanf("%d",&car[i].carnumber); printf("請輸入發(fā)車時(shí)間:\n"); scanf("%d %d",&car[i].setout.hour,&car[i].setout.minutes); printf("請輸入起點(diǎn)站:\n"); scanf("%s",car[i].beginpoint); printf("請輸入終點(diǎn)站:\n"); scanf("%s",car[i].endpoint); printf("請輸入行車時(shí)間:\n"); scanf("%f",&car[i].lasttime); printf("請輸入額定載量:\n"); scanf("%d",&car[i].fixnumber); printf("請輸入已定票人數(shù):\n"); scanf("%d",&car[i].fixednumber); } for(i=0;i<4;i++) {printf("班次\t發(fā)車時(shí)間\t起點(diǎn)\t終點(diǎn)\t行車時(shí)間(小時(shí))\t額定載量\t已訂票人數(shù)\n"); printf("%d\t%d:%d\t",car[i].carnumber,car[i].setout.hour,car[i].setout.minutes); printf("%s\t%s\t%f\t%d\t%d\t\n",car[i].beginpoint,car[i].endpoint,car[i].lasttime,car[i].fixnumber,car[i].fixednumber); }} void ShowMessage() {int i; time_t tval; struct tm*now; tval=time(NULL); now=localtime(&tval);for(i=0;i<4;i++) {if((now->tm_hour==car[i].setout.hour&&now->tm_min<car[i].setout.minutes)||(now->tm_hour<car[i].setout.hour)) {printf("%d\t%d:%d\t",car[i].carnumber,car[i].setout.hour,car[i].setout.minutes); printf("%s\t%s\t%f\t%d\t%d\t\n",car[i].beginpoint,car[i].endpoint,car[i].lasttime,car[i].fixnumber,car[i].fixednumber);} else {printf("此車已出發(fā)。\n"); printf("%d\t%d:%d\t",car[i].carnumber,car[i].setout.hour,car[i].setout.minutes); printf("%s\t%s\t%f\t%d\t%d\t\n",car[i].beginpoint,car[i].endpoint,car[i].lasttime,car[i].fixnumber,car[i].fixednumber);} }} void SearchMessage() {char functionnumber; printf("查詢子菜單:\n"); printf("=========================================================================\n"); printf(" 1.按班次號查詢\n"); printf(" 2.按終點(diǎn)站查詢\n"); printf(" 3.返回主菜單\n"); printf("=========================================================================\n"); printf("請選擇你需要的功能:"); scanf("%s",&functionnumber); switch(functionnumber) { case '1':system("cls");searchbynumber();break; case '2':system("cls");searchbyaddress();break; case '3':system("cls");mainmenu();break; default:printf("輸入錯(cuò)誤,請確保你的輸入為1-3.\n"); printf("請按任意鍵返回查詢子菜單\n"); getchar(); getchar(); SearchMessage(); } } void searchbynumber() {int searchnumber; int s; printf("請輸入你要查詢的班次號:"); scanf("%d",&searchnumber); if(searchnumber>=1&&searchnumber<=4) {s=searchnumber-1; printf("班次\t發(fā)車時(shí)間\t起點(diǎn)\t終點(diǎn)\t行車時(shí)間(小時(shí))\t額定載量\t已訂票人數(shù)\n");printf("%d\t%d:%d\t",car[s].carnumber,car[s].setout.hour,car[s].setout.minutes); printf("%s\t%s\t%f\t%d\t%d\t\n",car[s].beginpoint,car[s].endpoint,car[s].lasttime,car[s].fixnumber,car[s].fixednumber);} else printf("對不起,沒有這趟車."); } void searchbyaddress() {int i; char address[20]; printf("請輸入終點(diǎn)站名:"); scanf("%s",address); for(i=0;i<=4;i++) if(strcmp(address,car[i].endpoint)==0) {printf("%d\t%d:%d\t",car[i].carnumber,car[i].setout.hour,car[i].setout.minutes); printf("%s\t%s\t%f\t%d\t%d\t\n",car[i].beginpoint,car[i].endpoint,car[i].lasttime,car[i].fixnumber,car[i].fixednumber); } } void TicketManagement() { char functionnumber; printf("==========================================================================\n"); printf(" 1.訂票.\n"); printf(" 2.退票.\n"); printf(" 3.返回主菜單.\n"); printf("==========================================================================\n"); printf("請選擇你需要的功能:\n"); scanf("%s",&functionnumber); switch(functionnumber) {case '1':system("cls"); TicketOrder();break; case '2':system("cls"); TicketDelete(); break; case '3':system("cls"); {mainmenu();}break; default: {printf("輸入錯(cuò)誤,請確保你的輸入為1--3.\n"); printf("按任意鍵返回子菜單.\n"); getchar();getchar(); TicketManagement(); } } } void TicketOrder() {int i; int s; printf("請輸入要訂購的車票的班次:\n"); scanf("%d",&i); s=i-1; if(s<0||s>3) {printf("對不起,沒有這趟車,請查詢后再訂票.\n"); printf("按任意鍵返回車票管理菜單。"); getchar(); getchar(); TicketManagement(); } else { time_t tval; struct tm*now; tval=time(NULL); now=localtime(&tval); if((now->tm_hour==car[s].setout.hour&&now->tm_min<car[s].setout.minutes)||(now->tm_hour<car[s].setout.hour)) {if(car[s].fixednumber<car[s].fixnumber) {car[s].fixednumber++; printf("你的訂票成功,請按時(shí)上車,謝謝使用!\n"); }else printf("對不起,今天的這趟車的票已賣完,請明天再來,謝謝合作!\n"); }else printf("對不起,今天的這趟車已出發(fā),請明天再來,謝謝合作!\n"); } printf("班次\t發(fā)車時(shí)間\t起點(diǎn)\t終點(diǎn)\t行車時(shí)間(小時(shí))\t額定載量\t已訂票人數(shù)\n"); printf("%d\t%d:%d\t",car[s].carnumber,car[s].setout.hour,car[s].setout.minutes); printf("%s\t%s\t%f\t%d\t%d\t",car[s].beginpoint,car[s].endpoint,car[s].lasttime,car[s].fixnumber,car[s].fixednumber); printf("按任意鍵返回主菜單。\n");getchar(); getchar(); } void TicketDelete() {int i; int s; printf("請輸入要退購的車票的班次:\n"); scanf("%d",&i); s=i-1; if(s<0||s>3) {printf("對不起,沒有這趟車,請查詢后再退票.\n"); printf("按任意鍵返回車票管理菜單。"); getchar(); getchar(); TicketManagement(); } else { time_t tval; struct tm*now; tval=time(NULL); now=localtime(&tval); if((now->tm_hour==car[s].setout.hour&&now->tm_min<car[s].setout.minutes)||(now->tm_hour<car[s].setout.hour)) {if(car[s].fixednumber<car[s].fixnumber) {car[s].fixednumber--; printf("退票成功,謝謝使用!\n"); }else printf("對不起,今天的這趟車的票尚未賣出,無法完成退票!\n"); }else printf("對不起,今天的這趟車已出發(fā),無法完成退票!\n"); } printf("班次\t發(fā)車時(shí)間\t起點(diǎn)\t終點(diǎn)\t行車時(shí)間(小時(shí))\t額定載量\t已訂票人數(shù)\n"); printf("%d\t%d:%d\t",car[s].carnumber,car[s].setout.hour,car[s].setout.minutes); printf("%s\t%s\t%f\t%d\t%d\t",car[s].beginpoint,car[s].endpoint,car[s].lasttime,car[s].fixnumber,car[s].fixednumber);`在這里插入代碼片` printf("按任意鍵返回主菜單。\n"); getchar(); getchar(); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C語言實(shí)現(xiàn)24點(diǎn)游戲計(jì)算器的示例代碼
24點(diǎn)是一種益智游戲,24點(diǎn)是把4個(gè)整數(shù)(一般是正整數(shù))通過加減乘除以及括號運(yùn)算,使最后的計(jì)算結(jié)果是24的一個(gè)數(shù)學(xué)游戲,24點(diǎn)可以考驗(yàn)人的智力和數(shù)學(xué)敏感性,它能在游戲中提高人們的心算能力。本文將用C語言實(shí)現(xiàn)這一游戲,感興趣的可以了解一下2022-08-08C++實(shí)現(xiàn)十六進(jìn)制字符串轉(zhuǎn)換為十進(jìn)制整數(shù)的方法
這篇文章主要介紹了C++實(shí)現(xiàn)十六進(jìn)制字符串轉(zhuǎn)換為十進(jìn)制整數(shù)的方法,涉及C++字符串與數(shù)制轉(zhuǎn)換的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07GCC 編譯使用動態(tài)鏈接庫和靜態(tài)鏈接庫的方法
根據(jù)鏈接時(shí)期的不同,庫又有靜態(tài)庫和動態(tài)庫之分,有別于靜態(tài)庫,動態(tài)庫的鏈接是在程序執(zhí)行的時(shí)候被鏈接的2013-03-03C語言結(jié)課設(shè)計(jì)之計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了C語言結(jié)課設(shè)計(jì)之計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02C++標(biāo)準(zhǔn)庫學(xué)習(xí)之weak_ptr智能指針用法詳解
這篇文章主要為大家詳細(xì)介紹了C++標(biāo)準(zhǔn)庫中weak_ptr智能指針用法的相關(guān)知識,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-12-12C++異常處理 try,catch,throw,finally的用法
這篇文章主要介紹了C++異常處理 try,catch,throw,finally的用法,需要的朋友可以參考下2018-01-01C/C++?實(shí)現(xiàn)動態(tài)資源文件釋放的方法
當(dāng)我們開發(fā)Windows應(yīng)用程序時(shí),通常會涉及到使用資源(Resource)的情況。資源可以包括圖標(biāo)、位圖、字符串等,它們以二進(jìn)制形式嵌入到可執(zhí)行文件中,這篇文章主要介紹了C/C++?實(shí)現(xiàn)動態(tài)資源文件釋放,需要的朋友可以參考下2023-12-12