C语言课程设计实验报告

华中科技大学计算机科学与技术学院

《C语言程序设计》课程设计

实验报告

题目: 汽车租赁信息管理系统

专业: 班级: 学号:

完成日期: 20xx年 10 月 21 日

指导教师: 姓名: 成绩:

一、题目

汽车租赁信息管理系统

对某汽车租赁公司汽车租赁信息进行管理,包括汽车基本信息和汽车租赁信息。

(1)需要处理的基础数据

a) 汽车租赁公司信息参考:

C语言课程设计实验报告

b) 汽车基本信息参考:

C语言课程设计实验报告

c) 汽车租赁信息参考:

C语言课程设计实验报告

(2)系统功能

a) 各种基本数据的录入。如:汽车基本信息录入、租赁公司信息录入、汽车租赁信息录入。

b) 各种基本数据的修改。即:允许对已经录入的数据重新进行编辑、修改。

c) 各种基本数据的插入。

d) 各种基本数据的删除。

e) 基于各种数据的查询。如:某租赁公司在指定日期的租车信息。

f) 基于各种基本数据的统计计算。如:

(I)统计各汽车租赁公司总汽车数和租金总额,按租金总额从高到低排序后输出。 (II)统计某年度十二个月份汽车租赁的总次数和总租金。

(III)统计各公司各类汽车出租次数、出租金额,按出租金额从高到低排序后输出。

(IV)分别统计出租率最高的5家公司,从高到低排序后输出公司名称、公司汽车总数、出租总次数。

(V)汽车租赁信息其它方面的统计。

二、系统功能模块结构图

C语言课程设计实验报告

三、数据结构设计及用法说明

这个系统是采用三个方向的十字链表,其中第一条链是汽车租赁公司的基本信息,包括公司名称、汽车类型和各类型汽车数量,第二条链是汽车基本信息,包括汽车类型、公司名称、汽车数、日租金、联系人和联系电话,第三条链是汽车租赁的基本信息,包括客户姓名、身份证号、租车日期、租车天数、公司名称、汽车类型和租车数目。

下图就是数据三个方向的十字交叉链表

C语言课程设计实验报告

四、程序结构

下图为程序结构的流程图:

C语言课程设计实验报告

五、各模块的功能

Build :Load:将已经存好的数据导入

New:输入新的数据

Save:将输入的数据保存

Quit:退出程序

Search:Firm:查询公司信息

Bus:查询汽车信息

Busrent查询汽车租赁信息

Modify:Firm:修改公司信息

Bus:修改汽车信息

Busrent:修改汽车租赁信息

Delete:Firm:删除公司信息

Bus:删除汽车信息

Busrent:删除汽车租赁信息

Insert:Firm:插入公司信息

Bus:插入汽车信息

Busrent:插入汽车租赁信息

Output:Firm:输出公司信息

Bus:输出汽车信息

Busrent:输出汽车租赁信息

Censue:Tongji1:统计每个公司的汽车总数和租赁的总收入

Tongji2:统计每个年度所有公司出租汽车总数和总收入 Tongji3:统计每个公司每种类型的汽车出租次数和收入

Tongji4:统计每个公司汽车的出租率、总汽车数和租出汽车次数 Tongji5:统计所有公司的所有年度汽车出租总数和总收入

六、试验结果

C语言课程设计实验报告

C语言课程设计实验报告

C语言课程设计实验报告

七、体会

这次实验结合了C语言里面的数组、指针、链表、文件等知识点。刚开始的时候不知道如何下手,后来在相关书籍上找了相似的程序慢慢分析后开始自己尝试着写,因为开始的时候还是不会,就和寝室里面的人讨论、相互参考,经过几天的研究,我们终于写出了第一个界面,有了第一次的经验,我慢慢的写出了Build函数以及后面的函数。最难的就是函数的调试了,开始运行的时候报错特别多,自己就那样一点一点的调,错误也渐渐减少,但是到最后又几个错误不管我怎么调就是报错,当时真的很着急,后来找到了班上成绩比较好的同学,纵欲把最后几个报错的地方改正了。经过这么多的曲折,当我看到自己写出来的程序时心里有的是高兴与激动。或许对于别人来说,这次的实验只是小菜一碟,但对我来说,这是经过我的付出与努力换来的。

八、参考文献

1.C语言程序设计 曹计昌 卢萍 李开编著 辞学出版社

2.Turbo C 使用大全第一册、第二册 徐金梧等编译 北京科海培训中心

3.C程序设计 谭浩强 清华大学出版

4.C语言程序设计 廖雷 高等教育出版社

九、程序清单

#include<stdio.h>

#include<stdlib.h> #include<conio.h>

#include<string.h> typedef struct buscode {

char busnum[5];

char type[2];

char firm[30];

int rent;

char contactor[20]; char tel[20];

struct buscode *next; struct buscode *right; }L;

typedef struct bus_rentcode {

char busnum[5]; char name[20];

char id_card_num[20]; char rent_date[12]; int rent_days;

char firm_name[30]; int mount;

struct bus_rentcode *next; }H;

typedef struct firmcode {

char name[30]; int mount1;

int mount2;

int mount3;

struct firmcode *next; struct firmcode *down; }T;

char *Menu[] = {"Build", "Quit", "Search", "Modify", "Delete", "Insert", "Output", "Census"};

char *Prompt[] = {"F1-Help",

"F5-Zoom",

"F6-Switch",

"F7-Trace",

"F8-Step",

"F9-Make",

"F10-Menu",

"NUM"};

char *Menus[] = {"Load",

"New",

"Save",

"Are you sure?",

"Firm",

"Bus",

"Busrent",

"Firm",

"Bus",

"Busrent",

"Firm",

"Bus",

"Busrent",

"Firm",

"Bus",

"Busrent",

"Firm",

"Bus",

"Busrent",

"tongji 1",

"tongji 2",

"tongji 3",

"tongji 4",

"tongji 5"};

int MnN[] = { 3, 1, 3, 3, 3, 3, 3, 5}; int MnLoc[][5] = {{4,3,2,18,6},

{13,10,2,25,4},

{22,17,2,42,6},

{32,23,2,57,6},

{42,33,2,69,6},

{52,43,2,62,6},

{62,45,2,79,6}, {72,50,2,79,8}}; int Mnm, Mns;

char buf[30*25*2], buf1[40*3*2];

void output_firm(T *head) ; void build(T **);

void Save(T *head);

void output_bus(T *head);

void Load(T **head);

void output_busrent(T *head); void Insert_firm(T *head); void Insert_bus(T *head);

void Insert_busrent(T *head); void Delete_firm(T *head); void Delete_bus(T *head);

void Delete_busrent(T *head); void Search_firm(T *head); void Search_bus(T *head);

void Search_busrent(T *head); void Modify_firm(T *head); void Modify_bus(T *head);

void Modify_busrent(T *head); void tongji1(T *head);

void tongji2(T *head);

void tongji3(T *head);

void tongji4(T *head);

void tongji5(T *head);

void ShowMenuM (void);

void SetMenuM (int );

void ClrMenuM (int );

void ShowMenuS (int );

void HideMenuS (int );

void SetMenuS (int );

void ClrMenuS (int );

void SelLR (int );

void SelUD (int );

void ExeItem (int, int); void ScanKb (int *, int *);

T *hp=NULL;

L *t1;

H *t2;

void main(void)

