铁路售票管理系统
程序中传递的有信息有:票务信息(包括车次,出发站、到达站、出发时间日期,历时、票数,票价)个人购票信息(姓名,身份信息,车次,出发时间日期,座位号,票价)
票务浏览 (对票务系统中的所有票务信息进行浏览,获取不同时间日期的票务信息。)
购票 当乘客购票成功后,为乘客构建购票信息,用于存储该乘客所有的购票信息,
以便乘客查询,同时减少票务系统中的相关票数。
退票 当乘客退票成功后,将相关的购票信息从为乘客构建的购票信息系统中删除,
同时增加票务系统中的相关票数。
信息查看 乘客可随时查看票务系统中所有的票务信息,同时也可提供UI,用于查看个人的所有购票信息。
用户界面
管理员界面
1.查看票务
2.管理票务
(详细操作暂不展示)
...
main.c文件
#include "slist.h"
#include "menu.h"
#include "file.h"
#include <stdio.h>
int main(void)
{
tNODE* head = NULL; //存放火车信息的链表
uNODE* head1 = NULL; //存放乘客信息的链表
NODE* head2 = NULL; //存放用户账号密码的链表
Welcome(); //欢迎界面
load(&head, &head1); //文件操作
load1(&head2);
while(MainMenu(&head, &head1,&head2)); //主菜单
slist_freeT(&head); //释放链表
slist_freeU(&head1);
slist_free(&head2);
return 0;
}
文件操作
file.h
//file.c文件的头文件
#ifndef __FILE_H
#define __FILE_H
#include"slist.h"
int load(tNODE** , uNODE**);
int load1(NODE**);
int saveT(tNODE*);
int saveU(uNODE*);
int save(NODE*);
#endif
file.c
#include"file.h"
#include"slist.h"
#include<stdio.h>
int load(tNODE** head, uNODE** head1) //打开车票,与乘客的文件
{
FILE* fp = fopen("ticket.dat", "r");//以只读方式打开
FILE* fp1 = fopen("user.dat", "r");
if (!fp)
{
puts("ticket.dat打开失败");
return -1;
}
if (!fp1)
{
puts("user.dat打开失败");
return -1;
}
Ticket data = { 0 };
User data1 = { 0 };
while (fread((&data), sizeof(Ticket), 1, fp))//将文件中的信息读取到链表中
{
slist_addTicket(head, data);//头插法,将每次读取到的信息插入
}
while (fread((&data1), sizeof(User), 1, fp1))
{
slist_addUser(head1, data1);
}
fclose(fp);
fclose(fp1);
return 0;
}
int load1(NODE** head2)
{
FILE *fp = fopen("account.dat","r");//账号密码文件
if(!fp )
{
puts("account.dat加载失败");
return -1;
}
Useract data2 = {0};
while(fread((&data2),sizeof(Useract),1,fp))
{
slist_user(head2,data2);
}
fclose(fp);
return 0;
}
/*将链表中的信息保存到对应的链表中*/
int saveT(tNODE* head)
{
FILE* fp = fopen("ticket.dat", "w");
if (!fp)
{
puts("ticket.dat打开失败");
return -1;
}
tNODE* p = head;
while (p)
{
fwrite(&(p->data), sizeof(Ticket), 1, fp);
p = p->next;
}
fclose(fp);
return 0;
}
int saveU(uNODE* head1)
{
FILE* fp = fopen("user.dat", "w");
if (!fp)
{
puts("user.dat打开失败");
return -1;
}
uNODE* p = head1;
while (p)
{
fwrite(&(p->data), sizeof(User), 1, fp);
p = p->next;
}
fclose(fp);
return 0;
}
int save(NODE* head2)
{
FILE* fp = fopen("account.dat", "w");
if (!fp)
{
puts("account.dat打开失败");
return -1;
}
NODE* p = head2;
while (p)
{
fwrite(&(p->data), sizeof(Useract), 1, fp);
p = p->next;
}
fclose(fp);
return 0;
}
链表操作
slist.h
#ifndef __SLIST_H
#define __SLIST_H
typedef struct
{
char num[10]; // 车次
char start[30];//出发站
char end[30];//到达站
char date[20];//出发日期
char time[10];//出发时间
float take;//历时
int count;//票数
float price;//票价
}Ticket;
typedef struct node
{
Ticket data;
struct node *next;
}tNODE;
typedef struct
{
char name[30];// 姓名
char id[20];//身份
char num[10];//车次
char date[20];//出发日期
char time[10];//出发时间
char seat[20];//座位号
float price;//票价
}User;
typedef struct
{
char name[20];//用户名
char password[20];//密码
char issue[20];//密保问题
char answer[20];//密保答案
int num;//0为用户,1为管理员
}Useract;
typedef struct node_u
{
Useract data;
struct node_u* next;
}NODE;
typedef struct unode
{
User data;
struct unode *next;
}uNODE;
int slist_addTicket(tNODE**, Ticket);//插入函数
int slist_addUser(uNODE**,User);
int slist_deleteTicket(tNODE**,User);//删除函数
int slist_deleteUser(uNODE**,User);
int slist_user(NODE**, Useract); //添加
void slist_printT(const tNODE*); //遍历
void slist_printU(const uNODE*);
void slist_freeT(tNODE**); //释放链表
void slist_freeU(uNODE**);
void slist_free(NODE**);
#endif
slist.c
#include"slist.h"
#include<stdio.h>
#include<stdlib.h>
int slist_addTicket(tNODE** head, Ticket data)
{
tNODE* pNew = (tNODE*)malloc(sizeof(tNODE));
if(!pNew)
{
puts("数据插入失败!");
return -1;
}
pNew -> data = data;
pNew -> next = *head;
*head = pNew;
return 0;
}
int slist_addUser(uNODE** head1, User data1)
{
uNODE* pNew = (uNODE*)malloc(sizeof(uNODE));
if(!pNew)
{
puts("数据插入失败!");
return -1;
}
pNew -> data = data1;
pNew -> next = *head1;
*head1 = pNew;
return 0;
}
int slist_user(NODE** head2, Useract data2)
{
NODE* pNew = (NODE*) malloc (sizeof(NODE));
if(!pNew)
{
puts("注册失败!");
return -1;
}
pNew -> data = data2;
pNew -> next = *head2;
*head2 = pNew;
return 0;
}
void slist_printT(const tNODE* head)
{
const tNODE* p = head;
printf("=============================================================================\n\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", "车次", "出发站", "到达站", "出发日期", "出发时间", "历时", "票数", "票价");
while(p)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%.2f\t%d\t%.2f\n", p->data.num, p->data.start, p->data.end, p->data.date, p->data.time, p->data.take, p->data.count, p->data.price);
p = p -> next;
}
printf("=============================================================================\n\n");
}
void slist_printU(const uNODE* head1)
{
const uNODE* p = head1;
printf("=============================================================================\n\n");
printf("%s\t%s\t\t\t%s\t%s\t%s\t%s\t%s\n", "姓名", "身份", "车次", "出发日期", "出发时间", "座位号", "票价");
while(p)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%s\t%.2f\n", p->data.name, p->data.id, p->data.num, p->data.date, p->data.time, p->data.seat, p->data.price);
p = p -> next;
}
printf("=============================================================================\n\n");
}
void slist_freeT(tNODE** head)
{
tNODE* p = *head,*q = NULL;
while(p)
{
q = p;
p = p -> next;
free(q);
}
}
void slist_freeU(uNODE** head1)
{
uNODE* p = *head1,*q = NULL;
while(p)
{
q = p;
p = p -> next;
free(q);
}
}
void slist_free(NODE** head2)
{
NODE* p = *head2, *q = NULL;
while(p)
{
q = p;
p = p -> next;
free(q);
}
}
菜单文件
menu.h
#ifndef __MENU_H
#define __MENU_H
#include"slist.h"
#include"file.h"
void Welcome(void);
int MainMenu(tNODE**,uNODE**, NODE**);
int tMenu(tNODE**, uNODE**,NODE**);
int tmenu(tNODE**, uNODE**,NODE**);
int uMenu(tNODE**, uNODE**,NODE**);
int umenu(tNODE**, uNODE**,NODE**);
int Manage(tNODE**, uNODE**);
#endif
menu.c
#include"menu.h"
#include<string.h>
#include"function.h"
#include<stdio.h>
#include"slist.h"
void Welcome(void)
{
printf("\n\n");
puts("|============================|");
puts("| |");
puts("|*** 欢迎使用铁路购票系统 ***|");
puts("| |");
puts("|============================|");
puts("\n");
puts(" =======按任意键继续======");
getchar();
}
int MainMenu(tNODE** head, uNODE** head1, NODE** head2)
{
puts("======================");
puts("----1. 管理员模式----");
puts("----2. 用户模式------");
puts("----0. 退出程序------");
puts("======================");
printf("\n请选择:");
int i = 0;
scanf("%d",&i);
switch(i)
{
case 0:
break;
case 1:
while(tmenu(head, head1, head2));
break;
case 2:
while(umenu(head, head1, head2));
break;
default:
puts("选择有误,请重新选择");
break;
}
return i;
}
int tmenu(tNODE** head, uNODE** head1, NODE** head2)
{
puts("======================");
puts("1. 管理员注册");
puts("2. 管理员登陆");
puts("3. 修改密码");
puts("4. 找回密码");
puts("0. 返回上一级");
puts("======================");
int n = 0;
printf("\n请选择:");
scanf("%d", &n);
switch(n)
{
case 0:
return n;
case 1:
{
Useract data = {0};
puts("请输入用户名:");
scanf("%s", data.name);
puts("请输入密码");
printf("\033[8m");
scanf("%s", data.password);
printf("\033[0m");
puts("请输入密保问题:");
scanf("%s", data.issue);
puts("请输入答案:");
scanf("%s", data.answer);
data.num = 1;
NODE* p = *head2;
while(p)
{
if(strcmp( data.name, p->data.name) == 0)
{
puts("用户名已存在!");
return n;
}
p = p -> next;
}
puts("注册成功");
slist_user(head2,data);
save(*head2);
return n;
}
break;
case 2:
{
char name[20] = { 0 };
char password[20] = { 0 };
NODE* p = NULL;
int count = 0;
while (1)
{
p = *head2;
printf("用户名:");
scanf("%s", name);
printf("密码:");
printf("\033[8m");
scanf("%s", password);
printf("\033[0m");
count++;
while (p)
{
if ((strcmp(name, p->data.name) == 0) && (strcmp(password, p->data.password) == 0))
{
if (p->data.num == 1)
{
printf("\n");
puts("登陆中,请稍后... ...");
sleep(2);
printf("\n");
puts("登陆成功!");
while (tMenu(head, head1, head2));
return n;
}
}
p = p->next;
}
if (count == 3)
{
printf("\n");
puts("登陆失败!");
printf("\n");
break;
}
printf("\n");
puts("用户名或密码错误请重新输入");
printf("\n");
}
}
break;
case 3:
change_password(head2);
break;
case 4:
find_password(*head2);
break;
default:
puts("选择有误,请重新选择");
break;
}
return n;
}
int tMenu(tNODE** head, uNODE** head1, NODE** head2)
{
puts("======================");
puts("----1. 查看票务------");
puts("----2. 管理票务------");
puts("----0. 返回上一层----");
puts("======================");
printf("\n请选择:");
int i = 0;
scanf("%d", &i);
switch(i)
{
case 0:
break;
case 1:
while(find(*head, *head1));
break;
case 2:
while(Manage(head, head1));
break;
default:
puts("选择有误,请重新选择");
break;
}
return i;
}
int umenu(tNODE** head, uNODE** head1,NODE** head2)
{
puts("======================");
puts("1. 用户注册");
puts("2. 用户登陆");
puts("3. 修改密码");
puts("4. 找回密码");
puts("0. 返回上一级");
puts("======================");
int n = 0;
printf("\n请选择:");
scanf("%d", &n);
switch(n)
{
case 0:
break;
case 1:
{
Useract data = {0};
puts("请输入用户名:");
scanf("%s", data.name);
puts("请输入密码");
printf("\033[8m");
scanf("%s", data.password);
printf("\033[0m");
puts("请输入密保问题:");
scanf("%s", data.issue);
puts("请输入答案:");
scanf("%s", data.answer);
data.num = 0;
NODE* p = *head2;
while(p)
{
if(strcmp( p -> data.name, data.name) == 0)
{
puts("用户名已存在!");
return n;
}
p = p -> next;
}
puts("注册成功");
slist_user(head2,data);
save(*head2);
}
break;
case 2:
{
char name[20] = { 0 };
char password[20] = { 0 };
NODE* p = NULL;
int count = 0;
while (1)
{
p = *head2;
printf("用户名:");
scanf("%s", name);
printf("密码:");
printf("\033[8m");
scanf("%s", password);
printf("\033[0m");
count++;
while (p)
{
if ((strcmp(name, p->data.name) == 0) && (strcmp(password, p->data.password) == 0))
{
if (p->data.num == 0)
{
printf("\n");
puts("登陆中,请稍后... ...");
sleep(2);
printf("\n");
puts("登陆成功!");
printf("\n");
while (uMenu(head, head1, head2));
return n;
}
}
p = p->next;
}
if (count == 3)
{
printf("\n");
puts("登陆失败!");
printf("\n");
break;
}
printf("\n");
puts("用户名或密码错误请重新输入");
printf("\n");
}
}
break;
case 3:
change_password(head2);
break;
case 4:
find_password(*head2);
break;
default:
puts("输入错误请重新输入");
break;
}
return n;
}
int uMenu(tNODE** head, uNODE** head1, NODE** head2)
{
puts("=======================");
puts("----1. 购票------------");
puts("----2. 退票------------");
puts("----3. 改签------------");
puts("----4. 查看信息------");
puts("----5. 查看票务------");
puts("----0. 返回上一级---");
puts("=======================");
printf("\n请选择:");
int i = 0;
scanf("%d", &i);
switch(i)
{
case 0:
break;
case 1:
while(buyTicket(head, head1));
break;
case 2:
while(refundTicket(head,head1));
break;
case 3:
while (change_ticket(head, head1));
break;
case 4:
while(findInform(*head1));
break;
case 5:
slist_printT(*head);
break;
default:
puts("输入有误请重新输入!");
break;
}
return i;
}
int Manage(tNODE** head, uNODE** head1)
{
puts("=====================");
puts("----1. 增加票务-----");
puts("----2. 删除票务-----");
puts("----3. 修改票务----");
puts("----4. 售票-----");
puts("----5. 退票-----");
puts("----6. 改签-----");
puts("----0. 返回上一级---");
puts("=====================");
printf("\n请选择:");
int i = 0;
scanf("%d", &i);
switch (i)
{
case 0:
break;
case 1:
while (addTicket(head));
break;
case 2:
while (deletTicket(head));
break;
case 3:
while (change(head));
break;
case 4:
while (buyTicket(head,head1));
break;
case 5:
while (deletUser(head1, head));
break;
case 6:
while (change_ticket(head, head1));
break;
default:
puts("选择有误请重新选择");
break;
}
return i;
}
工程文件
function.h文章来源:https://www.toymoban.com/news/detail-519275.html
#ifndef __FUNCTION_H
#define __FUNCTION_H
#include"slist.h"
int change_password(NODE**);
int addTicket(tNODE**);
int deletUser(uNODE**, tNODE**);
int deletTicket(tNODE**);
int buyTicket(tNODE**, uNODE**);
int refundTicket(tNODE**,uNODE**);
int findInform(uNODE*);
int find(tNODE*, uNODE*);
int change_ticket(tNODE**, uNODE**);
int find_password(NODE*);
int change(tNODE**);
#endif
function.c文章来源地址https://www.toymoban.com/news/detail-519275.html
#include"function.h"
#include"slist.h"
#include"file.h"
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
static int ticket_print(tNODE* head);
static int user_print(uNODE* head1);
int addTicket(tNODE** head)
{
Ticket tri = {0};
char ch ='\0';
tNODE* p = NULL;
do
{
p = *head;
puts("请输入车次");
scanf("%s", tri.num);
while (p)
{
if (strcmp(p->data.num, tri.num) == 0 )
{
puts("该车次已存在,请勿重复添加!");
return 0;
}
p = p->next;
}
puts("请输入起始站");
scanf("%s", tri.start);
puts("请输入终点站");
scanf("%s", tri.end);
puts("请输入出发日期(例如2022/11/11)");
scanf("%s", tri.date);
puts("请输入出发时间(例如12:15)");
scanf("%s", tri.time);
puts("请输入历时");
scanf("%f", &tri.take);
puts("请输入票数");
scanf("%d", &tri.count);
puts("请输入票价");
scanf("%f", &tri.price);
slist_addTicket(head,tri);
puts("是否继续添加(Y/N)");
while(getchar() != '\n');
ch = getchar();
}while(ch == 'y' || ch == 'Y');
slist_printT(*head);
saveT(*head);
return 0;
}
int deletUser(uNODE** head1, tNODE** head)
{
slist_printU(*head1);
char name[20] = {0};
puts("请输入要删除的乘员姓名:");
scanf("%s", name);
char id[20] = {0};
puts("请输入要删除的乘员id:");
while (1)
{
scanf("%s", id);
if (strlen(id) == 18)
break;
puts("id错误请重新输入");
}
uNODE* p = *head1, *q = NULL;
tNODE* t = *head;
if(!p)
return -1;
if ((strcmp(p->data.name, name) == 0) && (strcmp(p->data.id, id) == 0))
{
while (t)
{
if (strcmp(p->data.num, t->data.num) == 0)
{
(t->data.count)++;
break;
}
t = t->next;
}
*head1 = p->next;
free(p);
saveU(*head1);
puts("退票成功!");
slist_printU(*head1);
slist_printT(*head);
return 0;
}
while (p)
{
if ((strcmp(p->data.name, name) == 0) && (strcmp(p->data.id, id) == 0))
{
while (t)
{
if (strcmp(p->data.num, t->data.num) == 0)
{
(t->data.count)++;
break;
}
t = t->next;
}
q->next = p->next;
free(p);
saveU(*head1);
puts("退票成功!");
slist_printU(*head1);
slist_printT(*head);
return 0;
}
q = p;
p = p->next;
}
puts("未找到要退票的成员信息");
return 0;
}
int deletTicket(tNODE** head)
{
slist_printT(*head);
char num[20] = {0};
puts("请输入要删除的车次:");
scanf("%s", num);
tNODE* p = *head, *q = NULL;
if(!p)
return -1;
if(strcmp(num, p -> data.num) == 0)
{
*head = p -> next;
free(p);
puts("删除成功!");
saveT(*head);
slist_printT(*head);
return 0;
}
while(p)
{
if(strcmp(num, p -> data.num) == 0 )
{
q -> next = p -> next;
free(p);
puts("删除成功!");
saveT(*head);
slist_printT(*head);
return 0;
}
q = p;
p = p -> next;
}
printf("\n");
puts("未找到要删除的车次");
slist_printT(*head);
return 0;
}
int refundTicket(tNODE** head, uNODE** head1)
{
char name[20] = {0};
puts("请输入要删除的姓名:");
scanf("%s", name);
char id[30] = {0};
puts("请输入要删除的id:");
while (1)
{
scanf("%s", id);
if (strlen(id) == 18)
break;
puts("id错误请重新输入");
}
uNODE* p = *head1, *q = NULL;
tNODE* t = *head;
if(!p)
return -1;
if((strcmp(name, p -> data.name) == 0 )&& (strcmp(id, p -> data.id) == 0))
{
while (q)
{
if (strcmp(p->data.num, t->data.num) == 0)
{
(t->data.count)++;
break;
}
t = t->next;
}
*head1 = p -> next;
free(p);
saveU(*head1);
puts("删除成功!");
slist_printT(*head);
return 0;
}
while(p)
{
if((strcmp(name, p -> data.name) == 0) && (strcmp(id, p -> data.id) == 0))
{
while (q)
{
if (strcmp(p->data.num, t->data.num) == 0)
{
(t->data.count)++;
break;
}
t = t->next;
}
q -> next = p -> next;
free(p);
puts("退票成功!");
slist_printT(*head);
saveU(*head1);
return 0;
}
q = p;
p = p -> next;
}
puts("未找到要删除的乘员");
return 0;
}
int buyTicket(tNODE** head,uNODE** head1 )
{
if(*head == NULL)
{
puts("当前暂无可购买车票!");
return -1;
}
slist_printT(*head);
char ch = '\0';
User user = {0};
tNODE* p = NULL;
uNODE* q = NULL;
do
{
puts("请输入要购买的车次");
scanf("%s", user.num);
p = *head;
q = *head1;
int flag = 0;
while(p)
{
if(strcmp(p -> data.num, user.num) == 0)
{
puts("是否为学生(y/n)");
while (getchar() != '\n');
ch = getchar();
if (ch == 'y' || ch == 'Y')
{
user.price = (p->data.price) * 0.69;
}
else
user.price = p->data.price;
strcpy( user.date, p->data.date);
strcpy(user.time, p->data.time);
(p -> data.count)--;
flag = 1;
break;
}
p = p -> next;
}
if (flag == 0)
{
puts("该车次未运行");
return 0;
}
puts("请输入姓名:");
scanf("%s", user.name);
puts("请输入身份证号:");
while (1)
{
scanf("%s", user.id );
if (strlen(user.id) == 18)
break;
puts("身份证输入错误,请重新输入");
}
puts("请输入座位号:");
scanf("%s", user.seat);
while(q)
{
if(strcmp(q -> data.name, user.name) == 0 && strcmp( q -> data.num, user.num) == 0)
{
puts("购票失败,请勿重复购买");
return -1;
}
q = q -> next;
}
puts("购票成功!");
printf("=============================================================================\n\n");
printf("%s\t%s\t\t\t%s\t%s\t%s\t%s\t%s\n", "姓名", "身份", "车次", "出发日期", "出发时间 ", "座位号", "票价");
printf("%s\t%s\t%s\t%s\t%s\t\t%s\t%.2f\n", user.name, user.id, user.num, user.date, user.time, user.seat, user.price);
printf("=============================================================================\n\n");
slist_addUser(head1, user);
saveU(*head1);
saveT(*head);
puts("是否继续添加(Y/N)");
while(getchar() != '\n');
ch = getchar();
}while(ch == 'y' || ch == 'Y');
slist_printT(*head);
return 0;
}
int findInform(uNODE* head1)
{
uNODE* p = NULL;
char ch;
do
{
p = head1;
char name[30] = { 0 };
puts("请输入要查询的乘客姓名:");
scanf("%s", name);
char id[20] = { 0 };
puts("请输入要查询的乘客id");
while (1)
{
scanf("%s", id);
if (strlen(id) == 18)
break;
puts("id错误请重新输入");
}
int flag = 0;
while (p)
{
if ((strcmp(p->data.name, name) == 0) && (strcmp(p->data.id, id) == 0))
{
puts("信息如下:");
printf("=============================================================================\n\n");
printf("%s\t%s\t\t\t%s\t%s\t%s\t%s\t%s\n", "姓名", "身份", "车次", "出发日期", "出发时间 ", "座位号", "票价");
printf("%s\t%s\t%s\t%s\t%s\t\t%s\t%.2f\n", p->data.name, p->data.id, p->data.num, p->data.date, p->data.time, p->data.seat, p->data.price);
printf("=============================================================================\n\n");
flag = 1;
}
p = p->next;
}
if (flag == 0)
{
puts("未找到乘客信息!");
}
puts("是否继续查找(Y/N)");
while (getchar() != '\n');
ch = getchar();
} while (ch == 'Y' || ch == 'y');
return 0;
}
int find(tNODE* head, uNODE* head1)
{
puts("===========================");
puts("1. 查询车次信息");
puts("2. 售票信息");
puts("0. 返回上一级");
puts("===========================");
printf("\n");
int i = 0;
printf("请选择:");
scanf("%d", &i);
switch(i)
{
case 0:
break;
case 1:
while (ticket_print(head));
break;
case 2:
while (user_print(head1));
break;
default :
puts("输入错误请重新输入!");
break;
}
return i;
}
int change_ticket(tNODE** head, uNODE** head1)
{
char ch;
int flag = 0;
uNODE* p = *head1;
tNODE* q = *head, * t = *head;
char name[20] = { 0 };
char num[10] = { 0 };
char new_num[10] = { 0 };
puts("请输入乘客姓名:");
scanf("%s", name);
puts("请输入的车次:");
scanf("%s", num);
while (p)
{
if ((strcmp(name, p->data.name) == 0) && (strcmp(num, p -> data.num) == 0))
{
flag = 1;
break;
}
p = p->next;
}
if (flag == 0)
{
puts("未找到该乘客信息");
return 0;
}
slist_printT(*head);
while (q)
{
if (strcmp(num, q->data.num) == 0)
{
(q->data.count)++;
saveT(*head);
break;
}
q = q->next;
}
puts("请输入要改签的车次:");
scanf("%s", new_num);
while (t)
{
if (strcmp(new_num, t->data.num) == 0)
{
strcpy(p->data.num, new_num);
strcpy(p->data.date, t->data.date);
strcpy(p->data.time, t->data.time);
puts("是否为学生(y/n)");
while (getchar() != '\n');
ch = getchar();
if (ch == 'y' || ch == 'Y')
{
p->data.price = (t->data.price) * 0.69;
}
else
p->data.price = t->data.price;
(t->data.count)--;
puts("请稍后... ...");
sleep(2);
puts("改签成功!");
printf("=============================================================================\n\n");
printf("%s\t%s\t\t\t%s\t%s\t%s\t%s\t%s\n", "姓名", "身份", "车次", "出发日期", "出发时间 ", "座位号", "票价");
printf("%s\t%s\t%s\t%s\t%s\t\t%s\t%.2f\n", p->data.name, p->data.id, p->data.num, p->data.date, p->data.time, p->data.seat, p->data.price);
printf("=============================================================================\n\n");
saveT(*head);
saveU(*head1);
return 0;
}
t = t->next;
}
puts("改签失败");
return 0;
}
int find_password(NODE* head2)
{
Useract data = { 0 };
puts("请输入用户名:");
scanf("%s", data.name);
NODE* p = head2;
while (p)
{
if (strcmp( p->data.name, data.name) == 0)
{
printf("%s\n", p->data.issue);
puts("请输入答案:");
scanf("%s", data.answer );
if (strcmp( data.answer, p->data.answer) == 0)
{
printf("您所查询的密码为:%s\n", p->data.password);
return 0;
}
else
{
puts("答案错误,查询失败!");
return -1;
}
}
p = p->next;
}
puts("查无此人!");
return -1;
}
int change_password(NODE** head2)
{
Useract data = { 0 };
puts("请输入用户名:");
scanf("%s", data.name);
puts("请输入密码:");
printf("\033[8m");
scanf("%s", data.password);
printf("\033[0m");
NODE* p = *head2;
while (p)
{
if ((strcmp( data.name, p->data.name) == 0) && (strcmp( data.password, p->data.password) == 0))
{
puts("请输入要修改的密码:");
printf("\033[8m");
scanf("%s", p->data.password);
printf("\033[0m");
puts("修改成功");
save(*head2);
return 0;
}
p = p->next;
}
puts("用户或密码错误!");
return -1;
}
static int ticket_print(tNODE* head)
{
puts("===========================");
puts("1. 查看全部");
puts("2. 按日期查询");
puts("3. 按终点站查询");
puts("0. 返回上一级");
puts("===========================");
printf("\n");
int i = 0;
printf("请选择:");
scanf("%d", &i);
switch (i)
{
case 0:
return i;
case 1:
slist_printT(head);
break;
case 2:
{
char date[30] = { 0 };
printf("请输入要查询的日期:");
scanf("%s", date);
tNODE* p = head;
printf("=============================================================================\n\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", "车次", "出发站", "到达站", "出发日期","出发时间", "历时", "票数", "票价");
while (p)
{
if (strcmp(p->data.date, date) == 0)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%.2f\t%d\t%.2f\n", p->data.num, p->data.start, p->data.end, p->data.date, p-> data.time , p->data.take, p->data.count, p->data.price);
}
p = p->next;
}
printf("=============================================================================\n\n");
}
break;
case 3:
{
char end[30] = { 0 };
printf("请输入要查询的终点站:");
scanf("%s", end);
tNODE* p = head;
printf("=============================================================================\n\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", "车次", "出发站", "到达站", "出发日期", "出发时间", "历时", "票数", "票价");
while (p)
{
if (strcmp(p->data.end, end) == 0)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%.2f\t%d\t%.2f\n", p->data.num, p->data.start, p->data.end, p->data.date, p->data.time, p->data.take, p->data.count, p->data.price);
}
p = p->next;
}
printf("=============================================================================\n\n");
}
break;
default:
puts("输入错误请重新输入!");
break;
}
return i;
}
static int user_print(uNODE* head1)
{
puts("===========================");
puts("1. 查看全部");
puts("2. 按车次查询");
puts("3. 按日期查询");
puts("4. 按姓名查询");
puts("0. 返回上一级");
puts("===========================");
printf("\n");
int i = 0;
printf("请选择:");
scanf("%d", &i);
switch (i)
{
case 0:
return i;
case 1:
slist_printU(head1);
break;
case 2:
{
char num[30] = { 0 };
printf("请输入要查询的车次:");
scanf("%s", num);
uNODE* p = head1;
printf("=============================================================================\n\n");
printf("%s\t%s\t\t\t%s\t%s\t%s\t%s\t%s\n", "姓名", "身份", "车次", "出发日期", "出发时间", "座位号", "票价");
while (p)
{
if (strcmp(p->data.num, num) == 0)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%s\t%.2f\n", p->data.name, p->data.id, p->data.num, p->data.date, p->data.time, p->data.seat, p->data.price);
}
p = p->next;
}
printf("=============================================================================\n\n");
}
break;
case 3:
{
char date[30] = { 0 };
printf("请输入要查询的日期:");
scanf("%s", date);
uNODE* p = head1;
printf("=============================================================================\n\n");
printf("%s\t%s\t\t\t%s\t%s\t%s\t%s\t%s\n", "姓名", "身份", "车次", "出发日期", "出发时间", "座位号", "票价");
while (p)
{
if (strcmp(p->data.date, date) == 0)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%s\t%.2f\n", p->data.name, p->data.id, p->data.num, p->data.date, p->data.time, p->data.seat, p->data.price);
}
p = p->next;
}
printf("=============================================================================\n\n");
}
break;
case 4:
{
char name[30] = { 0 };
printf("请输入要查询的名字:");
scanf("%s", name);
uNODE* p = head1;
printf("=============================================================================\n\n");
printf("%s\t%s\t\t\t%s\t%s\t%s\t%s\t%s\n", "姓名", "身份", "车次", "出发日期", "出发时间", "座位号", "票价");
while (p)
{
if (strcmp(p->data.name, name) == 0)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%s\t%.2f\n", p->data.name, p->data.id, p->data.num, p->data.date, p->data.time, p->data.seat, p->data.price);
}
p = p->next;
}
printf("=============================================================================\n\n");
}
break;
default:
puts("输入错误请重新输入!");
break;
}
return i;
}
int change(tNODE** head)
{
slist_printT(*head);
char num[20] = { 0 };
puts("请输入要修改的车次:");
scanf("%s", num);
tNODE* p = *head, * q = *head;
while (p)
{
if (strcmp(p->data.num, num) == 0)
{
char new_num[20] = { 0 };
puts("请输入修改后的车次:");
scanf("%s", new_num);
while (q)
{
if (strcmp(new_num, q->data.num) == 0)
{
puts("车次已存在,修改失败!");
return 0;
}
q = q->next;
}
strcpy( p->data.num, new_num);
puts("请输入修改后的起始站");
scanf("%s", p->data.start);
puts("请输入修改后的终点站");
scanf("%s", p->data.end);
puts("请输入修改后的出发日期(例如2022/11/11)");
scanf("%s", p->data.date);
puts("请输入修改后的出发时间(例如12:15)");
scanf("%s", p->data.time);
float take = 0, price = 0;
int count = 0;
puts("请输入修改后的历时");
scanf("%f", &take);
p->data.take = take;
puts("请输入修改后的票数");
scanf("%d", &count);
p->data.count = count;
puts("请输入修改后的票价");
scanf("%f", &price);
p->data.price = price;
saveT(*head);
puts("请稍后... ...");
sleep(1);
puts("修改成功!");
printf("=============================================================================\n\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", "车次", "出发站", "到达站", "出发日期", "出发时间", "历时", "票数", "票价");
printf("%s\t%s\t%s\t%s\t%s\t\t%.2f\t%d\t%.2f\n", p->data.num, p->data.start, p->data.end, p->data.date, p->data.time, p->data.take, p->data.count, p->data.price);
printf("=============================================================================\n\n");
return 0;
}
p = p->next;
}
puts("未找到该车次");
return 0;
}
到了这里,关于C语言阶段小项目(火车购票系统)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!