欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實(shí)現(xiàn)火車票管理系統(tǒng)

 更新時(shí)間:2022年03月16日 08:15:55   作者:for_s  
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)火車票管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了C語言實(shí)現(xiàn)火車票管理系統(tǒng)課程設(shè)計(jì)的具體代碼,供大家參考,具體內(nèi)容如下

1、前言

這是大一剛學(xué)C語言一個(gè)學(xué)期完成的課設(shè)項(xiàng)目,里面的功能還可以進(jìn)一步的完善,僅供分享、參考、記錄使用,加油!

2、設(shè)計(jì)目的

隨著社會(huì)的發(fā)展,為了滿足人們的訂車票需求,所以設(shè)計(jì)了一個(gè)車票管理系統(tǒng),讓用戶可以查詢到車票的余數(shù),乘車時(shí)間,以及為用戶提供一個(gè)訂票和退票的平臺(tái),同時(shí)管理員也可以借用此系統(tǒng)進(jìn)行對車票進(jìn)行操作。

3、設(shè)計(jì)內(nèi)容

1.對車票的各類信息進(jìn)行采集并錄入;
2.從磁盤文件中讀取車輛信息;
3.對所有車票信息的個(gè)數(shù)進(jìn)行統(tǒng)計(jì)
4.對車票信息進(jìn)行增加;
5.對特定的車票進(jìn)行查詢
6.對所有車輛的旅程總時(shí)長進(jìn)行排序;
7.乘客輸入自己的信息訂票;
8.乘客輸入自己的信息退票;
9.注冊賬號(hào)以及登錄賬號(hào)進(jìn)入系統(tǒng)。

4、概要設(shè)計(jì)

采用鏈表實(shí)現(xiàn)系統(tǒng),同時(shí)設(shè)置了密碼,用戶進(jìn)入系統(tǒng)輸入密碼時(shí),給密碼進(jìn)行了加密操作,而且該管理系統(tǒng)實(shí)現(xiàn)了查票、訂票、退票、增加票、排序等功能。

5、各函數(shù)功能

登錄功能: void enroll(),int land();
包括注冊和登錄,新用戶需要先注冊登錄,并且登錄的時(shí)候密碼用*進(jìn)行覆蓋;
車票功能:①struct node *read_inf();
從文件中讀取信息,在文件中書寫好車票信息,然后調(diào)用函數(shù),將文件中的信息讀取并顯示出來。
②void save_inf(struct node *pHead);
將從鍵盤輸入的車票信息保存到文件中,最后可以在文件中查看所保存的信息。
③struct node *add(struct node *pHead);
增加車票信息,采用頭插法或者尾插法增加車票信息并且顯示出所有的車票信息。
④int listlength(struct node *pHead);
統(tǒng)計(jì)所以的車票信息數(shù),通過鏈表的遍歷的方法,用count計(jì)數(shù),最后count的值即為車票信息數(shù)。
⑤int inquire(struct node *pHead);
查詢所需的車票信息,通過鏈表遍歷,查找起點(diǎn)站和終點(diǎn)站和所需相一致的進(jìn)而實(shí)現(xiàn)此功能。
⑥void Sort(struct node *pHead);
對車票的時(shí)長進(jìn)行排序,通過鏈表的遍歷,采用冒泡排序,讓時(shí)長從短到長的排序,也可以把時(shí)長變量換成余票數(shù)等等變量名進(jìn)行排序,借用中間變量進(jìn)行交換值。
⑦void output(struct node *pHead);
輸出顯示車票信息,采用鏈表的遍歷方法,將所存儲(chǔ)的鏈表信息打印顯示出來。
⑧int buy(struct node *pHead);
訂票,輸入姓名,以及所需的訂票數(shù),查詢起始站與終點(diǎn)站,最后票數(shù)會(huì)得到相應(yīng)的減少。
⑨int back(struct node *pHead);
退票,輸入姓名,以及所想的退票數(shù),最后此票數(shù)會(huì)得到相應(yīng)的增加。

6、源代碼

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
#include<windows.h>

#define n 5

int len=0;

//乘客信息
struct passenge ? ? ? ? ? ? ? ? ? ??
{
? ? char name[10]; ? ? ? ? ? ? ? ? //姓名
? ? int ?num; ? ? ? ? ? ? ? ? ? ? ?//所需票量
}lg[n]; ? ? ? ? ? ? ? ? ? ? ? ? ? //結(jié)構(gòu)體變量名?