{

int i,idx,key0,key1,flag = 1;

textbackground(CYAN);

clrscr( );

ShowMenuM();

Mnm = 1;

Mns = 0;

SetMenuM(Mnm);

while(flag){

key0=key1=0;

ScanKb(&key0, &key1);

if(key0 != 0){ /*if an ordinary key is pressed*/ if(Mns == 0){ /*operate on main menu*/ if(key0 == 13)

ShowMenuS(Mnm);

else{

for(i=0;i<8;i++)

if(key0 - *Menu[i] == 0 || key0 - *Menu[i] == 32) break;

if(i < 8)

ShowMenuS(i+1);

}

}

else{ /*operate on sub menu*/ if(key0 == 13)

ExeItem(Mnm,Mns);

else if(key0 == 27){

HideMenuS(Mnm);

Mns = 0;

}

else{

for(i=1,idx=0;i<Mnm;i++)

idx += MnN[i-1];

for(i=idx;i<idx+MnN[Mnm-1];i++)

if(key0 - *Menus[i] == 0 || key0 - *Menus[i] == 32) break;

if(i < idx + MnN[Mnm-1])

ExeItem(Mnm,i - idx + 1);

}

}

}

else{ /*if a special key is pressed*/ switch(key1){

case 33: ShowMenuS(1); break; /*Alt+F*/ case 18: ShowMenuS(2); break; /*Alt+E*/ case 19: ShowMenuS(3); break; /*Alt+R*/ case 46: ShowMenuS(4); break; /*Alt+C*/ case 25: ShowMenuS(5); break; /*Alt+P*/ case 24: ShowMenuS(6); break; /*Alt+O*/ case 32: ShowMenuS(7); break; /*Alt+D*/ case 48: ShowMenuS(8); break; /*Alt+B*/

case 61: ExeItem(1,1); break; /*F3*/ case 106:ExeItem(1,2); break; /*Alt+F3*/ case 60: ExeItem(1,4); break; /*F2*/ case 45: flag = 0; break; /*Alt+X*/

case 102:ExeItem(3,1); break; /*Ctrl+F9*/ case 95: ExeItem(3,2); break; /*Ctrl+F2*/ case 62: ExeItem(3,3); break; /*F4*/ case 65: ExeItem(3,4); break; /*F7*/ case 66: ExeItem(3,5); break; /*F8*/ case 108:ExeItem(3,6); break; /*Alt+F5*/

case 97: ExeItem(7,1); break; /*Ctrl+F4*/ case 96: ExeItem(7,2); break; /*Ctrl+F3*/

case 100:ExeItem(8,1); break; /*Ctrl+F7*/ case 101:ExeItem(8,6); break; /*Ctrl+F8*/

case 72: SelUD(-1); break; /*UP*/ case 80: SelUD( 1); break; /*DOWN*/ case 75: SelLR(-1); break; /*LEFT*/ case 77: SelLR( 1); break; /*Right*/ }

}

}

}

void ShowMenuM(void) /*show main menu*/ {

int i;

window(1,1,80,1);

textbackground(GREEN);

textcolor(YELLOW);

clrscr( );

for(i=0; i<8; i++){

gotoxy(MnLoc[i][0], 1);

textcolor(RED);

cprintf("%c", *Menu[i]);

textcolor(BLACK);

cprintf("%s", Menu[i]+1);

}

}

void SetMenuM(int mmn) /*tag main menu*/

{

window(1,1,80,1);

textbackground(GREEN);

textcolor(YELLOW);

gotoxy(MnLoc[mmn-1][0], 1);

cprintf("%s", Menu[mmn-1]);

}

void ClrMenuM(int mmn) /*clear the tag of main menu*/ {

window(1,1,80,1);

textbackground(GREEN);

gotoxy(MnLoc[mmn-1][0], 1);

textcolor(RED);

cprintf("%c", *Menu[mmn-1]);

textcolor(BLACK);

cprintf("%s", Menu[mmn-1]+1);

}

void ShowMenuS(int mmn) /*show sub menu of main menu mmn*/ {

int i, left, top, right, bottom, ht, wd, idx;

if(mmn == Mnm && Mns > 0)

return;

if(mmn != Mnm){

if(Mns>0 ) HideMenuS(Mnm);

ClrMenuM(Mnm);

SetMenuM(Mnm=mmn);

}

Mns = 1;

left = MnLoc[Mnm-1][1];

top = MnLoc[Mnm-1][2];

right = MnLoc[Mnm-1][3];

bottom = MnLoc[Mnm-1][4];

ht = bottom - top + 1;

wd = right - left + 1;

for(i=1,idx=0;i<Mnm;i++)

idx += MnN[i-1];

gettext(left, top, right, bottom, buf);

window (left, top, right, bottom);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr( );

window (left, top, right, bottom + 1);

putch(0xda);

for(i=2;i<wd;i++)

putch(0xc4);

putch(0xbf);

for(i=2;i<ht;i++){

gotoxy(1,i);

textcolor(BLACK);

cprintf("%c %-*s%c", 0xb3, wd - 3, Menus[idx+i-2], 0xb3);

gotoxy(3,i);

textcolor(RED);

cprintf("%c", *Menus[idx+i-2]);

}

gotoxy(1,i);

textcolor(BLACK);

putch(0xc0);

for(i=2;i<=right-left;i++)

putch(0xc4);

putch(0xd9);

SetMenuS(Mns);

}

void HideMenuS(int mmn) /*hide sub menu of main menu mmn*/ {

int left, top, right, bottom;

left = MnLoc[mmn-1][1];

top = MnLoc[mmn-1][2];

right = MnLoc[mmn-1][3];

bottom = MnLoc[mmn-1][4];

puttext(left, top, right, bottom, buf);

Mns = 0;

}

void SetMenuS(int smn) /*tag sub menu*/

{

int i, left, top, right, bottom, ht, wd, idx;

ClrMenuS(Mns);

Mns = smn;

left = MnLoc[Mnm-1][1];

top = MnLoc[Mnm-1][2];

right = MnLoc[Mnm-1][3];

bottom = MnLoc[Mnm-1][4];

wd = right - left + 1;

for(i=1,idx=0;i<Mnm;i++)

idx += MnN[i-1];

idx += Mns - 1;

window (left, top, right, bottom);

textbackground(BLACK);

textcolor(WHITE);

gotoxy(2,Mns+1);

cprintf(" %-*s", wd - 3, Menus[idx]);

}

void ClrMenuS(int smn) /*clear the tag of sub menu*/ {

int i, left, top, right, bottom, ht, wd, idx;

left = MnLoc[Mnm-1][1];

top = MnLoc[Mnm-1][2];

right = MnLoc[Mnm-1][3];

bottom = MnLoc[Mnm-1][4];

wd = right - left + 1;

for(i=1,idx=0;i<Mnm;i++)

idx += MnN[i-1];

idx += smn - 1;

window (left, top, right, bottom);

textbackground(WHITE);

textcolor(BLACK);

gotoxy(2,smn+1);

cprintf(" %-*s", wd - 3, Menus[idx]);

gotoxy(3,smn+1);

textcolor(RED);

cprintf("%c", *Menus[idx]);

}

void SelLR(int lr) /*select menu item left or right*/ {

int mmn = Mnm + lr;

if(mmn > 8)

mmn = 1;

else if(mmn < 1)

mmn = 8;

if(Mns > 0)

ShowMenuS(mmn);

else{

ClrMenuM(Mnm);

SetMenuM(Mnm=mmn);

}

}

void SelUD(int ud) /*select submenu item up or down*/ {

int smn = Mns + ud;

if(Mnm == 2)

return;

if(smn > MnN[Mnm-1])

smn = 1;

else if(smn < 1)

smn = MnN[Mnm-1];

if(Mns == 0){

if(ud == 1) ShowMenuS(Mnm);

}

else{

if(Mnm == 8 && smn == 8)

if(ud > 0) smn++; else smn--;

ClrMenuS(Mns);

SetMenuS(Mns=smn);

}

}

