火车票管理系统程序设计

hongdong0913 2012-06-26 05:11:11
编译时出现了一些问题,哪位大哥来帮帮我吧。
Compiling...
xx.c
C:\Users\Administrator\Desktop\xx\xx.c(24) : warning C4013: 'printf' undefined; assuming extern returning int
C:\Users\Administrator\Desktop\xx\xx.c(33) : fatal error C1083: Cannot open include file: 'node.h': No such file or directory
Error executing cl.exe.

xx.obj - 1 error(s), 1 warning(s)
源代码如下(百度文库里的)
#ifndef _NODE_H_
#define _NODE_H_
struct Train_Information
{
char TrainNum[15];
char StartTime[20];
char StartPlace[20];
char EndPlace[20];
char TimeCost[15];
int LNP; //额定载量
int tickets;
};
typedef struct Train_Information Type;
const int sizeInfo=sizeof(Type);
struct node
{
Type data;
struct node *next;
};
const int size=sizeof(struct node);

void showstar()
{
printf("*************************************************\n");
}
#endif


#ifndef _LIST_H_
#define _LIST_H_
#include <string.h>
#include <time.h>
#include "node.h"
char tbuffer[9];

struct node* Delete(struct node* head); //根据姓名删除班车表中某车次所有信息
struct node* Insertafter(struct node* head,Type data); //读入后后插法建链
int printeverybody(struct node* head); //打印班车表
struct node* Addone(struct node* head); //添加车次
struct node* Edit(struct node* head); //编辑修改车次信息
struct node* SortST(struct node* head); //发车时间排序函数
struct node* SearchTic(struct node* head); //查询售票情况
struct node* SellTic(struct node* head); //售退票函数

void saveFileSort(struct node* head)
{
struct node *p=head;
FILE *fp;
if((fp=fopen("sort.dat","w"))==NULL)
{
printf("打不开\n");
exit(0);
}
if(head==NULL)
{
printf("没东西。。存不了!!");
return;
}
while(p)
{
fprintf(fp,"%s%s%s%s%s%d%d",(p->data).TrainNum,(p->data).StartTime,(p->data).StartPlace,(p->data).EndPlace,(p->data).TimeCost
,(p->data).LNP,(p->data).tickets);
p=p->next;
}
fclose(fp);
}

struct node* Delete(struct node* head)
{
if(head==NULL)
{
printf("没东西。。删除不起来!!");
return head;
}
getchar();
char p[30];
printf("请输入您要删除的车次:\n");
gets(p);
struct node *a=head,*b=NULL;
if(head==NULL)
{
printf("\n班车表中没有数据\n");
return head;
}
while(a&&strcmp(p,(a->data).TrainNum))
{
b=a;
a=a->next;
}
if(a)
{
if(b)
b->next=a->next;
else
head=head->next;
free(a);
printf("已经删除该车次的所有信息。\n\n\n");
}
else
printf("\n您所查找车次不在班车表中\n\n\n");
return head;
}




struct node* Insertafter(struct node* head,Type x)
{
struct node *p,*p1;
p=(struct node*)malloc(size);
p->data=x;
p->next=NULL;
if(head==NULL)
{
head=p;
return head;
}
p1=head;
while(p1->next)
{
p1=p1->next;
}
p1->next=p;
return head;
}



struct node* Addone(struct node* head)
{
struct node *p,*p1;
p=(struct node*)malloc(size);
printf("请输入车次号\n");
scanf("%s",(p->data).TrainNum);
printf("请输入起始时间\n");
scanf("%s",(p->data).StartTime);
printf("请输入发车地点\n");
scanf("%s",(p->data).StartPlace);
printf("请输入到达地点\n");
scanf("%s",(p->data).EndPlace);
printf("请输入行驶时间\n");
scanf("%s",(p->data).TimeCost);
printf("请输入额定载量\n");
scanf("%d",&(p->data).LNP);
printf("请输入可售票数量\n");
scanf("%d",&(p->data).tickets);
p->next=NULL;
if(head==NULL)
{
head=p;
return head;
}
p1=head;
while(p1->next)
{
p1=p1->next;
}
p1->next=p;
printf("********************\n");
printf(" 插入成功\n");
printf("********************\n");
return head;
}