//車票信息
typedef struct train ? ? ? ? ? ? ? ? ? ? ?
{
? ? char start_stat[20]; ? ? ? ? ?//起始站
? ? char end_stat[20]; ? ? ? ? ? ?//終點(diǎn)站
? ? char go_time[16]; ? ? ? ? ? ? //出發(fā)時(shí)間?
? ? char go_data[16]; ? ? ? ? ? ? //出發(fā)日期
? ? char train_num[15]; ? ? ? ? ? //車次信息
? ? char all_time[16]; ? ? ? ? ? ?//旅途時(shí)間
? ? int ?ticket_lea; ? ? ? ? ? ? ? //余票數(shù)量
}Train; ? ? ? ? ? ? ?//把結(jié)構(gòu)體struct train 叫做 Train?

typedef Train Item; ? ?//又把Train 叫做 Item,目的讓鏈表更通用 ? ?鏈表里只有2 個(gè)東西 項(xiàng)目和指針 ?

struct node
{ ? ? ? ? ? ? ? ? ? ? ? ?//node是一個(gè)節(jié)點(diǎn) ? 節(jié)點(diǎn)包括項(xiàng)目和指針?
?? ?Item item;
?? ?struct node *next;
};

//注冊信息
void enroll()
{
?? ?char a[100]; ? ? ? ? ? ? ? ? ? //注冊用戶名
?? ?char b[100]; ? ? ? ? ? ? ? ? ? //注冊密碼
?? ?char s[100]; ? ? ? ? ? ? ? ? ? //再次確定密碼
?? ?int ?len;
?? ?
? ??? ?printf("請輸入您的用戶名:");
?? ?scanf("%s",a);
?? ?
?? ?printf("請?jiān)O(shè)置您的密碼:");
?? ??? ??? ?
?? ?reset: scanf("%s",b); ? ? //用到了if goto語句?

?? ? ? ?len=strlen(b); ? ?//讀取密碼長度?
?? ? ??
?? ? ? if(len>9)
?? ??? ?{
?? ??? ??? ?printf("密碼長度過長,請重新設(shè)置:");
?? ? ? ? ?goto reset; ? ?//if goto 語句 ?
?? ? ? ?}
? ?? ? ?printf("請?jiān)俅屋斎肽O(shè)置的密碼:");
? ? ??? ?scanf("%s",s);
?? ?
?? ?if(strcmp(b,s) == 0) ? ? ? //字符串比較函數(shù)?
?? ?{
?? ??? ?FILE *fp;
?? ??? ?
?? ??? ?fp=fopen("register.txt","at"); ? ? //選用追加方式,可以存多個(gè)信息
?? ??? ?
?? ??? ?if(fp == NULL)
?? ??? ?{
?? ??? ??? ?printf("文件不存在!");
?? ??? ??? ?exit(1); ? ? ? ? ? ? ? ? ? ? ? ? ??
?? ??? ?}
?? ??? ?
?? ??? ?fprintf(fp,"%s %s\n",a,b); ? ? ? ? ? ? ? ? ? ?//字符串寫入函數(shù)進(jìn)行寫入操作
? ? ? ?
?? ? ? ?printf("\n\t------注冊成功------\n");
?? ??? ?fclose(fp);
?? ?}
?? ?else if(strcmp(b,s) != 0)
?? ?{
?? ??? ?printf("您兩次輸入的密碼不一致,請重新設(shè)置密碼!\n");
?? ??? ?goto reset; ? ? ? ? ?//if goto 語句?
?? ?}
}