void ExeItem(int mmn, int smn) /*execute the corresponding command*/ {

if(mmn == 1 && smn == 1) Load(&hp);

if(mmn == 1 && smn == 2) build(&hp);

if(mmn == 1 && smn == 3) Save(hp);

if(mmn == 2 && smn == 1) exit(0);

if(mmn == 3 && smn == 1) Search_firm(hp);

if(mmn == 3 && smn == 2) Search_bus(hp);

if(mmn == 3 && smn == 3) Search_busrent(hp);

if(mmn == 4 && smn == 1) Modify_firm(hp);

if(mmn == 4 && smn == 2) Modify_bus(hp);

if(mmn == 4 && smn == 3) Modify_busrent(hp);

if(mmn == 5 && smn == 1) Delete_firm(hp);

if(mmn == 5 && smn == 2) Delete_bus(hp);

if(mmn == 5 && smn == 3) Delete_busrent(hp);

if(mmn == 6 && smn == 1) Insert_firm(hp);

if(mmn == 6 && smn == 2) Insert_bus(hp);

if(mmn == 6 && smn == 3) Insert_busrent(hp);

if(mmn == 7 && smn == 1) output_firm(hp);

if(mmn == 7 && smn == 2) output_bus(hp);

if(mmn == 7 && smn == 3) output_busrent(hp);

if(mmn == 8 && smn == 1) tongji1(hp);

if(mmn == 8 && smn == 2) tongji2(hp);

if(mmn == 8 && smn == 3) tongji3(hp);

if(mmn == 8 && smn == 4) tongji4(hp);

if(mmn == 8 && smn == 5) tongji5(hp);

if(Mns > 0 && Mnm != 2) HideMenuS(Mnm);

}

void ScanKb(int *pk0, int *pk1) /*accept input from keyboard*/ {

int key;

while (bioskey(1) == 0);

key = bioskey(0);

*pk0 = key & 0xff;

*pk1 = (key >> 8) & 0xff;

}

void build(T **head) /* 生成链表函数具体实现 */ {

T *hp=NULL;

int a=1;

char ch;

T *p;

L *t1=NULL;

H *t2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(1,1);

do{

p=(T *)malloc(sizeof(T)); /*创建公司基本信息第一个结点*/

cprintf("please input the firm name:\n");

scanf("%s",p->name);

getchar();

clrscr();

cprintf("please input the mount of bus type1:\n");

scanf("%d",&p->mount1);

getchar();

clrscr();

cprintf("please input the mount of bus type2:\n");

scanf("%d",&p->mount2);

getchar();

clrscr();

cprintf("please input the mount of bus type3:\n");

scanf("%d",&p->mount3);

getchar();

clrscr();

p->down=NULL; /*置汽车信息链的头指针为空*/

p->next=hp; /*公司基本信息链头指针值赋给结点的 next域*/

hp=p; /*头指针指向新创建的结点*/

cprintf("Do you want continue?'y'or'n'\n");

ch=getchar();getchar();

if(ch=='n'||ch=='N') break;

}while(a);

(*head)=hp; /*调用函数中的head头指针指向新创建的公司基本信息结点*/

p=(*head); /* p1指向公司信息链的链头*/

while(p!=NULL){

cprintf(" Continue input bus message?'y'or'n'\n");

ch=getchar();getchar();

if(ch=='n'||ch=='N') {

clrscr();

break;

}

while(ch=='y'||ch=='Y'){

t1=(L *)malloc(sizeof(L)); /*创建汽车信息的结点*/

cprintf("please input the bus number:\n");

scanf("%s",t1->busnum);

getchar();

clrscr();

cprintf("please input the bus type:\n");

scanf("%s",t1->type);

getchar();

clrscr();

cprintf("please input the firm name:\n");

scanf("%s",t1->firm);

getchar();

clrscr();

cprintf("please input the rent of one day:\n");

scanf("%d",&t1->rent);

getchar();

clrscr();

cprintf("please input the contactor name:\n");

scanf("%s",t1->contactor);

getchar();

clrscr();

cprintf("please input the telephone:\n");

scanf("%s",t1->tel);

getchar();

clrscr();

t1->right=NULL; /*

置汽车信息链的头指针为空*/

t1->next=(L *)p->down; /*头指针值赋给新结点的指针域*/

p->down=(T *)t1; /*头指针指向新结点*/

cprintf("Continue input the bus message?'y'or'n'\n");

ch=getchar();getchar();

if(ch=='n'||ch=='N') {

clrscr();

break;

}

}

while(p!=NULL){

if(t1!=NULL){

cprintf("Continue input the bus rent message?'y'or'n'\n");

ch=getchar();getchar();

}

if(ch=='n'||ch=='N') {

clrscr();

break;

}

while(ch=='y'||ch=='Y'){

t2=(H *)malloc(sizeof(H));

cprintf("please input the bus number:\n");

scanf("%s",t2->busnum);

getchar();

clrscr();

cprintf("please input the custorm's name:\n");

scanf("%s",t2->name);

getchar();

clrscr();

cprintf("please input the custorm's id_card_num:\n");

scanf("%s",t2->id_card_num);

getchar();

clrscr();

cprintf("please input the rent_date:\n");

scanf("%s",t2->rent_date);

getchar();

clrscr();

cprintf("please input the rent_days:\n");

scanf("%d",&t2->rent_days);

clrscr();

cprintf("please input the firm_name:\n");

scanf("%s",t2->firm_name);

getchar();

clrscr();

cprintf("please input the mount of rent:\n");

scanf("%d",&t2->mount);

getchar();

clrscr();

t2->next=(H *)t1->right; /*头指针值赋给新结点的指针域*/

t1->right=(L *)t2; /*头指针指向新结点*/

cprintf("Continue input this bus rent message?'y'or'n'\n");

ch=getchar();getchar();

if(ch=='n'||ch=='N') {

clrscr();

break;

}

}

t1=t1->next; /*t1指向汽车信

息链的下一个结点*/

}

p=p->next;

}

clrscr();

} /*指向公司信息链的下一个结点*/

void output_firm(T *head)