struct node* Edit(struct node* head)
{
int choice;
getchar();
char p[30];
printf("请输入您要修改的车次号:\n");
gets(p);
struct node *a=head,*b=NULL;
if(head==NULL)
{
printf("\n班车表中没有数据\n");
return head;
}
while(a&&strcmp(p,(a->data).TrainNum))
{
b=a;
a=a->next;
}
if(a)
{
printf("请选择您要求更改的项:\n");
printf("--------1.车次号-------------\n");
printf("--------2.起始时间-----------\n");
printf("--------3.发车地点-----------\n");
printf("--------4.到达地点-----------\n");
printf("--------5.行驶时间-----------\n");
printf("--------6.额定载量-----------\n");
printf("--------7.余票量-------------\n");
printf("--------0.不改了-------------\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("车次号:"); scanf("%s",(a->data).TrainNum); break;
case 2: printf("起始时间:"); scanf("%s",(a->data).StartTime); break;
case 3: printf("发车地点:"); scanf("%s",(a->data).StartPlace); break;
case 4: printf("到达地点:"); scanf("%s",(a->data).EndPlace); break;
case 5: printf("行驶时间:"); scanf("%s",(a->data).TimeCost); break;
case 6: printf("额定载量:"); scanf("%d",&(a->data).LNP); break;
case 7: printf("余票量:"); scanf("%d",&(a->data).tickets); break;
case 0: break;
}
printf("搞定!\n");

}
else
printf("\n您所查找的车次不在班车表中\n\n\n");
return head;

}



...全文
353 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongdong0913 2012-06-26
  • 打赏
  • 举报
回复
int printeverybody(struct node* head)
{
struct node *p;
if (head==NULL)
{
printf("班车表中没有信息\n");
return 0;
}
showstar();
printf("\t车次 发车时间 起点站 终点站 行车时间 额定载量 余票数量\n");

_strtime( tbuffer ); //获取系统时间

for(p=head;p;p=p->next)
{

printf("\t%-10s%-10s%-10s%-10s%-10s%-15d%-10d \n",(p->data).TrainNum
,(p->data).StartTime,(p->data).StartPlace,(p->data).EndPlace,(p->data).TimeCost,(p->data).LNP,(p->data).tickets);
if( strcmp( tbuffer , (p->data).StartTime )>=0 )
printf("%-10s班次车已经开走了,你来不及了\n",(p->data).TrainNum);
printf("\n");
}
showstar();
printf("\n\n\n\n\n\n");
return 0;
}


struct node* SortST(struct node* head)
{
Type data;
struct node *p,*q,*m;
char *min,*flat;

for(q=head;q;q=q->next)
{
flat=min=(q->data).StartTime;
for(p=q->next;p;p=p->next)
{
if(strcmp(min,(p->data).StartTime)>0)
{
min=(p->data).StartTime;
m=p;
}
}
if(flat!=min)
{
data=m->data;
m->data=q->data;
q->data=data;
}
}
saveFileSort(head);

return head;
}

struct node* SearchTic(struct node* head)
{
if(head==NULL)
{
printf("\n班车表中没有数据\n");
return head;
}
struct node *a=head,*b=NULL;
char tn[15],sp[20],ep[20];
showstar();
printf("*****欢迎查询余票,下面您将要输入查询内容*****:\n\n");
showstar();
printf("请输入车次号\n"); scanf("%s",tn);
printf("请输入发车地点\n"); scanf("%s",sp);
printf("请输入到达地点\n"); scanf("%s",ep);
while(a&&strcmp(tn,(a->data).TrainNum)&&strcmp(sp,(a->data).StartPlace)&&strcmp(ep,(a->data).EndPlace))
{
b=a;
a=a->next;
}
if(a)
{
showstar();
printf("余票数量:\t");
printf("%-20d\n",(a->data).tickets);
}
else printf("符合你要求的车次不存在\n");
return head;
}

struct node* SellTic(struct node* head)
{
_strtime( tbuffer );

if(head==NULL)
{
printf("\n班车表中没有数据\n");
return head;
}
struct node *a=head,*b=NULL;
char tn[15],sp[20],ep[20];
int cho;
printf("请问阁下买票还是退票??\n买票选1 退票选2 打酱油的选0\n");
scanf("%d",&cho);
if(cho==0)
return head;
else
{
showstar();
printf("请输入车次号\n"); scanf("%s",tn);
while( a&&strcmp(tn,(a->data).TrainNum) )
{
b=a;
a=a->next;
}
if(a)
{
if(cho==1)
{
if( strcmp( tbuffer , (a->data).StartTime )<0 && (a->data).tickets>0 )
{
(a->data).tickets--;
printf("你已经买走了票,请给钱!\n");
}
else printf("车走了票没了,您来的真不是时候。\n");
}
else
{
showstar();
printf("没事不要退票,扰乱车站秩序。\n");
showstar();
}
}
else printf("符合你要求的车次不存在\n");
return head;
}

}