//登陸頁面
int land()
{
?? ?int ?i=0; ? ? ?//i是為了判斷密碼長度 并加密?
?? ?char a[10]; ? ? ? ? ? ? ? ??
?? ?char b[10]; ? ? ? ? ? ? ? ? ??

?? ?char user_name[10]; ? ? ? ? ??
?? ?char user_passwords[10]; ? ? ?

?? ?printf("請輸入您的用戶名:");
?? ?scanf("%s",user_name);

? ? printf("請輸入您的密碼:");

?? ?while(i<9 && (user_passwords[i] = getch()) && user_passwords[i] != '\r') ? //如果輸入超限 或者 遇到換行符就跳出循環(huán)
?? ?{
?? ??? ?printf("*"); ? //掩飾密碼?
?? ??? ?i++;
?? ?}
?? ?
?? ?user_passwords[i]=0; ? //字符串結(jié)束標(biāo)志 '/0'?
?? ?
?? ?FILE *fp;
?? ?fp=fopen("register.txt","rt"); ? ? ? //又打開文件?
?? ?
?? ?if(fp==NULL)
?? ?{
?? ??? ?printf("文件不存在!");
?? ??? ?exit(1);
?? ?}
?? ?
?? ?while(fscanf(fp,"%s %s",a,b)!=EOF) ? ?//讀文件判斷賬號(hào)密碼是否正確?
?? ?{ ? ?
?? ??? ?if(strcmp(a,user_name)==0 ?&& ?strcmp(b,user_passwords)==0) ? //字符串比較函數(shù),看是否正確?
?? ??? ? {
?? ??? ??? ?printf("\n\t--------登陸成功--------\n");
?? ??? ??? ?printf("\t------歡迎進(jìn)入系統(tǒng)------\n");
?? ??? ??? ?return 0;
?? ??? ? }?
?? ?}
?? ?if(1)
?? ?{
?? ??? ?printf("\n信息輸入錯(cuò)誤!\n");
?? ? ? ? land();
?? ?}
?? ?fclose(fp);
}