{

int i=2,j=0;

T *p=head;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

while(p!=NULL){

cprintf("firm name:%s",p->name);

gotoxy(1,i);

i++;

cprintf("bus type 1:qiche 2:jiaoche 3:huoche");

gotoxy(1,i);

i++;

cprintf("bus type1:%d bus type2:%d

type3:%d",p->mount1,p->mount2,p->mount3);

gotoxy(1,i);

i++;

p=p->next;

getch();

j++;

if(j==8){

clrscr();

i=2;

j=0;

}

}

clrscr();

}

void output_bus(T *head)

{

int i=2,j=0;

T *p=head;

L *t1=NULL;

window(1,2,80,25);

textbackground(CYAN); bus

textcolor(BLACK);

clrscr();

while(p!=NULL){

if((p->down)!=NULL){

cprintf("firm name:%s",p->name);

gotoxy(1,i);

i++;

cprintf("bus type 1:qiche 2:jiaoche 3:huoche\n"); gotoxy(6,i);

i++;

t1=(L *)p->down;

}

while(t1!=NULL){

cprintf("bus number:%s",t1->busnum);

gotoxy(6,i);

i++;

cprintf("bus type:%s",t1->type);

gotoxy(6,i);

i++;

cprintf("the rent of one day:%d yuan",t1->rent); gotoxy(6,i);

i++;

cprintf("the contactor name:%s",t1->contactor);

gotoxy(6,i);

i++;

cprintf("the telephone:%s",t1->tel);

gotoxy(6,i);

i++;

t1=t1->next;

getch();

j++;

if(j==3){

clrscr();

i=4;

j=0;

cprintf("firm name:%s",p->name);

gotoxy(1,2);

cprintf("bus type 1:qiche 2:jiaoche 3:huoche"); gotoxy(6,3);

}

}

p=p->next;

clrscr();

i=2;

j=0; }

clrscr(); }

void Save(T *head) {

FILE *out1,*out2,*out3; T *p=head; L *t1=NULL; H *t2=NULL;

if((out1=fopen("f:\\firm.dat","wb"))==NULL) /**/

exit(-1);

if((out2=fopen("f:\\bus.dat","wb"))==NULL) /* exit(-1);

if((out3=fopen("f:\\busrent.dat","wb"))==NULL) /**/

exit(-1); while(p!=NULL){

fwrite(p,sizeof(T),1,out1); 录*/

t1=(L *)p->down; /*息遍历指针指向汽车信息链的链头*/ while(t1!=NULL){

fwrite(t1,sizeof(L),1,out2); 录*/

t2=(H *)t1->right; while(t2!=NULL){

fwrite(t2,sizeof(H),1,out3); /*记录*/

t2=t2->next; /*汽车租赁信息结点*/ }

t1=t1->next; /*个汽车信息结点*/ }

p=p->next; /*个公司比本信息结点*/ }

fclose(out1); /*司信息文件*/

fclose(out2); /*汽车信息文件*/

打开公司基本信息文件打开汽车基本信息文件*/ 打开汽车租赁信息文件 /*写公司基本信息记汽车信 /*写汽车信息记写汽车租赁信息指向下一个指向下一指向下一关闭公关闭

fclose(out3); /*关闭汽车租赁信息文件*/

}

void Load(T **head)

{

FILE *in1,*in2,*in3;

T *hp=NULL,*p;

L *t1=NULL;

H *t2=NULL;

if((in1=fopen("f:\\firm.dat","rb"))==NULL) /*打开公司基本信息文件*/

exit(-1);

if((in2=fopen("f:\\bus.dat","rb"))==NULL) /*打开汽车信息文件*/

exit(-1);

if((in3=fopen("f:\\busrent.dat","rb"))==NULL) /*打开汽车租赁信息文件*/

exit(-1);

while(!feof(in1)){

p=(T *)malloc(sizeof(T)); /*创建公司基本信息结点*/

fread(p,sizeof(T),1,in1); /*读一条公司基本信息记录到结点中*/

if(!feof(in1)){

p->down=NULL; /*置汽车信息链的头指针为NULL*/

p->next=hp; /*公司基本信息链头指针值赋给结点的next域*/

hp=p; /*头指针指向新创建的结点*/

}

}

(*head)=hp; /*调用函数中的head头指针指向新创建的公司基本信息链*/

while(!feof(in2)){

t1=(L *)malloc(sizeof(L)); /*创建新汽车信息结点*/

fread(t1,sizeof(L),1,in2); /*读一条汽车信息记录到新结点*/

if(!feof(in2)){

p=(*head); /*遍历指针p指向公司基本信息链的链头*/

while(p!=NULL){ /*遍历公司基本信息

链*/

if(!strcmp(p->name,t1->firm)){ /*查找相同公司名的结点*/

t1->right=NULL;

t1->next=(L *)p->down; /*找到,新结点加入汽车信息链*/

p->down=(T *)t1;

break;

}

else

p=p->next; /*没找到,转下一结点*/

}

}

}

while(!feof(in3)){

t2=(H *)malloc(sizeof(H));

fread(t2,sizeof(H),1,in3);

if(!feof(in3)){

p=(*head);

while(p!=NULL){

t1=(L *)p->down;

while(t1!=NULL){

if(!strcmp(t1->busnum,t2->busnum)){

t2->next=(H *)t1->right;

t1->right=(L *)t2;

break;

}

else

t1=t1->next;

}

p=p->next;

}

}

}

fclose(in1); /*关闭公司基本信息文件*/

fclose(in2); /*关闭汽车信息文件*/ fclose(in3); /*关闭汽车租赁信息文件*/

}

void output_busrent(T *head)

{

int i=2,j=0;

T *p=head;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

while(p!=NULL){

t1=(L *)p->down;

while(t1!=NULL){

t2=(H *)t1->right;

while(t2!=NULL){

cprintf("firm name:%s\n",t2->firm_name);

gotoxy(1,i);

i++;

cprintf("bus type:%s\n",t1->type);

gotoxy(1,i);

i++;

cprintf("bus number:%s\n",t2->busnum);

gotoxy(1,i);

i++;

cprintf("customer'name:%s\n",t2->name);

gotoxy(1,i);

i++;

cprintf("customer's id card number:%s\n",t2->id_card_num); gotoxy(1,i);

i++;

cprintf("the rent date:%s\n",t2->rent_date);

gotoxy(1,i);

i++;

cprintf("rent days:%d days\n",t2->rent_days);

gotoxy(1,i);

i++;

cprintf("the rent mount:%d\n",t2->mount);

gotoxy(1,i);

i++;

t2=t2->next;

getch();

j++;

if(j==2){

clrscr();

i=2;

j=0;

}

}

t1=t1->next;

}

p=p->next;

}

clrscr();

}

void Insert_firm(T *head)

{

int i=2,j=0,k;

int ch;

T *p=head,*p1=NULL,*p2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

cprintf("(1)head;");

gotoxy(20,2);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name);

gotoxy(20,i+1);

p=p->next;

i++;

j++;

}

do{

cprintf("please choose where to insert(1--%d):",j+1); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j+1);

if(ch==1){

clrscr();

p1=(T *)malloc(sizeof(T));

cprintf("please input the firm name:\n");

scanf("%s",p1->name);

getchar();

clrscr();

cprintf("please input the mount of bus type1:\n"); scanf("%d",&p1->mount1);

getchar();

clrscr();

cprintf("please input the mount of bus type2:\n"); scanf("%d",&p1->mount2);

getchar();

clrscr();

cprintf("please input the mount of bus type3:\n"); scanf("%d",&p1->mount3);

getchar();

clrscr();

p1->down=NULL;

p1->next=hp;

hp=p1;

p=p1;

}

if(j==0) return;

if(ch==j+1){

clrscr();

p=head;

while((p->next)!=NULL){

p=p->next;

}

p1=(T *)malloc(sizeof(T));

cprintf("please input the firm name:\n");

scanf("%s",p1->name);

getchar();

clrscr();

cprintf("please input the mount of bus type1:\n"); scanf("%d",&p1->mount1);

getchar();

clrscr();

cprintf("please input the mount of bus type2:\n"); scanf("%d",&p1->mount2);

getchar();

clrscr();

cprintf("please input the mount of bus type3:\n"); scanf("%d",&p1->mount3);

getchar();

clrscr();

p1->next=NULL;

p1->down=NULL;

p->next=p1;

p=head;

}

if(ch>1&&ch<j+1){

clrscr();

p1=head;

for(k=1;k<ch-1;k++){

p1=p1->next;

}

p=p1->next;

p2=(T *)malloc(sizeof(T));

cprintf("please input the firm name:\n");

scanf("%s",p2->name);

getchar();

clrscr();

cprintf("please input the mount of bus type1:\n"); scanf("%d",&p2->mount1);

getchar();

clrscr();

cprintf("please input the mount of bus type2:\n"); scanf("%d",&p2->mount2);

getchar();

clrscr();

cprintf("please input the mount of bus type3:\n"); scanf("%d",&p2->mount3);

getchar();

clrscr();

p2->next=p;

p2->down=NULL;

p1->next=p2;

p=head;

}

}

void Insert_bus(T *head)

{

int i=1,j=0,k;

int ch;

T *p=head;

L *p1=NULL,*p2=NULL,*r=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name);

gotoxy(20,i+1);

p=p->next;

