发布时间:2023-10-24 09:57来源:www.sf1369.com作者:宇宇
车票系统,与你的第2题要求略有不同,你自己修改吧
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
#include<含尺time.h>
#include<conio.h>
#include<string.h>
const int MAX=20;
const int N=50;
const int MAXFILENAME=100;
enum {FALSE,TRUE};
struct time
{
int hour;
int minutes;
};
struct ticket
{
int SerialNumber;
struct time SetOut;
char DeparturePoint[MAX];
char TerminalPoint[MAX];
float LastTime;
int FixNumber;
int FixedNumber;
}car[N];
int RecordNumber;
int FLAG=FALSE;
/**********************************************/
int ShowMessage(void); //载入原始数据
void mainmenu(void); //主菜单
void InsertMessage(void); /升卜/录入班次信息
void SearchMenu(void); //查询路线子菜单
void SearchByNumber(void); //按班次号查询
void SearchByAddress(void); //按终点站查询
void TicketManagement(void); //车票售出与退回
void TicketOrder(void); //售票
void TicketDelete(void); //退票
void exit(void); //退出该系吵老穗统
/********************************************/
int main(void)
{
RecordNumber=ShowMessage();
if(1)
do{
mainmenu();
}while(FLAG==FALSE);
return 0;
}
void mainmenu(void)
{
system(color 1f);
system(mode con: cols=140 lines=130);
char functionNumber;
printf( 车票管理系统\n\n);
printf( 制作:hmm182007\n);
printf( 日期:2007/11/25/19:57\n);
printf(============================================================================\n);
printf( 1.录入班次信息\t\n);
printf( 2.浏览班次信息\t\n);
printf( 3.查询行车路线\t\n);
printf( 4.售票与退票系统\t\n);
printf( 5.退出该系统\t\n);
printf(============================================================================\n);
printf(请选择你所需要的功能:);
scanf(%c,&functionNumber);
switch(functionNumber)
{
case '1':
{
InsertMessage();
printf(\n按任意键回主菜单......\n);
getchar();
getchar();
}
break;
case '2':
{
ShowMessage();
printf(\n按任意键回主菜单......\n);
getchar();
getchar();
}
break;
case '3':
{
SearchMenu();
printf(\n按任意键回主菜单......\n);
getchar();
getchar();
}
break;
case '4':
{
TicketManagement();
getchar();
getchar();
}
break;
case '5':FLAG=TRUE;exit();break;
default:
{
printf(输入错误,请确保你的输入为1--5.\n);
printf(按任意键回主菜单......\n);
getchar();
getchar();
}
}//switch ends
FLAG=FALSE;
}
void InsertMessage(void)
{
FILE *fp;
char filename[MAXFILENAME];
int i;
printf(请输入文件名或者文件路径名:);
scanf(%s,filename);
if((fp=fopen(filename,r))==NULL)
{
printf(文件%s不可读,请确认文件%s存在或者文件路径正确.\n\n,filename,filename);
mainmenu();
}
for(i=RecordNumber;!feof(fp)&&!ferror(fp);i++)
{
fscanf(fp,%d%d%d,&car[i].SerialNumber,&car[i].SetOut.hour,&car[i].SetOut.minutes);
fscanf(fp,%s%s%f%d%d,&car[i].DeparturePoint,&car[i].TerminalPoint,&car[i].LastTime,&car[i].FixNumber,&car[i].FixedNumber);
}
int count=i;
printf(班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n);
for(i=0;i<count;i++)
{
printf(%d\t%d:%d\t\t,car[i].SerialNumber,car[i].SetOut.hour,car[i].SetOut.minutes);
printf(%s\t%s\t\t%.1f\t %d\t\t%d\n,car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,car[i].FixNumber,car[i].FixedNumber);
}
fclose(fp);
}
int ShowMessage(void)
{
int i;
FILE *fp;
if((fp=fopen(add.txt,r))==NULL)
{
printf(读取数据失败,请检查文件add.txt是否存在.\n);
exit(-1);
}
for(i=0;!feof(fp)&&!ferror(fp);i++)
{
fscanf(fp,%d%d%d,&car[i].SerialNumber,&car[i].SetOut.hour,&car[i].SetOut.minutes);
fscanf(fp,%s%s%f%d%d,&car[i].DeparturePoint,&car[i].TerminalPoint,&car[i].LastTime,&car[i].FixNumber,&car[i].FixedNumber);
}
int count=i;
printf(班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n);
for(i=0;i<count;i++)
{
printf(%d\t%d:%d\t\t,car[i].SerialNumber,car[i].SetOut.hour,car[i].SetOut.minutes);
printf(%s\t%s\t\t%.1f\t %d\t\t%d\n,car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,car[i].FixNumber,car[i].FixedNumber);
}
return count;
}
void SearchMenu(void)
{
system(color 1f);
system(mode con: cols=140 lines=130);
char functionNumber;
printf( 查询子菜单\n);
printf(============================================================================\n);
printf( 1.按班次号查询\t\n);
printf( 2.按终点站查询\t\n);
printf( 3.返回主菜单\t\n);
printf(============================================================================\n);
printf(请选择你所需要的功能:);
scanf(%*c%c,&functionNumber);
switch(functionNumber)
{
case '1':SearchByNumber();break;
case '2':SearchByAddress();break;
case '3':
getchar();
mainmenu();
break;
default:
printf(输入错误,请确保你的输入为1--3.\n);
printf(按任意键回查询子菜单......\n);
getchar();
getchar();
SearchMenu();
}
}
void SearchByNumber(void)
{
int SearchNumber;
printf(请输入要查询的班次号:);
scanf(%d,&SearchNumber);
printf(班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n);
printf(%d\t%d:%d\t\t,car[SearchNumber-1].SerialNumber,car[SearchNumber-1].SetOut.hour,car[SearchNumber-1].SetOut.minutes);
printf(%s\t%s\t\t%.1f\t %d\t\t%d\n,car[SearchNumber-1].DeparturePoint,car[SearchNumber-1].TerminalPoint,car[SearchNumber-1].LastTime,car[SearchNumber-1].FixNumber,car[SearchNumber-1].FixedNumber);
}
void SearchByAddress(void)
{
int i;
char Address[MAX];
printf(请输入终点站的名称:);
scanf(%s,&Address);
printf(班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n);
for(i=0;i<RecordNumber;i++)
{
//对比终点站记录,找到并输出
if((strcmp(Address,car[i].TerminalPoint))==0)
{
printf(%d\t%d:%d\t\t,car[i].SerialNumber,car[i].SetOut.hour,car[i].SetOut.minutes);
printf(%s\t%s\t\t%.1f\t %d\t\t%d\n,car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,car[i].FixNumber,car[i].FixedNumber);
}
}
}
void TicketManagement(void)
{
char functionNumber;
system(color 1f);
system(mode con: cols=140 lines=130);
printf( 订票与退票菜单\n);
printf(============================================================================\n);
printf( 1.订票\t\n);
printf( 2.退票\t\n);
printf( 3.返回主菜单.\n);
printf(============================================================================\n);
printf(选择你需要的功能:);
scanf(%*c%c,&functionNumber);
switch(functionNumber)
{
case '1':
{
TicketOrder();
//getchar();
//getchar();
}
break;
case '2':TicketDelete();break;
case '3':
{
getchar();
mainmenu();
}
break;
default:
{
printf(输入错误,请确保你的输入为1--3.\n);
printf(按任意键回主菜单......\n);
getchar();
getchar();
mainmenu();
}
}
}
void TicketOrder(void)
{
int i;
printf(请输入要订购的车票的班次:);
scanf(%d,&i);
if(i<0||i>RecordNumber)
{
printf(对不起,今天没有这趟车,请明天再来,谢谢使用!\n);
printf(按任意键回主菜单......\n);
getchar();//getchar();
TicketManagement();
}
time_t tval;
struct tm *now;
tval = time(NULL);
now = localtime(&tval);
if((now->tm_hour==car[i].SetOut.hour&&now->tm_min<car[i].SetOut.minutes)||(now->tm_hour<car[i].SetOut.hour))
{
if(car[i].FixedNumber<car[i].FixNumber)
{
car[i].FixedNumber++;
printf(你的订票成功,请按时上车,谢谢使用!\n);
}
else printf(对不起,今天的这趟车的票已卖完,请明天再来,谢谢合作!\n);
}
else printf(对不起,今天的这趟车已发出,请明天再来,谢谢合作!\n);
printf(班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n);
printf(%d\t%d:%d\t\t,car[i-1].SerialNumber,car[i-1].SetOut.hour,car[i-1].SetOut.minutes);
printf(%s\t%s\t\t%.1f\t %d\t\t%d\n,car[i-1].DeparturePoint,car[i-1].TerminalPoint,car[i-1].LastTime,car[i-1].FixNumber,car[i-1].FixedNumber);
//printf(按任意键回主菜单......\n);
//getchar();getchar();
}
void TicketDelete(void)
{
int i;
printf(请输入要退购的车票的班次:);
scanf(%d,&i);
if(i<0||i>RecordNumber)
{
printf(对不起,今天没有这趟车,无法完成退票.谢谢使用!\n);
getchar();
//getchar();
TicketManagement();
getchar();
}
time_t tval;
struct tm *now;
tval = time(NULL);
now = localtime(&tval);
if((now->tm_hour==car[i].SetOut.hour&&now->tm_min<car[i].SetOut.minutes)||(now->tm_hour<car[i].SetOut.hour))
{
if(car[i].FixedNumber>=1)
{
car[i].FixedNumber--;
printf(退订车票成功,谢谢使用!\n);
}
else printf(对不起,今天的这趟车的票尚未卖出,无法完成退票!\n);
}
else printf(对不起,今天的这趟车已发出,无法完成退票!\n);
printf(班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n);
printf(%d\t%d:%d\t\t,car[i-1].SerialNumber,car[i-1].SetOut.hour,car[i-1].SetOut.minutes);
printf(%s\t%s\t\t%.1f\t %d\t\t%d\n,car[i-1].DeparturePoint,car[i-1].TerminalPoint,car[i-1].LastTime,car[i-1].FixNumber,car[i-1].FixedNumber);
getchar();//getchar();
}
void exit(void)
{
printf(\n\n*********************谢谢使用本系统,欢迎下次继续使用***********************\n);
exit(0);
}
运动会分数统计
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NULL 0
#define MaxSize 30
typedef struct athletestruct /*运动员*/
{
char name[20];
int score; /*分数*/
int range; /**/
int item; /*项目*/
}ATH;
typedef struct schoolstruct /*学校*/
{
int count; /*编号*/
int serial; /**/
int menscore; /*男选手分数*/
int womenscore; /*女选手分数*/
int totalscore; /*总分*/
ATH athlete[MaxSize]; /**/
struct schoolstruct *next;
}SCH;
int nsc,msp,wsp;
int ntsp;
int i,j;
int overgame;
int serial,range;
int n;
SCH *head,*pfirst,*psecond;
int *phead=NULL,*pafirst=NULL,*pasecond=NULL;
input ()
{
char answer;
head = (SCH *)malloc(sizeof(SCH)); /**/
head->next = NULL;
pfirst = head;
answer = 'y';
while ( answer == 'y' )
{
Is_Game_DoMain:
printf(\nGET Top 5 when odd\nGET Top 3 when even);
printf(\n输入运动项目序号 (x<=%d):让段,ntsp);
scanf(%d,pafirst);
overgame = *pafirst;
if ( pafirst != phead )
{
for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )
{
if ( overgame == *pasecond )
{
printf(\n这个项目已经存在请选择其他的数字\n);
goto Is_Game_DoMain;
}
}
}
pafirst = pafirst + 1;
if ( overgame > ntsp )
{
printf(\n项目不存在);
printf(\n请重新输入);
goto Is_Game_DoMain;
}
switch ( overgame%2 )
{
case 0: n = 3;break;
case 1: n = 5;break;
}
for ( i = 1 ; i <= n ; i++ )
{
Is_Serial_DoMain:
printf(\n输入序号 of the NO.%d (0<陵滑樱x<=%d): ,i,nsc);
scanf(%d,&serial);
if ( serial > nsc )
{
printf(\n超过学校数目,请重新输入);
goto Is_Serial_DoMain;
}
if ( head->next == NULL )
{
create();
}
psecond = head->next ;
while ( psecond != NULL )
{
if ( psecond->serial == serial )
{
pfirst = psecond;
pfirst->尺丛count = pfirst->count + 1;
goto Store_Data;
}
else
{
psecond = psecond->next;
}
}
create();
Store_Data:
pfirst->athlete[pfirst->count].item = overgame;
pfirst->athlete[pfirst->count].range = i;
pfirst->serial = serial; (Input name:) : );
scanf(%s,pfirst->athlete[pfirst->count].name);
}
printf(\n继续输入运动项目(y&n)?);
answer = getch();
printf(\n);
}
}
calculate() /**/
{
pfirst = head->next;
while ( pfirst->next != NULL )
{
for (i=1;i<=pfirst->count;i++)
{
if ( pfirst->athlete[i].item % 2 == 0 )
{
switch (pfirst->athlete[i].range)
{
case 1:pfirst->athlete[i].score = 5;break;
case 2:pfirst->athlete[i].score = 3;break;
case 3:pfirst->athlete[i].score = 2;break;
}
}
else
{
switch (pfirst->athlete[i].range)
{
case 1:pfirst->athlete[i].score = 7;break;
case 2:pfirst->athlete[i].score = 5;break;
case 3:pfirst->athlete[i].score = 3;break;
case 4:pfirst->athlete[i].score = 2;break;
case 5:pfirst->athlete[i].score = 1;break;
}
}
if ( pfirst->athlete[i].item <=msp )
{
pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score;
}
else
{
pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score;
}
}
pfirst->totalscore = pfirst->menscore + pfirst->womenscore;
pfirst = pfirst->next;
}
}
output()
{
pfirst = head->next;
psecond = head->next;
while ( pfirst->next != NULL )
{
clrscr();
printf(\n第%d号学校的结果成绩:,pfirst->serial);
printf(\n\n项目的数目\t学校的名字\t分数);
for (i=1;i<=ntsp;i++)
{
for (j=1;j<=pfirst->count;j++)
{
if ( pfirst->athlete[j].item == i )
{
printf(\n %d\t\t\t\t\t\t%s\n %d,i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;
}
}
}
printf(\n\n\n\t\t\t\t\t\t按任意建 进入下一页);
getch();
pfirst = pfirst->next;
}
clrscr();
printf(\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分);
pfirst = head->next;
while ( pfirst->next != NULL )
{
printf(\n %d\t\t %d\t\t %d\t\t %d,pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);
pfirst = pfirst->next;
}
printf(\n\n\n\t\t\t\t\t\t\t按任意建结束);
getch();
}
create()
{
pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));
pfirst->next = head->next ;
head->next = pfirst ;
pfirst->count = 1;
pfirst->menscore = 0;
pfirst->womenscore = 0;
pfirst->totalscore = 0;
}
void Save()
{FILE *fp;
if((fp = fopen(school.dat,wb))==NULL)
{printf(can't open school.dat\n);
fclose(fp);
return;
}
fwrite(pfirst,sizeof(SCH),10,fp);
fclose(fp);
printf(文件已经成功保存\n);
}
main()
{
system(cls);
printf(\n\t\t\t 运动会分数统计\n);
printf(输入学校数目 (x>= 5):);
scanf(%d,&nsc);
printf(输入男选手的项目(x<=20):);
scanf(%d,&msp);
printf(输入女选手项目(<=20):);
scanf(%d,&wsp);
ntsp = msp + wsp;
phead = calloc(ntsp,sizeof(int));
pafirst = phead;
pasecond = phead;
input();
calculate();
output();
Save();
}
懒得够可以的....
二级考试书里有很典型的民航定飘系统的题目,到图书管找去
我们当初也有这道题,一模一样,所以发给你了。再加点分哦。