//將信息保存到文件?
void save_inf(struct node *pHead) ? ? ? ? ? ? //將鏈表中的信息保存到制定文件中
{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //頭指針不能移動(dòng)?
? ? struct node *pTemp; ? //因?yàn)橐粋€(gè)節(jié)點(diǎn)移動(dòng) 所以定義為pTemp移動(dòng)?
? ??
?? ?FILE *fp;
? ? fp=fopen("information.txt","at"); ? ?//打開文件?
? ??
?? ?if(fp==NULL)
? ? {
? ? ? ? printf("打開文件失敗,文件可能不存在!\n");
? ? ? ? exit(1);
? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//遍歷輸入?
? ? for(pTemp=pHead ; pTemp != NULL;pTemp=pTemp->next) ? ? ?//節(jié)點(diǎn)先指向項(xiàng)目,項(xiàng)目里面再找成員?
? ? ? ??
?? ??? ?fprintf(fp,"%s %s %s %s %s %s %d\n",pTemp->item.start_stat,pTemp->item.end_stat,
?? ??? ??? ?pTemp->item.go_time,pTemp->item.go_data,pTemp->item.train_num,pTemp->item.all_time,pTemp->item.ticket_lea);
? ?
? ? fclose(fp);
}?

//增加?
struct node *add(struct node *pHead)
{
?? ? ? struct node *pNew;
?? ? ? struct node *current;?
?? ? ?
?? ? ? ?pNew=(struct node *)malloc(sizeof(struct node)); ? ? ?//再次分配結(jié)點(diǎn)的內(nèi)存空間
? ? ? ??
? ? ? ? pNew->next=pHead; ? ?//新結(jié)點(diǎn)指向原來的首節(jié)點(diǎn)?
? ? ? ? pHead=pNew; ? ? ? ? ?//頭指針指向新結(jié)點(diǎn)
? ? ? ??
? ? ? ??
? ? ? ? //尾插法;
?? ??? ?/*current=pHead;
?? ??? ?while(current->next!=NULL)
?? ??? ?{
?? ??? ??? ?current=current->next;
?? ??? ?}?
?? ??? ?current->next=pNew;
?? ??? ?pNew->next=NULL;
? ? ? ? */
? ? ? ??
? ? ? ? printf("\n請輸入起始站:");
? ? ? ? scanf("%s",pNew->item.start_stat);
? ? ? ? printf("請輸入終點(diǎn)站:");
? ? ? ? scanf("%s",pNew->item.end_stat);
? ? ? ? printf("請輸入出發(fā)時(shí)間:");
? ? ? ? scanf("%s",pNew->item.go_time);
? ? ? ? printf("請輸入出發(fā)日期:");
? ? ? ? scanf("%s",pNew->item.go_data);
? ? ? ? printf("請輸入車次信息:");
? ? ? ? scanf("%s",pNew->item.train_num);
? ? ? ? printf("請輸入旅途時(shí)間:");
? ? ? ? scanf( "%s",pNew->item.all_time);
? ? ? ? printf("請輸入余票數(shù)量:");
? ? ? ? scanf("%d",&pNew->item.ticket_lea);
?? ??? ?
?? ??? ?current=pHead;
?? ?
?? ??? ?while(current!=NULL){
?? ??? ??? ?printf("%-10s",current->item.start_stat);
? ? ? ? ?? ?printf("%-10s",current->item.end_stat);
? ? ? ? ?? ?printf("%-12s",current->item.go_time);
? ? ? ? ?? ?printf("%-14s",current->item.go_data);
?? ??? ??? ?printf("%-12s",current->item.train_num);
? ? ? ? ?? ?printf("%-13s",current->item.all_time);
? ? ? ? ?? ?printf("%-d",current->item.ticket_lea);
? ? ? ? ?? ?printf("\n");
? ? ? ? ?? ?current=current->next;
?? ??? ?}
?? ??? ??
? ? ? ? return pHead; ? ? ? //返回頭指針?
? ? ? ??
?}?


//輸出顯示模塊
void output(struct node *pHead)
{
? ? struct node *pTemp; ? ? ? ? ? ? ? ? //循環(huán)所用的臨時(shí)指針

?? ?pTemp=pHead; ? ? ? ? ? ? ? ? ? ? ? ? //指針的到首結(jié)點(diǎn)的指針

? ? printf("\t******車票信息如下******\n");
? ? printf("起始站 ? ?終點(diǎn)站 ? ?出發(fā)時(shí)間 ? ?出發(fā)日期 ? ? 車次信息 ? ? 旅途時(shí)間 ? ?余票量\n");

? ? while((pTemp!=NULL))
? ? {
? ? ? ? printf("%-10s",pTemp->item.start_stat);
? ? ? ? printf("%-10s",pTemp->item.end_stat);
? ? ? ? printf("%-12s",pTemp->item.go_time);
? ? ? ? printf("%-14s",pTemp->item.go_data);
?? ??? ?printf("%-12s",pTemp->item.train_num);
? ? ? ? printf("%-13s",pTemp->item.all_time);
? ? ? ? printf("%-d",pTemp->item.ticket_lea);
? ? ? ? printf("\n");
? ? ? ? pTemp=pTemp->next; ? ? ? ? ? ? ?//移動(dòng)臨時(shí)指針到下一個(gè)結(jié)點(diǎn)
? ? }

}

//查詢車票信息
int inquire(struct node *pHead)
{
?? ?int flag = 0;
? ? struct node *pTemp;?
? ??
? ? char inquire_start[20],inquire_end[20]; ? ? ? //查詢選擇的起始站和終點(diǎn)站
??
? ? printf("請輸入要查詢車票的起始站和終點(diǎn)站:");
? ? scanf("%s %s",inquire_start,inquire_end);
? ??
?? ?pTemp=pHead;
? ??
? ? while(pTemp!=NULL)
? ? {
? ? ? ? if((strcmp(pTemp->item.start_stat,inquire_start)==0) && (strcmp(pTemp->item.end_stat,inquire_end)==0))
? ? ? ? {
? ? ? ? ?? ?flag = 1;
? ? ? ? ? ? printf("\n車票信息結(jié)果如下:\n");
? ? ? ? ? ? printf("起始站 ? ?終點(diǎn)站 ? ?出發(fā)時(shí)間 ? ?出發(fā)日期 ? ?車次 ? ?旅途時(shí)間 ? ?余票量\n");
? ? ? ? ? ? printf("%-10s",pTemp->item.start_stat);
? ? ? ? ?? ?printf("%-10s",pTemp->item.end_stat);
? ? ? ? ?? ?printf("%-12s",pTemp->item.go_time);
? ? ? ? ?? ?printf("%-14s",pTemp->item.go_data);
?? ??? ??? ?printf("%-12s",pTemp->item.train_num);
? ? ? ? ?? ?printf("%-13s",pTemp->item.all_time);
? ? ? ? ?? ?printf("%-d",pTemp->item.ticket_lea); ? ? ??
?? ??? ?}
? ? ? ? ? ?pTemp=pTemp->next;
? ? ? ? ? ?continue;
?? ?}
?? ?
?? ?if(flag == 0)
? ? {
? ? ?? ?printf("輸入錯(cuò)誤!\n");
?? ??? ?inquire(pHead);
?? ?}
?? ?return 0;
?? ?}?
?? ?
//訂票?? ?
?? ?int buy(struct node *pHead)
{
? ? struct node *pTemp;?
? ? char ? choice_start[20],choice_end[20]; ? ? ? /*購票選擇的起始和終點(diǎn)站*/
? ? int ? ?numbers; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/*購買數(shù)量*/
? ? char ? buy_name[10]; ? ? ? ? ? ? ? ? ? ? ? ? ?/*購買人姓名*/
? ? char ? wy;
? ??
? ? pTemp=pHead;?
? ? printf("請輸入所購買車票的起始站、終點(diǎn)站和票數(shù):");
? ? scanf("%s %s %d",choice_start,choice_end,&numbers);
??
? ? while(pTemp!=NULL)
? ? {
? ? ? ? if((strcmp(pTemp->item.start_stat,choice_start)==0)&&(strcmp(pTemp->item.end_stat,choice_end)==0)) ? ? ?/*找到起始終點(diǎn)均相同的站*/
? ? ? ? {
? ? ? ? ? ? if(numbers<=pTemp->item.ticket_lea) ? ? ? /*若小于余票量進(jìn)行辦理*/
? ? ? ? ? ? {
? ? ? ? ? ? ? ? printf("找到符合信息的車次:\n");
? ? ? ? ? ? ? ? printf("起始站 ? ?終點(diǎn)站 ? ?出發(fā)時(shí)間 ? ?出發(fā)日期 ? ?車次 ? ?旅途時(shí)間 ? ?余票量\n");
? ? ? ? ? ? ? ? printf("%-10s",pTemp->item.start_stat);
? ? ? ? ? ? ? ? printf("%-10s",pTemp->item.end_stat);
? ? ? ? ? ? ? ? printf("%-11s",pTemp->item.go_time);
? ? ? ? ? ? ? ? printf("%-12s",pTemp->item.go_data);
? ? ? ? ? ? ? ? printf("%-10s",pTemp->item.train_num);
? ? ? ? ? ? ? ? printf("%-13s",pTemp->item.all_time);
? ? ? ? ? ? ? ? printf("%-d",pTemp->item.ticket_lea);
?? ??? ??? ??? ?printf("\n");
? ? ? ? ? ? ? ? printf("請您輸入姓名:");
? ? ? ? ? ? ? ? scanf("%s",buy_name);
? ? ? ? ? ? ? ??
?? ??? ??? ??? ?printf("正在辦理訂票......\n");
? ? ? ? ? ? ? ? printf("恭喜您辦理成功!\n");
? ? ? ? ? ? ? ??
?? ??? ??? ??? ?pTemp->item.ticket_lea=pTemp->item.ticket_lea - numbers; ? ? ? /*辦理成功,該車次票量減少*/
? ? ? ? ? ? ? ??
?? ??? ??? ??? ?strcpy(lg[len].name,buy_name);
? ? ? ? ? ? ? ??
?? ??? ??? ??? ?lg[len].num=numbers;
?? ??? ??? ??? ?len++;
?? ??? ??? ??? ?return 0; ? ?/*訂票成功返回主菜單*/
? ? ? ? ? ? }
? ? ? ? ? ? else?
? ? ? ? ? ? {
? ? ? ? ? ? ? ? printf("您所需要的票數(shù)超過余票數(shù),請問是否繼續(xù)辦理(Y/y || N/n)?\n");
? ? ? ? ? ? ? ? getchar();
? ? ? ? ? ? ? ? scanf("%c",&wy);
? ? ? ? ? ? ? ??
?? ??? ??? ??? ?if(wy == 'Y' || wy == 'y')
? ? ? ? ? ? ? ? ? ? buy(pHead);
? ? ? ? ? ? ? ? else if(wy == 'N' || wy=='n' )
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ? printf("謝謝使用,按任意鍵返回!\n");
?? ??? ??? ??? ??? ? getch();
?? ??? ??? ??? ??? ? return 0;
?? ??? ??? ??? ?}
? ? ? ? ? ? }
? ? ? ? }
?? ??? ?else
?? ??? ??? ?pTemp=pTemp->next;
?? ?}
?? ?printf("\n很遺憾,未找到您需要的車次,請重新訂票!\n");

?? ?buy(pHead);
?? ?return 0;
}