i++; j++; } p=head; if(p==NULL){ gotoxy(10,1); cprintf("No place to insert bus message!"); gotoxy(10,2); cprintf("Please insert firm message first!"); getch(); clrscr(); return; } else{ do{ cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); } clrscr(); p=head; for(k=0;k<ch-1;k++){ p=p->next; } p1=(L *)p->down; i=2; j=0; gotoxy(20,1); cprintf("(1)head;"); gotoxy(20,2); while(p1!=NULL){ cprintf("(%d)bus number:%s;",i,p1->busnum); gotoxy(20,i+1); p1=p1->next; i++; j++; } p1=(L *)p->down; if(p1!=NULL){ do{ cprintf("please choose bus second(1--%d):",j+1); scanf("%d",&ch);

gotoxy(20,i+1); i++; }while(ch<1||ch>j+1); if(ch==j+1){ clrscr(); p1=(L *)p->down; while((p1->next)!=NULL){ p1=p1->next; } p2=(L *)malloc(sizeof(L)); /*创建汽车信息的结点*/ cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar(); clrscr(); cprintf("please input the bus type:\n"); scanf("%s",&p2->type); getchar(); clrscr(); cprintf("please input the firm name:\n"); scanf("%s",p2->firm); getchar(); clrscr(); cprintf("please input the rent of one day:\n"); scanf("%d",&p2->rent); getchar(); clrscr(); cprintf("please input the contactor name:\n"); scanf("%s",p2->contactor); getchar(); clrscr(); cprintf("please input the telephone:\n"); scanf("%s",p2->tel); getchar(); clrscr(); p2->right=NULL; p2->next=NULL; p1->next=p2; } if(ch>1&&ch<j+1){ clrscr(); p1=(L *)p->down; for(k=1;k<ch-1;k++){ p1=p1->next; }

r=p1->next; p2=(L *)malloc(sizeof(L)); /*创建汽车信息的结点*/ cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar(); clrscr(); cprintf("please input the bus type:\n"); scanf("%s",&p2->type); getchar(); clrscr(); cprintf("please input the firm name:\n"); scanf("%s",p2->firm); getchar(); clrscr(); cprintf("please input the rent of one day:\n"); scanf("%d",&p2->rent); getchar(); clrscr(); cprintf("please input the contactor name:\n"); scanf("%s",p2->contactor); getchar(); clrscr(); cprintf("please input the telephone:\n"); scanf("%s",p2->tel); getchar(); clrscr(); p2->right=NULL; p2->next=r; p1->next=p2; } if(ch==1){ clrscr(); p1=(L *)p->down; p2=(L *)malloc(sizeof(L)); /*创建汽车信息的结点*/ cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar(); clrscr(); cprintf("please input the bus type:\n"); scanf("%s",&p2->type); getchar(); clrscr(); cprintf("please input the firm name:\n"); scanf("%s",p2->firm);

getchar(); clrscr(); cprintf("please input the rent of one day:\n"); scanf("%d",&p2->rent); getchar(); clrscr(); cprintf("please input the contactor name:\n"); scanf("%s",p2->contactor); getchar(); clrscr(); cprintf("please input the telephone:\n"); scanf("%s",p2->tel); getchar(); clrscr(); p2->right=NULL; p2->next=p1; p->down=(T *)p2; } } if(p1==NULL){ clrscr(); p2=(L *)malloc(sizeof(L)); /*创建汽车信息的结点*/ cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar(); clrscr(); cprintf("please input the bus type:\n"); scanf("%s",&p2->type); getchar(); clrscr(); cprintf("please input the firm name:\n"); scanf("%s",p2->firm); getchar(); clrscr(); cprintf("please input the rent of one day:\n"); scanf("%d",&p2->rent); getchar(); clrscr(); cprintf("please input the contactor name:\n"); scanf("%s",p2->contactor); getchar(); clrscr(); cprintf("please input the telephone:\n"); scanf("%s",p2->tel);

getchar();

clrscr();

p2->right=NULL;

p2->next=NULL;

p->down=(T *)p2;

}

}

void Insert_busrent(T *head)

{

int i=1,j=0,k;

int ch;

T *p=head;

L *t1=NULL;

H *p1=NULL,*p2=NULL,*r=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name);

gotoxy(20,i+1);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

gotoxy(6,1);

cprintf("No place to insert busrent message!"); gotoxy(6,2);

cprintf("Please insert firm message first!"); getch();

clrscr();

return;

}

else{

do{

cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j);

} clrscr(); p=head; for(k=0;k<ch-1;k++){ p=p->next; } t1=(L *)p->down; i=1; j=0; gotoxy(20,1); while(t1!=NULL){ cprintf("(%d)bus number:%s;",i,t1->busnum); gotoxy(20,i+1); t1=t1->next; i++; j++; } t1=(L *)p->down; if(t1==NULL){ gotoxy(6,1); cprintf("No place to insert busrent message!"); gotoxy(6,2); cprintf("Please insert bus message first!"); getch(); clrscr(); return; } else{ do{ cprintf("please choose bus second(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); } for(k=0;k<ch-1;k++){ t1=t1->next; } clrscr(); p1=(H *)t1->right; i=2; j=0; gotoxy(20,1); cprintf("(1)head;");

gotoxy(20,2); while(p1!=NULL){ cprintf("(%d)custorm's name:%s;",i,p1->name); gotoxy(20,i+1); p1=p1->next; i++; j++; } p1=(H *)t1->right; if(p1!=NULL){ do{ cprintf("please choose custorm's name third(1--%d):",j+1); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j+1); if(ch==j+1){ clrscr(); p1=(H *)t1->right; while((p1->next)!=NULL){ p1=p1->next; } p2=(H *)malloc(sizeof(H)); cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar(); clrscr(); cprintf("please input the custorm's name:\n"); scanf("%s",p2->name); getchar(); clrscr(); cprintf("please input the custorm's id_card_num:\n"); scanf("%s",p2->id_card_num); getchar(); clrscr(); cprintf("please input the rent_date:\n"); scanf("%s",p2->rent_date); getchar(); clrscr(); cprintf("please input the rent_days:\n"); scanf("%d",&p2->rent_days); clrscr(); cprintf("please input the firm_name:\n"); scanf("%s",p2->firm_name);

getchar(); clrscr(); cprintf("please input the mount of rent"); scanf("%d",&p2->mount); getchar(); clrscr(); p2->next=NULL; p1->next=p2; } if(ch>1&&ch<j+1){ clrscr(); p1=(H *)t1->right; for(k=1;k<ch-1;k++){ p1=p1->next; } r=p1->next; p2=(H *)malloc(sizeof(H)); cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar(); clrscr(); cprintf("please input the custorm's name:\n"); scanf("%s",p2->name); getchar(); clrscr(); cprintf("please input the custorm's id_card_num:\n"); scanf("%s",p2->id_card_num); getchar(); clrscr(); cprintf("please input the rent_date:\n"); scanf("%s",p2->rent_date); getchar(); clrscr(); cprintf("please input the rent_days:\n"); scanf("%d",&p2->rent_days); clrscr(); cprintf("please input the firm_name:\n"); scanf("%s",p2->firm_name); getchar(); clrscr(); cprintf("please input the mount of rent"); scanf("%d",&p2->mount); getchar(); clrscr();

p2->next=r; p1->next=p2; } if(ch==1){ clrscr(); p1=(H *)t1->right; p2=(H *)malloc(sizeof(H)); cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar(); clrscr(); cprintf("please input the custorm's name:\n"); scanf("%s",p2->name); getchar(); clrscr(); cprintf("please input the custorm's id_card_num:\n"); scanf("%s",p2->id_card_num); getchar(); clrscr(); cprintf("please input the rent_date:\n"); scanf("%s",p2->rent_date); getchar(); clrscr(); cprintf("please input the rent_days:\n"); scanf("%d",&p2->rent_days); clrscr(); cprintf("please input the firm_name:\n"); scanf("%s",p2->firm_name); getchar(); clrscr(); cprintf("please input the mount of rent"); scanf("%d",&p2->mount); getchar(); clrscr(); p2->next=p1; t1->right=(L *)p2; } } if(p1==NULL){ clrscr(); p2=(H *)malloc(sizeof(H)); cprintf("please input the bus number:\n"); scanf("%s",p2->busnum); getchar();

clrscr();

cprintf("please input the custorm's name:\n"); scanf("%s",p2->name);

getchar();

clrscr();

cprintf("please input the custorm's id_card_num:\n"); scanf("%s",p2->id_card_num);

getchar();

clrscr();

cprintf("please input the rent_date:\n");

scanf("%s",p2->rent_date);

getchar();

clrscr();

cprintf("please input the rent_days:\n");

scanf("%d",&p2->rent_days);

clrscr();

cprintf("please input the firm_name:\n");

scanf("%s",p2->firm_name);

getchar();

clrscr();

cprintf("please input the mount of rent");

scanf("%d",&p2->mount);

getchar();

clrscr();

p2->next=NULL;

t1->right=(L *)p2;

}

}

void Delete_firm(T *head)

{

int i=1,j=0,k;

int ch;

T *p=head,*p1=NULL,*p2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name);

gotoxy(20,i+1);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

cprintf("No firm message exist!");

getch();

clrscr();

}

else{

do{

cprintf("please choose who to delete(1--%d):",j); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j);

}

if(ch==1){

hp=hp->next;

}

clrscr();

p=head;

if(ch==j){

for(k=0;k<j-2;k++){

p=p->next;

}

p->next=NULL;

}

p=head;

if(ch>1&&ch<j){

for(k=0;k<ch-2;k++){

p=p->next;

}

p1=p;

p2=p->next;

p2=p2->next;

p1->next=p2;

}

}

