C語言實現(xiàn)車票管理系統(tǒng)
本文實例為大家分享了C語言實現(xiàn)車票管理系統(tǒng)的具體代碼,供大家參考,具體內容如下
一、項目簡介
設計一個車票管理系統(tǒng)實現(xiàn)錄入、查看班次信息,售票,退票等基本功能。設計中要求綜合運用所學知識,上機解決一些與實際應用結合緊密的、規(guī)模較大的問題,通過分析、設計、編碼、調試等各環(huán)節(jié)
二、任務概述
(1)錄入班次信息(信息用文件保存),可不定時地增加班次數(shù)據(jù)
(2)瀏覽班次信息,可顯示出所有班次當前狀總。
(3)查詢路線:可按班次號查詢 ,可按終點站查詢
(4)售票和退票功能
A:當查詢出已定票人數(shù)小于額定載量且當前系統(tǒng)時間小于發(fā)車時間時才能售票,自動更新已售票人數(shù)
B:退票時,輸入退票的班次,當本班車未發(fā)出時才能退票,自動更新已售票人數(shù)
【數(shù)據(jù)結構】
本程序用到2個結構體,方便信息的錄入,瀏覽,查詢,訂票與退票,等功能的實現(xiàn)。
三、功能展示
四、思維導圖
五、程序源碼
#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ù)終點站查詢的函數(shù) void TicketManagement(void);//選擇訂票/退票的函數(shù) void TicketOrder();//訂票實現(xiàn)函數(shù) void TicketDelete();//退票實現(xiàn)函數(shù) int FLAG;//標志 struct time//時間結構體 { int hour; int minutes; }; struct ticket//車票的結構體 { int carnumber;//車次 struct time setout; char beginpoint[20];//起點站 char endpoint[20];//終點站 float lasttime;//行車時間 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ā)車時間:\n"); scanf("%d %d",&car[i].setout.hour,&car[i].setout.minutes); printf("請輸入起點站:\n"); scanf("%s",car[i].beginpoint); printf("請輸入終點站:\n"); scanf("%s",car[i].endpoint); printf("請輸入行車時間:\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ā)車時間\t起點\t終點\t行車時間(小時)\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.按終點站查詢\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("輸入錯誤,請確保你的輸入為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ā)車時間\t起點\t終點\t行車時間(小時)\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("請輸入終點站名:"); 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("輸入錯誤,請確保你的輸入為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("你的訂票成功,請按時上車,謝謝使用!\n"); }else printf("對不起,今天的這趟車的票已賣完,請明天再來,謝謝合作!\n"); }else printf("對不起,今天的這趟車已出發(fā),請明天再來,謝謝合作!\n"); } printf("班次\t發(fā)車時間\t起點\t終點\t行車時間(小時)\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ā)車時間\t起點\t終點\t行車時間(小時)\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(); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C++實現(xiàn)十六進制字符串轉換為十進制整數(shù)的方法
這篇文章主要介紹了C++實現(xiàn)十六進制字符串轉換為十進制整數(shù)的方法,涉及C++字符串與數(shù)制轉換的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07GCC 編譯使用動態(tài)鏈接庫和靜態(tài)鏈接庫的方法
根據(jù)鏈接時期的不同,庫又有靜態(tài)庫和動態(tài)庫之分,有別于靜態(tài)庫,動態(tài)庫的鏈接是在程序執(zhí)行的時候被鏈接的2013-03-03C++異常處理 try,catch,throw,finally的用法
這篇文章主要介紹了C++異常處理 try,catch,throw,finally的用法,需要的朋友可以參考下2018-01-01C/C++?實現(xiàn)動態(tài)資源文件釋放的方法
當我們開發(fā)Windows應用程序時,通常會涉及到使用資源(Resource)的情況。資源可以包括圖標、位圖、字符串等,它們以二進制形式嵌入到可執(zhí)行文件中,這篇文章主要介紹了C/C++?實現(xiàn)動態(tài)資源文件釋放,需要的朋友可以參考下2023-12-12