//退票
int back(struct node *pHead)
{
?? ? struct node *pTemp;
? ??? ? int i;
?? ? char wy; ? ? ? ? ? ? ? ?//判斷yes or no?
? ? ?
?? ? char back_name[10]; ? ? //退票人姓名
? ? ?int back_num; ? ? ? ? ? //退票數(shù)
?? ? char back_start[20]; ? ?//退票起始站
?? ? char back_end[20]; ? ? ?//退票終點(diǎn)站
? ? ?
?? ? printf("請輸入要退票人姓名和退票數(shù):");
? ? ?scanf("%s%d",back_name,&back_num);
?? ? printf("請輸入退票的起始站和終點(diǎn)站:");
?? ? scanf("%s%s",back_start,back_end);
? ? ?pTemp=pHead;
?? ?
?? ? while(pTemp!=NULL)
?? ? {
?? ??? ? if((strcmp(pTemp->item.start_stat,back_start)==0)&&(strcmp(pTemp->item.end_stat,back_end)==0)) ? ? ?/*找到起始終點(diǎn)均相同的站*/
?? ??? ? {
?? ??? ??? ? for(i=0;i<len;i++)
?? ??? ??? ? {
?? ??? ??? ??? ? if(strcmp(back_name,lg[i].name)==0)
?? ??? ??? ??? ? {
?? ??? ??? ??? ??? ? printf("退票成功!\n");
? ? ? ? ? ? ? ? ? ? ?pTemp->item.ticket_lea=pTemp->item.ticket_lea + back_num; ? ? ? //辦理成功,該車次票數(shù)增加
?? ??? ??? ??? ??? ? return 0;
?? ??? ??? ??? ? }
? ? ? ? ? ? ? ? ?else
?? ??? ??? ??? ? {
?? ??? ??? ??? ??? ? printf("未找到您定的票,請問您是否重輸信息繼續(xù)進(jìn)行退票(Y/y || N/n):");
?? ??? ??? ??? ??? ? getchar();
?? ??? ??? ??? ??? ??? ?scanf("%c",&wy);
? ? ? ? ? ? ? ? ? ? ?if(wy=='Y' || wy =='y')
?? ??? ??? ??? ??? ??? ?back(pHead);
?? ??? ??? ??? ??? ?else if(wy=='N' || wy == 'n')
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ? printf("謝謝使用,按任意鍵返回!\n");
?? ??? ??? ??? ??? ??? ? getch();
?? ??? ??? ??? ??? ??? ? return 0;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ? }
?? ??? ??? ? }
?? ??? ? }
?? ??? ?else
?? ??? ??? ?pTemp=pTemp->next;
?? ? }
?? ?printf("\n很遺憾,未找到您要退票的車次,請重新退票!\n");
?? ?back(pHead);
?? ?return 0;
}