void Delete_bus(T *head)

{

int i=1,j=0,k;

int ch;

T *p=head;

L *p1=NULL,*p2=NULL,*r=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name);

gotoxy(20,i+1);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

cprintf("No bus message exist!");

getch();

clrscr();

return;

}

else{

do{

cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j);

}

clrscr();

p=head;

for(k=0;k<ch-1;k++){

p=p->next;

}

p1=(L *)p->down;

i=1;

j=0;

gotoxy(20,1);

while(p1!=NULL){

cprintf("(%d)bus number:%s;",i,p1->busnum); gotoxy(20,i+1);

p1=p1->next;

i++;

j++;

} } p1=(L *)p->down; if(p1!=NULL){ do{ cprintf("please choose who to delete second(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); if(ch==j){ clrscr(); p1=(L *)p->down; for(k=0;k<j-2;k++){ p1=p1->next; } p1->next=NULL; } if(ch==1){ clrscr(); p1=(L *)p->down; p1=p1->next; p->down=(T *)p1; } p1=(L *)p->down; if(ch>1&&ch<j){ clrscr(); for(k=0;k<ch-2;k++){ p1=p1->next; } p2=p1; r=p1->next; r=r->next; p2->next=r; } } if((p->down)==NULL){ clrscr(); gotoxy(1,1); cprintf("No bus message exit now!"); getch(); clrscr(); }

void Delete_busrent(T *head)

{

int i=1,j=0,k;

int ch;

T *p=head;

L *t1=NULL;

H *p1=NULL,*p2=NULL,*r=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name);

gotoxy(20,i+1);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

cprintf("No busrent message exist!");

getch();

clrscr();

return;

}

else{

do{

cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j);

}

clrscr();

p=head;

for(k=0;k<ch-1;k++){

p=p->next;

}

t1=(L *)p->down;

i=1;

j=0;

gotoxy(20,1);

while(t1!=NULL){

cprintf("(%d)bus number:%s;",i,t1->busnum); gotoxy(20,i+1); t1=t1->next; i++; j++; } t1=(L *)p->down; if(t1==NULL){ cprintf("No bus message exist!"); getch(); clrscr(); } else{ do{ cprintf("please choose bus second(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); } t1=(L *)p->down; for(k=0;k<ch-1;k++){ t1=t1->next; } clrscr(); p1=(H *)t1->right; i=1; j=0; gotoxy(20,1); while(p1!=NULL){ cprintf("(%d)custorm's name:%s;",i,p1->name); gotoxy(20,i+1); p1=p1->next; i++; j++; } p1=(H *)t1->right; if(p1!=NULL){ do{ cprintf("please choose custorm's name to delete third(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j);

if(ch==j){

clrscr();

for(k=0;k<j-2;k++){

p1=p1->next;

}

p1->next=NULL;

}

if(ch==1){

clrscr();

p1=(H *)t1->right;

p1=p1->next;

t1->right=(L *)p1;

}

p1=(H *)t1->right;

if(ch>1&&ch<j){

clrscr();

for(k=0;k<ch-2;k++){

p1=p1->next;

}

p2=p1;

r=p1->next;

r=r->next;

p2->next=r;

}

}

if((t1->right)==NULL){

clrscr();

gotoxy(1,1);

cprintf("No busrent message exit now!"); getch();

clrscr();

}

}

void Search_firm(T *head)

{

int i=1;

char Name[20];

T *p=head;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(1,1);

cprintf("Input the firm name you want to search:");

scanf("%s",Name);

while(p!=NULL){

if(!strcmp(p->name,Name)){

clrscr();

gotoxy(1,i);

i++;

cprintf("firm name:%s\n",p->name);

gotoxy(1,i);

i++;

cprintf("bus type 1:qiche 2:jiaoche 3:huoche\n"); gotoxy(1,i);

i++;

cprintf("bus type1:%d bus

type3:%d\n",p->mount1,p->mount2,p->mount3);

gotoxy(1,i);

i++;

break;

}

p=p->next;

}

if(p==NULL){

clrscr();

cprintf("No this firm exist!");

}

getch();

clrscr();

}

void Search_bus(T *head)

{

int i=1,j=0,k;

int ch;

char num[10];

T *p=head;

L *p1=NULL;

H *p2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name); type2:%d bus

gotoxy(20,i+1);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

gotoxy(10,1);

cprintf("No bus message exsit!");

getch();

clrscr();

return;

}

else{

do{

cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j);

}

clrscr();

p=head;

for(k=0;k<ch-1;k++){

p=p->next;

}

p1=(L *)p->down;

i=1;

cprintf("Input the bus num you want to search:");

scanf("%s",num);

while(p1!=NULL){

if(!strcmp(p1->busnum,num)){

clrscr();

gotoxy(6,1);

i++;

cprintf("firm name:%s",p->name);

gotoxy(6,i);

i++;

cprintf("bus type 1:qiche 2:jiaoche 3:huoche\n"); gotoxy(6,i);

i++;

cprintf("bus number:%s",p1->busnum);

gotoxy(6,i);

i++;

cprintf("bus type:%s",p1->type);

gotoxy(6,i);

i++;

cprintf("the rent of one day:%d yuan",p1->rent); gotoxy(6,i);

i++;

cprintf("the contactor name:%s",p1->contactor); gotoxy(6,i);

i++;

cprintf("the telephone:%s",p1->tel);

gotoxy(6,i);

i++;

p2=(H *)p1->right;

if(p2==NULL){

cprintf("Now you can rent it!");

}

else{

while((p2->next)!=NULL){

p2=p2->next;

}

cprintf("the last rent date:%s",p2->rent_date); gotoxy(6,i);

i++;

cprintf("the last rent days:%d",p2->rent_days); }

break;

}

p1=p1->next;

}

if(p1==NULL){

clrscr();

cprintf("This firm does't have this bus !");

}

getch();

clrscr();

}

void Search_busrent(T *head)

{

int i=1,j=0,k=0;

int ch;

char time[9];

T *p=head;

L *t1=NULL;

H *t2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){

cprintf("(%d)firm name:%s;",i,p->name);

gotoxy(20,i+1);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

gotoxy(6,1);

cprintf("No busrent message to search!"); getch();

clrscr();

return;

}

else{

do{

cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j);

}

clrscr();

cprintf("Input the data you want to search:"); scanf("%s",time);

p=head;

for(k=0;k<ch-1;k++){

p=p->next;

}

t1=(L *)p->down;

i=2;

k=0;

j=0;

while(t1!=NULL){

t2=(H *)t1->right;

while(t2!=NULL){

if(!strcmp(t2->rent_date,time)){

gotoxy(1,i); i++; cprintf("firm name:%s\n",t2->firm_name); gotoxy(1,i); i++; cprintf("bus type:%s\n",t1->type); gotoxy(1,i); i++; cprintf("bus number:%s\n",t2->busnum); gotoxy(1,i); i++; cprintf("customer'name:%s\n",t2->name); gotoxy(1,i); i++; cprintf("customer's id card number:%s\n",t2->id_card_num); gotoxy(1,i); i++; cprintf("the rent date:%s\n",t2->rent_date); gotoxy(1,i); i++; cprintf("rent days:%d days\n",t2->rent_days); gotoxy(1,i); i++; cprintf("the rent mount:%d\n",t2->mount); gotoxy(1,i); i++; getch(); j++; if(j==2){ clrscr(); i=2; j=0; } k++; } t2=t2->next; } t1=t1->next; } if(k==0){ clrscr(); cprintf("%s firm has no bus rent record on this day !",p->name); getch(); }

clrscr();

}

void Modify_firm(T *head)

{

int i=1,j=0,k;

char ch;

T *p=head;

L *t1=NULL;

H *t2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

i++;

while(p!=NULL){

cprintf("(%d)firm name:%s;",i-1,p->name); gotoxy(20,i);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

gotoxy(10,1);

cprintf("No firm message to modify!");

getch();

clrscr();

return;

}

else{

do{

cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch);

gotoxy(20,i+1);

i++;

}while(ch<1||ch>j);

}

clrscr();

gotoxy(20,1);

i=2;

p=head;

for(k=0;k<ch-1;k++){

p=p->next;

}

cprintf("(1) firm name:%s\n",p->name);

gotoxy(20,i);

i++;

cprintf("(2) bus type1:%d ",p->mount1);

gotoxy(20,i);

i++;

cprintf("(3) bus type2:%d ",p->mount2);

gotoxy(20,i);

i++;

cprintf("(4) bus type3:%d ",p->mount3);

gotoxy(20,i);

i++;

do{

cprintf("Input the option to modify(1-4):");

scanf("%d",&ch);

gotoxy(20,i);

i++;

}while(ch<1||ch>4);

switch(ch){

case 1:for(i=0;i<30&&*(p->name+i)!=NULL;i++){

*(p->name+i)='\0';

}

cprintf("please input the new firm name:\n"); scanf("%s",p->name);

getchar();

clrscr();

t1=(L *)p->down;

while(t1!=NULL){

for(i=0;i<30&&*(t1->firm+i)!=NULL;i++){ *(t1->firm+i)='\0';

}

strcpy(t1->firm,p->name);

t2=(H *)t1->right;

while(t2!=NULL){

for(i=0;i<30&&*(t2->firm_name+i)!=NULL;i++){ *(t2->firm_name+i)='\0';

}

strcpy(t2->firm_name,p->name); t2=t2->next;

}

t1=t1->next;

}

break;

case 2:cprintf("please input the new mount of bus type1:\n"); scanf("%d",&p->mount1);

getchar();

clrscr();

break;

case 3:cprintf("please input the new mount of bus type2:\n"); scanf("%d",&p->mount2);

getchar();

clrscr();

break;

case 4:cprintf("please input the new mount of bus type3:\n"); scanf("%d",&p->mount3);

getchar();

clrscr();

break;

}

}