#endif

#ifndef _FILE_H_
#define _FILE_H_
#include<stdio.h>
#include<stdlib.h>
#include "list.h"




struct node* readFile(struct node *head)
{
Type data;
FILE *fp;
head=NULL;
if((fp=fopen("schedule.dat","r"))==NULL)
{
printf("找不到文件,重新创建\n");
fp=fopen("schedule.dat","w");
return head;
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%s%s%d%d",data.TrainNum,data.StartTime,data.StartPlace,data.EndPlace,data.TimeCost
,&data.LNP,&data.tickets);
head=Insertafter(head,data);

}
fclose(fp);
return head;
}

void saveFile(struct node* head)
{
struct node *p=head;
FILE *fp;
if((fp=fopen("schedule.dat","a"))==NULL)
{
printf("打不开\n");
exit(0);
}
if(head==NULL)
{
printf("没东西。。存不了!!");
return;
}
while(p)
{
fprintf(fp,"%s %s %s %s %s %d %d",(p->data).TrainNum,(p->data).StartTime,(p->data).StartPlace,(p->data).EndPlace,(p->data).TimeCost
,(p->data).LNP,(p->data).tickets);
p=p->next;
}
fclose(fp);
}

struct node* CreList(struct node* head)
{
Type data;
int n,i;
struct node *p=head;
FILE *fp;
if((fp=fopen("schedule.dat","w+"))==NULL)
{
printf("打不开\n");
exit(0);
}
printf("请输入您要录入的车次量: 1~n\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("插入第 %d 个数据:--->>\n",i);
head=Addone(head);
}
saveFile(head);
return head;
}

#endif

#include<stdio.h>
#include<stdlib.h>
#include "file.h"

void menu() //主菜单
{
printf("\t__________________________________________\n\n");
printf("\t|_____________班车表信息菜单_____________|\n");
showstar();
printf("\t|**********1、显示班车表信息********** |\n");
showstar();
printf("\t|**********2、修改班车表信录********** |\n");
showstar();
printf("\t|**********3、根据发车时间排序******** |\n");
showstar();
printf("\t|**********4、查询余票信息************ |\n");
showstar();
printf("\t|**********5、录入班车表信息********** |\n");
showstar();
printf("\t|**********6、快乐售票系统站********** |\n");
showstar();
printf("\t|**********0、退出班车信息表********** |\n");
showstar();
printf("\t|________________________________________|\n");
}

void menuedit() //编辑子菜单
{
printf("********1、添加班车信息********\n");
printf("********2、删除班车信息********\n");
printf("********3、修改班车信息********\n");
printf("********0、退出修改************\n");
}



struct node* editManage(struct node *head) //编辑子菜单运行函数
{
int xuanze;
menuedit();
printf("请输入选项\n");
scanf("%d",&xuanze);
switch(xuanze)
{
case 1: head=Addone(head); break;
case 2: head=Delete(head); break;
case 3: head=Edit(head); break;
case 0: break;
}
return head;
}



struct node* runMain(struct node *head,int choice) //主菜单运行函数
{
char tof;
switch(choice)
{
case 1: printeverybody(head); break;
case 2: head=editManage(head); saveFile(head); break;
case 3: head=SortST(head); break;
case 4: head=SearchTic(head); break;
case 5: head=CreList(head); break;
case 6: head=SellTic(head); saveFile(head); break;
case 0:
getchar();
printf("是否保存Y/N ?");
scanf("%c",&tof);
if(tof=='Y'||'y') saveFile(head);
exit(0);

}
return head;

}

主函数:
int main()
{

struct node *head=NULL;
int choice;
head=readFile(head);
do
{
menu();
printf("请输入选项\n");
scanf("%d",&choice);
if(choice>=0&&choice<=6)
head=runMain(head,choice);
else
printf("输入错误。请重新选择\n");

}while(choice);
return 0;
}

684

社区成员

发帖
与我相关
我的任务
社区描述
智能路由器通常具有独立的操作系统,包括OpenWRT、eCos、VxWorks等,可以由用户自行安装各种应用,实现网络和设备的智能化管理。
linuxpython 技术论坛(原bbs)
社区管理员
  • 智能路由器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