//從文件中讀取信息
struct node *read_inf() //從磁盤文件中讀取信息并存入單鏈表?
{
?? ?struct node *head, *r, *train; ? //定義結(jié)構(gòu)體指針變量 ?struct node是類型?
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //head為頭結(jié)點(diǎn)(頭結(jié)點(diǎn)中有信息),r為尾節(jié)點(diǎn), train為當(dāng)前節(jié)點(diǎn)?
?? ?FILE *fp;

?? ?if((fp=fopen("information.txt","rt"))==NULL)
?? ?{
?? ??? ?printf("讀文件出錯(cuò),按任意鍵退出");
?? ??? ?getch();
?? ??? ?exit(1);?
?? ?}
?? ?
?? ?head=(struct node *)malloc(sizeof(struct node)); ? //初始化?
?? ?head->next=NULL;
?? ?
?? ?fscanf(fp,"%s %s %s %s %s %s %d",head->item.start_stat,head->item.end_stat,
?? ??? ??? ?head->item.go_time,head->item.go_data,head->item.train_num,head->item.all_time,&head->item.ticket_lea);
?? ?
?? ?r=head; ?//r是尾節(jié)點(diǎn)?
?? ?while(!feof(fp)) ? ? //文件末結(jié)束?
?? ?{ ? ? ? ? ? ? ? ? ? ? ? ?
?? ??? ?train=(struct node *)malloc(sizeof(struct node)); ? ? ? ?//建立鏈表?
?? ??? ?fscanf(fp,"%s %s %s %s %s %s %d",train->item.start_stat,train->item.end_stat,
?? ??? ??? ?train->item.go_time,train->item.go_data,train->item.train_num,train->item.all_time,&train->item.ticket_lea);
?? ??? ?r->next=train; ? //鏈表節(jié)點(diǎn)?
?? ??? ?r=train;
?? ?}
?? ?r->next=NULL;
?? ?
?? ?fclose(fp);
?? ?printf("\n文件中信息以正確讀出,按任意鍵返回!");
?? ?getch(); ? //清除緩沖區(qū)?
?? ?system("cls");
?? ?return head;?
}