void Modify_bus(T *head)

{

int i=1,j=0,k;

char ch;

T *p=head;

L *t1;

H *t2;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

i++;

while(p!=NULL){

cprintf("(%d)firm name:%s;",i-1,p->name);

gotoxy(20,i);

p=p->next;

i++;

j++;

}

p=head;

if(p==NULL){

gotoxy(10,1);

cprintf("No bus message to modify!"); getch(); clrscr(); return; } else{ do{ cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); } clrscr(); gotoxy(20,1); i=1; p=head; for(k=0;k<ch-1;k++){ p=p->next; } t1=(L *)p->down; while(t1!=NULL){ cprintf("(%d)bus number:%s;",i,t1->busnum); gotoxy(20,i+1); t1=t1->next; i++; j++; } t1=(L *)p->down; if(t1==NULL){ gotoxy(6,1); cprintf("No bus message to modify!"); getch(); clrscr(); return; } else{ do{ cprintf("please choose bus second(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); }

for(k=0;k<ch-1;k++){

t1=t1->next;

}

clrscr();

i=2;

gotoxy(10,1);

cprintf("(1) bus number:%s",t1->busnum);

gotoxy(10,i);

i++;

cprintf("(2) bus type:%s",t1->type);

gotoxy(10,i);

i++;

cprintf("(3) the rent of one day:%d yuan",t1->rent); gotoxy(10,i);

i++;

cprintf("(4) the contactor name:%s",t1->contactor); gotoxy(10,i);

i++;

cprintf("(5) the telephone:%s",t1->tel);

gotoxy(10,i);

i++;

do{

cprintf("Input the option to modify(1-5):");

scanf("%d",&ch);

gotoxy(10,i);

i++;

}while(ch<1||ch>5);

switch(ch){

case 1:for(i=0;i<5&&*(t1->busnum+i)!=NULL;i++){ *(t1->busnum+i)='\0';

}

cprintf("please input the new bus number:\n"); scanf("%s",t1->busnum);

getchar();

clrscr();

t2=(H *)t1->right;

while(t2!=NULL){

for(i=0;i<5&&*(t2->busnum+i)!=NULL;i++){ *(t2->busnum+i)='\0';

}

strcpy(t2->busnum,t1->busnum);

t2=t2->next;

}

break;

case 2:for(i=0;i<2&&*(t1->type+i)!=NULL;i++){

*(t1->type+i)='\0';

}

cprintf("please input the new bus type:\n"); scanf("%s",t1->type);

getchar();

clrscr();

break;

case 3:cprintf("please input the rent of one day:\n"); scanf("%d",&t1->rent);

getchar();

clrscr();

break;

case 4:for(i=0;i<20&&*(t1->contactor+i)!=NULL;i++){ *(t1->contactor+i)='\0';

}

cprintf("please input the new contactor's name:\n"); scanf("%s",&t1->contactor);

getchar();

clrscr();

break;

case 5:for(i=0;i<20&&*(t1->tel+i)!=NULL;i++){

*(t1->tel+i)='\0';

}

cprintf("please input the new telephone:\n"); scanf("%s",&t1->tel);

getchar();

clrscr();

break;

}

}

void Modify_busrent(T *head)

{

int i=1,j=0,k;

int ch;

T *p=head;

L *t1=NULL;

H *t2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

while(p!=NULL){ cprintf("(%d)firm name:%s;",i,p->name); gotoxy(20,i+1); p=p->next; i++; j++; } p=head; if(p==NULL){ gotoxy(6,1); cprintf("No busrent message to modify!"); getch(); clrscr(); return; } else{ do{ cprintf("please choose firm first(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); } clrscr(); p=head; for(k=0;k<ch-1;k++){ p=p->next; } t1=(L *)p->down; i=1; j=0; gotoxy(20,1); while(t1!=NULL){ cprintf("(%d)bus number:%s;",i,t1->busnum); gotoxy(20,i+1); t1=t1->next; i++; j++; } t1=(L *)p->down; if(t1==NULL){ gotoxy(6,1); cprintf("No busrent message to modify!"); getch();

clrscr(); return; } else{ do{ cprintf("please choose bus second(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); } for(k=0;k<ch-1;k++){ t1=t1->next; } clrscr(); t2=(H *)t1->right; i=1; j=0; gotoxy(20,1); while(t2!=NULL){ cprintf("(%d)custorm's name:%s;",i,t2->name); gotoxy(20,i+1); t2=t2->next; i++; j++; } t2=(H *)t1->right; if(t2==NULL){ gotoxy(6,1); cprintf("NO busrent message to modify!"); getch(); clrscr(); return; } else{ do{ cprintf("please choose custorm's name third(1--%d):",j); scanf("%d",&ch); gotoxy(20,i+1); i++; }while(ch<1||ch>j); } for(k=0;k<ch-1;k++){ t2=t2->next;

}

clrscr();

i=2;

gotoxy(10,1);

cprintf("(1) customer'name:%s\n",t2->name);

gotoxy(10,i);

i++;

cprintf("(2) customer's id card number:%s\n",t2->id_card_num);

gotoxy(10,i);

i++;

cprintf("(3) the rent date:%s\n",t2->rent_date);

gotoxy(10,i);

i++;

cprintf("(4) rent days:%d days\n",t2->rent_days);

gotoxy(10,i);

i++;

cprintf("(5) the rent mount:%d\n",t2->mount);

gotoxy(10,i);

i++;

do{

cprintf("Input the option to modify(1-5):");

scanf("%d",&ch);

gotoxy(10,i);

i++;

}while(ch<1||ch>5);

switch(ch){

case 1:for(i=0;i<20&&*(t2->name+i)!=NULL;i++){

*(t2->name+i)='\0';

}

cprintf("please input the new customer's name:\n"); scanf("%s",t2->name);

getchar();

clrscr();

break;

case 2:for(i=0;i<20&&*(t2->id_card_num+i)!=NULL;i++){

*(t2->id_card_num+i)='\0';

}

cprintf("please input the new customer's id_card number:\n"); scanf("%s",t2->id_card_num);

getchar();

clrscr();

break;

case 3:for(i=0;i<12&&*(t2->rent_date+i)!=NULL;i++){

*(t2->rent_date+i)='\0';

}

cprintf("please input the new rent date:\n"); scanf("%s",t2->rent_date);

getchar();

clrscr();

break;

case 4:cprintf("please input the new rent days:\n"); scanf("%d",&t2->rent_days);

getchar();

clrscr();

break;

case 5:cprintf("please input the new rent mount:\n"); scanf("%d",&t2->mount);

getchar();

clrscr();

break;

}

}

void tongji1(T *head)

{

int i,j=0,k=0,m,n,c;

long int money[10]={0,0,0,0,0,0,0,0,0,0};

char name[30];

T *p=head,*p1=NULL,*p2=NULL,*r=NULL;

L *t1;

H *t2;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

while(p!=NULL){

j++;

p=p->next;

}

p=head;

while(p!=NULL){

t1=(L *)p->down;

while(t1!=NULL){

t2=(H *)t1->right;

while(t2!=NULL){

money[k]+=(t1->rent)*(t2->rent_days); t2=t2->next;

}

t1=t1->next;

}

k++;

p=p->next;

}

for(i=0,n=0,p1=head;i<j-1;i++,p1=p1->next,n++){

for(k=i+1,c=1,p2=p1->next;k<j;k++,c++,p2=p2->next){

if(money[n]<money[n+c]){

m=money[n];money[n]=money[n+c];money[n+c]=m;

strcpy(name[30],p1->name);

strcpy(p1->name,p2->name);

strcpy(p2->name,name[30]);

m=p1->mount1;p1->mount1=p2->mount1;p2->mount1=m;

m=p1->mount2;p1->mount2=p2->mount2;p2->mount2=m;

m=p1->mount3;p1->mount3=p2->mount3;p2->mount3=m;

r=p1->down;p1->down=p2->down;p2->down=r;

}

}

}

p=head;

k=1;

i=1;

while(p!=NULL){

gotoxy(6,i);

cprintf("(%d) firm name:%s",k,p->name);

i++;

gotoxy(10,i);

cprintf("the total bus is:%d",(p->mount1)+(p->mount2)+(p->mount3)); i++;

gotoxy(10,i);

cprintf("the total rent money is:%d",money[k-1]);

i++;

k++;

getch();

if((k-1)==6){

clrscr();

i=1;

}

p=p->next;

}

clrscr();

}

void tongji2(T *head)

{

int i,j=0;

long int money=0;

char year[5],s[5];

T *p=head;

L *t1=NULL;

H *t2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(20,1);

cprintf("Input the year you want to census:"); scanf("%s",year);

year[4]='\0';

p=head;

while(p!=NULL){

t1=(L *)p->down;

while(t1!=NULL){

t2=(H *)t1->right;

while(t2!=NULL){

for(i=0;i<4;i++){

s[i]=*(t2->rent_date+i);

}

s[4]='\0';

if(!strcmp(year,s)){

money+=(t1->rent)*(t2->rent_days); j++;

}

t2=t2->next;

}

t1=t1->next;

}

p=p->next;

}

clrscr();

gotoxy(20,1);

cprintf("In %s the total rent money is:%d",year,money); gotoxy(20,2);

cprintf("In %s the total rent times is:%d",year,j); getch();

clrscr();

}

void tongji5(T *head)

{

int i,j=0;

long int money=0;

T *p=head;

L *t1=NULL;

H *t2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

p=head;

while(p!=NULL){

t1=(L *)p->down;

while(t1!=NULL){

t2=(H *)t1->right;

while(t2!=NULL){

money+=(t1->rent)*(t2->rent_days); j++;

t2=t2->next;

}

t1=t1->next;

}

p=p->next;

}

clrscr();

gotoxy(20,1);

cprintf(" the history total rent money is:%d",money); gotoxy(20,2);

cprintf(" the history total rent times is:%d",j); getch();

clrscr();

}

void tongji3(T *head)

{

int i=0,j=0,k=0,n;

char ch;

long int s[3]={0,0,0},m;

typedef struct tongji

{

char type;

int times;

long int money;

struct tongji *next;

}E;

E *r=NULL,*r1=NULL,*r2=NULL;

T *p=head;

L *t1=NULL;

H *t2=NULL;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

p=head;

while(p!=NULL){

t1=(L *)p->down;

while(t1!=NULL){

t2=(H *)t1->right;

while(t2!=NULL){

if(!strcmp(t1->type,"1")){ i++;

s[0]+=(t1->rent)*(t2->rent_days); }

if(!strcmp(t1->type,"2")){

j++;

s[1]+=(t1->rent)*(t2->rent_days); }

if(!strcmp(t1->type,"3")){

k++;

s[2]+=(t1->rent)*(t2->rent_days); }

t2=t2->next;

}

t1=t1->next;

}

r=(E *)malloc(sizeof(E));

r->type='1';r->times=i;r->money=s[0]; r->next=(E *)malloc(sizeof(E));

r1=r->next;

r1->type='2';r1->times=j;r1->money=s[1]; r1->next=(E *)malloc(sizeof(E));

r2=r1->next;

r2->type='3';r2->times=k;r2->money=s[2]; r2->next=NULL;

for(i=0,r1=r;i<2;i++,r1=r1->next){

for(j=i+1,r2=r1->next;j<3;j++,r2=r2->next){ if(r1->money<r2->money){

m=r1->money;r1->money=r2->money;r2->money=m; k=r1->times;r1->times=r2->times;r2->times=k; ch=r1->type;r1->type=r2->type;r2->type=ch; }

}

}

i=2;

gotoxy(1,1);

cprintf("firm name:%s",p->name);

gotoxy(1,i);

i++;

while(r!=NULL){

cprintf("bus type:%c

money:%d",r->type,r->times,r->money);

gotoxy(1,i);

i++;

r=r->next;

}

p=p->next;

i=0;j=0;k=0;

s[0]=0;s[1]=0;s[2]=0;

getch();

clrscr();

}

}

void tongji4(T *head)

{

int i,j,k=0,c,n,h;

float v[10],m;

char name[30];

T *p=head,*p1=NULL,*p2=NULL,*r=NULL;

L *t1;

H *t2;

window(1,2,80,25);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

p=head;

while(p!=NULL){

i=0;

j=0;

t1=(L *)p->down;

while(t1!=NULL){ rent times:%d rent

t2=(H *)t1->right; if(t2!=NULL){ i++; } j++; t1=t1->next; } v[k]=(i*1.0)/j; k++; p=p->next; } v[k]='\0'; for(i=0,n=0,p1=head;i<k-1;i++,p1=p1->next,n++){ for(j=i+1,c=1,p2=p1->next;j<k;j++,c++,p2=p2->next){ if(v[n]<v[n+c]){ m=v[n];v[n]=v[n+c];v[n+c]=m; strcpy(name[30],p1->name); strcpy(p1->name,p2->name); strcpy(p2->name,name[30]); h=p1->mount1;p1->mount1=p2->mount1;p2->mount1=h; h=p1->mount2;p1->mount2=p2->mount2;p2->mount2=h; h=p1->mount3;p1->mount3=p2->mount3;p2->mount3=h; r=p1->down;p1->down=p2->down;p2->down=r; } } } p=head; k=1; j=0; n=0; i=1; while(p!=NULL){ gotoxy(6,i); cprintf("(%d) firm name:%s",k,p->name); i++; gotoxy(10,i); cprintf("occupancy rate:%0.4f",v[n]); i++; gotoxy(10,i); cprintf("the total bus is:%d",((p->mount1)+(p->mount2)+(p->mount3))); i++; gotoxy(10,i); t1=(L *)p->down; while(t1!=NULL){

} t2=(H *)t1->right; while(t2!=NULL){ j++; t2=t2->next; } t1=t1->next; } cprintf("the total rent times is:%d",j); j=0; i++; k++; n++; getch(); if(n==5) break; p=p->next; } clrscr();

相关推荐