//主界面
void meau()
{
? ? printf("\n");
? ? printf("\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
? ? printf("\t☆==============歡迎使用車票管理系統(tǒng)==============☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~1.存入車票信息~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~2.顯示車票信息~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~3.查詢車票信息~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~4.增加車票信息~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~5.統(tǒng)計(jì) 與 排序~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~6. 訂 ? ? 票~~~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~7. 退 ? ? 票~~~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~8.切換賬號(hào)登錄~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆~~~~~~~~~~~~~~~9.退出管理系統(tǒng)~~~~~~~~~~~~~~~~~~~☆\n");
? ? printf("\t☆================================================☆\n");
? ? printf("\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
? ? printf("請選擇編號(hào)(1-9)選擇功能進(jìn)行相應(yīng)的操作:");
}

//鏈表長度,為了更好的排序?
int listlength(struct node *pHead) ? //判斷鏈表的長度 進(jìn)而知道循環(huán)次數(shù)?
{
?? ?struct node *current;
?? ?int len=0;
?? ?
?? ?current=pHead;
?? ?while(current!=NULL)
?? ?{
?? ??? ?len++; ? ? ? ? ? ? ? ? ? //遍歷一篇 len自增 表示最后鏈表的長度?
?? ??? ?current=current->next;
?? ?}?
?? ?return len;
}

//排統(tǒng)計(jì)序?
void Sort(struct node *pHead)
{
?? ?int len;
?? ?
?? ?struct node *current;
?? ?
?? ?current=pHead;
?? ?len=listlength(pHead); ? ? ? ? //上面一個(gè)函數(shù)的功能判斷鏈表的長度?
?? ?printf("共有%d個(gè)信息\n", len);
?? ?while(len>1)
?? ?{ ? ? ? ? ? ? ? ? ? ? ? //冒泡排序?
?? ??? ?while(current->next != NULL)
?? ??? ?{
?? ??? ??? ?if(strcmp(current->item.all_time, current->next->item.all_time)>0) ? //比較時(shí)間?
?? ??? ??? ?{?? ?
?? ??? ??? ??? ?Item temp; ?//定義一個(gè)交換變量?
?? ??? ??? ??? ?
?? ??? ??? ??? ?temp=current->item;
?? ??? ??? ??? ?current->item=current->next->item;
?? ??? ??? ??? ?current->next->item=temp;
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ??? ?current=current->next;
?? ??? ?}
?? ??? ?len--;
?? ??? ?current=pHead; ? //每次從頭開始遍歷?
?? ?}
?? ?output(pHead); ?//進(jìn)去輸出函數(shù)?
?? ?return;
}?

//主函數(shù)
int main()
{
? ? system("color 4");
? ? printf("歡");sleep(0);
?? ?printf("迎");sleep(1);?
?? ?system("color 3");
?? ?printf("使");sleep(0);
?? ?printf("用");sleep(1);
?? ?system("color 2");
?? ?printf("車");sleep(0);
?? ?printf("票");sleep(1);
?? ?system("color 1");
?? ?printf("管");sleep(0);
?? ?printf("理");sleep(1);?
?? ?system("color 6");
?? ?printf("系");sleep(0);
?? ?printf("統(tǒng)\n");sleep(2);
?? ?printf("\t\t");
?? ?printf("\n");?? ?
?? ?
?? ?system("color 8");?
?? ?printf("\t\t\t即將進(jìn)入登陸注冊頁面請稍候.....");
?? ?sleep(3);
?? ?system("cls");
?? ?
? ? system("color 3");
?? ?
?? ?int x;?
?? ?printf("\t\t1.登陸\t\t\t2.注冊并登錄\n");
?? ?printf("請選擇序號(hào):");
?? ?scanf("%d",&x);
?? ?if(x==1)
?? ??? ?land();
?? ?else if(x==2)
?? ?{
?? ??? ?enroll();
?? ??? ?land();
?? ?}
?? ?else
?? ?{
?? ??? ?printf("輸入無效,即將退出系統(tǒng)!\n");
?? ??? ?exit(1);
?? ?}
?? ?
? ? int choice=8;
?? ?struct node *pHead; ? ? ? ? ? ? ? ? ?//定義頭結(jié)點(diǎn)
?? ?
? ? //選擇編號(hào) ?
? ? while(choice != 10)
? ? { ?
?? ??? ?meau();
?? ??? ?
?? ??? ?scanf("%d",&choice);

?? ??? ?switch(choice)
? ? ? ? { ?
? ? ? ? case 1:system("cls"); pHead=read_inf(); ?break; ? ? ? ??
? ? ? ? case 2:system("cls"); output(pHead); ? ? break; ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? case 3:system("cls"); inquire(pHead); ? ?break;
? ? ? ? case 4:system("cls"); add(pHead); ? save_inf(pHead); ? ? ? ?break;
? ? ? ? case 5:system("cls"); Sort(pHead); ? ? ? break;
? ? ? ? case 6:system("cls"); buy(pHead); ? ? ? ?break;
? ? ? ? case 7:system("cls"); back(pHead); ? ? ? break;
? ? ? ? case 8:land(); break;
? ? ? ? case 9:exit(1);
? ? ? ? default:printf("請輸入正確的編號(hào)!\n"); ?break;
? ? ? ? }?? ?
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++ 中快排的遞歸和非遞歸實(shí)現(xiàn)

    C++ 中快排的遞歸和非遞歸實(shí)現(xiàn)

    這篇文章主要介紹了C++ 中快排的遞歸和非遞歸實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • C語言實(shí)現(xiàn)簡單的三子棋項(xiàng)目

    C語言實(shí)現(xiàn)簡單的三子棋項(xiàng)目

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)簡單的三子棋項(xiàng)目,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • 解析一個(gè)有關(guān)sizeof用法的題目--sizeof(i++)

    解析一個(gè)有關(guān)sizeof用法的題目--sizeof(i++)

    本篇文章是對一個(gè)關(guān)于sizeof用法的題目進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • C++超詳細(xì)講解強(qiáng)制類型轉(zhuǎn)換

    C++超詳細(xì)講解強(qiáng)制類型轉(zhuǎn)換

    在C++語言中新增了四個(gè)關(guān)鍵字static_cast、const_cast、reinterpret_cast和dynamic_cast。這四個(gè)關(guān)鍵字都是用于強(qiáng)制類型轉(zhuǎn)換的
    2022-05-05
  • C++數(shù)組的定義詳情

    C++數(shù)組的定義詳情

    這篇文章主要介紹了C++數(shù)組的定義詳情,上一篇文章我們學(xué)習(xí)了類型,接下倆我們九在類型的基礎(chǔ)上展開本篇內(nèi)容數(shù)組的常用方法以及C++標(biāo)準(zhǔn)庫提供的一些關(guān)于數(shù)組的容器,需要的朋友可以參考一下,希望對你有所幫助
    2021-12-12
  • C++實(shí)現(xiàn)LeetCode(137.單獨(dú)的數(shù)字之二)

    C++實(shí)現(xiàn)LeetCode(137.單獨(dú)的數(shù)字之二)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(137.單獨(dú)的數(shù)字之二),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • C++中的類擴(kuò)展之繼承和組合詳解

    C++中的類擴(kuò)展之繼承和組合詳解

    在C++中,類擴(kuò)展可以通過繼承、組合和裝飾模式實(shí)現(xiàn)。繼承可以實(shí)現(xiàn)對已有類的修改和擴(kuò)展,組合可以增加新的功能,裝飾模式則能夠在不改變原類的情況下為其添加新的功能。這些技術(shù)在C++程序設(shè)計(jì)中應(yīng)用廣泛,提高了程序的可擴(kuò)展性和可維護(hù)性
    2023-04-04
  • C++面試八股文之如何實(shí)現(xiàn)strncpy函數(shù)

    C++面試八股文之如何實(shí)現(xiàn)strncpy函數(shù)

    strncpy函數(shù),主要用做字符串復(fù)制,將于字符從一個(gè)位置復(fù)制到另一個(gè)位置,那么如何實(shí)現(xiàn)一個(gè)strncpy函數(shù),下面小編就來和大家簡單講講吧
    2023-07-07
  • C++第三方日志庫log4cplus的安裝與使用配置教程

    C++第三方日志庫log4cplus的安裝與使用配置教程

    log4cplus是C++編寫的開源的日志系統(tǒng),log4cplus具有線程安全、靈活、以及多粒度控制的特點(diǎn),本文給大家介紹C++第三方日志庫log4cplus的安裝與使用教程,感興趣的朋友一起看看吧
    2022-02-02
  • c++ 網(wǎng)絡(luò)庫asio的優(yōu)勢

    c++ 網(wǎng)絡(luò)庫asio的優(yōu)勢

    這篇文章主要介紹了c++ 網(wǎng)絡(luò)庫asio的優(yōu)勢,幫助大家更好的利用c++開發(fā)服務(wù)端程序,感興趣的朋友可以了解下
    2020-10-10

最新評論