车友信息管理系统程序设计.docx

上传人:b****2 文档编号:3284188 上传时间:2023-05-05 格式:DOCX 页数:25 大小:20.36KB
下载 相关 举报
车友信息管理系统程序设计.docx_第1页
第1页 / 共25页
车友信息管理系统程序设计.docx_第2页
第2页 / 共25页
车友信息管理系统程序设计.docx_第3页
第3页 / 共25页
车友信息管理系统程序设计.docx_第4页
第4页 / 共25页
车友信息管理系统程序设计.docx_第5页
第5页 / 共25页
车友信息管理系统程序设计.docx_第6页
第6页 / 共25页
车友信息管理系统程序设计.docx_第7页
第7页 / 共25页
车友信息管理系统程序设计.docx_第8页
第8页 / 共25页
车友信息管理系统程序设计.docx_第9页
第9页 / 共25页
车友信息管理系统程序设计.docx_第10页
第10页 / 共25页
车友信息管理系统程序设计.docx_第11页
第11页 / 共25页
车友信息管理系统程序设计.docx_第12页
第12页 / 共25页
车友信息管理系统程序设计.docx_第13页
第13页 / 共25页
车友信息管理系统程序设计.docx_第14页
第14页 / 共25页
车友信息管理系统程序设计.docx_第15页
第15页 / 共25页
车友信息管理系统程序设计.docx_第16页
第16页 / 共25页
车友信息管理系统程序设计.docx_第17页
第17页 / 共25页
车友信息管理系统程序设计.docx_第18页
第18页 / 共25页
车友信息管理系统程序设计.docx_第19页
第19页 / 共25页
车友信息管理系统程序设计.docx_第20页
第20页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

车友信息管理系统程序设计.docx

《车友信息管理系统程序设计.docx》由会员分享,可在线阅读,更多相关《车友信息管理系统程序设计.docx(25页珍藏版)》请在冰点文库上搜索。

车友信息管理系统程序设计.docx

车友信息管理系统程序设计

5、

#include

#include

#include"file.h"

#include"string.h"

#include"ctype.h"

#include"windows.h"

#include"conio.h"

#include"malloc.h"

voidmenu()//一级菜单函数

{

printf("************1.显示车友信息*******************\n");

printf("************2.车友信息管理*******************\n");

printf("************3.车友人数统计*******************\n");

printf("************4.根据条件查询*******************\n");

printf("************0.退出*******************\n");

printf("\n");

}

voidmenuBase()//车友信息管理的二级菜单

{

printf("************1.增加车友信息*******************\n");

printf("************2.删除车友信息*******************\n");

printf("************3.修改车友信息*******************\n");

printf("************0.返回上级菜单*******************\n");

printf("\n");

}

voidmenuCount()//车友人数统计的二级菜单

{

printf("************1.车友总人数*******************\n");

printf("************2.车辆品牌的车友人数*******************\n");

printf("************0.返回上级菜单*******************\n");

printf("\n");

}

voidmenuSearch()//根据条件查询的二级菜单

{

printf("************1.根据车款查询车友信息*******************\n");

printf("************2.根据性别查询车友信息*******************\n");

printf("************0.返回上级菜单*******************\n");

printf("\n");

}

structnode*baseManage(structnode*head)//车友信息管理模块的实现

{

intchoice;

Typedata;

longs1;

chars2[20];

do//用do~while语句可以多次选择二级菜单

{

menuBase();//调用二级菜单显示函数

printf("choiceoneoperationyouwanttodo:

\n");

scanf("%d",&choice);//输入选择项

switch(choice)

{

case1:

readNode(&data);//首先读入待插入的车友信息,再插入

head=InsertOrder(head,data,1);

break;

case2:

printf("InputtheVIPnumberdeleted\n");//读入会员名,根据会员名进行删除(会员名就是一个号,相当于学号)

scanf("%d",&data.VIPnum);

head=Delete(head,data);

break;

case3:

printf("P;easeinputthrVIPnumberandhisnametobexiugai.\n");

printf("VIPnum:

");

scanf("%ld",&s1);

printf("name:

");

scanf("%s",&s2);

Revise(head,s2,s1);

break;

case0:

break;

}

}while(choice);//还是回到二级菜单允许再次选择二级功能

returnhead;

}

intCount(structnode*head)//求总人数

{

structnode*p;

intcount=0;//count统计总人数

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

{

count++;

}

returncount;

}

intbrandCount(structnode*head,char*s)

{

intcount=0;

structnode*p;

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

{

if((strcmp(p->data.brand,s)==0))

count++;

}

returncount;

}

structnode*countManage(structnode*head)//车友人数统计模块的实现

{

intchoice,all,brandcount;

chars[20];

do

{

menuCount();

printf("choiceoneoperationyouwanttodo:

\n");

scanf("%d",&choice);

switch(choice)

{

case1:

printf("thenumberofthepeopleis:

\n");

all=Count(head);

printf("all=%d",all);

printf("\n");

break;

case2:

printf("Pleaseinputthebrandwillbesearched:

\n");

scanf("%s",s);

brandcount=brandCount(head,s);

printf("brandcount=%d",brandcount);

printf("\n");

printf("\n");

break;

case0:

saveFile(head);

break;

}

}while(choice);

returnhead;

}

structnode*searchManage(structnode*head)//根据条件查询模块的实现

{

intchoice;

Typedata;

do//用do~while语句可以多次选择二级菜单

{

menuSearch();

printf("choiceoneoperationyouwanttodo:

\n");

scanf("%d",&choice);//输入选择项

switch(choice)

{

case1:

printf("InputaVIP\'scar\'sbrandwillbesearched:

\n");

scanf("%s",&data.brand);//输入车款,将根据车款查询

SearchNode(head,data,choice);

printf("\n");

break;

case2:

printf("InputaVIP\'ssexwillbesearched:

\n");

scanf("%s",&data.sex);//输入性别,将根据性别查询

SearchNode(head,data,choice);

printf("\n");

break;

case0:

break;

}

}while(choice);//返回二级菜单允许再次选择二级功能

returnhead;//返回头指针

}

structnode*runMain(structnode*head,intchoice)//该函数受main调用,根据选择项分别调用

{//函数实现各模块的功能

switch(choice)

{

case1:

printHead();//选择1.先输出表头

head=printList(head);//调用函数完成显示车友信息的功能

break;

case2:

head=baseManage(head);//选择2.调用函数完成车友信息管理功能

break;

case3:

head=countManage(head);//选择3,调用函数完成车友人数统计的功能

break;

case4:

head=searchManage(head);//选择4,调用函数完成根据条件查询的功能

break;

case0:

break;

}

returnhead;//返回头指针

}

intmain()

{

chard[6];

charm[6];

m[0]='8',m[1]='8',m[2]='0',m[3]='5',m[4]='0',m[5]='5';//数组比较

printf("请输入六位数密码:

");//输入密码

for(intn=0;;)

{

for(inti=0;i<6;i++)

{

d[i]=getch();

if(d[i]>='0'||d[i]<='9'||d[i]>='a'||d[i]<='z'||d[i]>='A'||d[i]<='Z')

putchar('*');

}

if(d[0]==m[0]&&d[1]==m[1]&&d[2]==m[2]&&d[3]==m[3]&&d[4]==m[4]&&d[5]==m[5])

{

printf("\n欢迎使用!

\n");

printf("\n按任意键继续\n");

break;

}

if(d[0]!

=m[0]||d[1]!

=m[1]||d[2]!

=m[2]||d[3]!

=m[3]||d[4]!

=m[4]||d[5]!

=m[5])//当密码错误时如下

printf("\n密码错误!

请重新输入:

");

if(n>3)

{

printf("error\n");

exit(0);

}

n++;

}

structnode*head=NULL;

intchoice;

head=readFile(head);

if(!

head)

{

createFile();

head=readFile(head);

}

do

{

menu();

printf("Pleaseinputyourchoice:

");

scanf("%d",&choice);

if(choice>=0&&choice<=4)

head=runMain(head,choice);

else

printf("erroeinput,pleaseinputyourchoiceagain!

\n");

}while(choice);

saveFile(head);

return0;

}

4、file,h

#include

#include

#include"list.h"

voidcreateFile()//建立初始的数据文件

{

Typedata;

intn,i;

FILE*fp;

if((fp=fopen("E:

\\文件.txt","w"))==NULL)//指定好文件名,以写入方式打开

{

printf("cannotopenfilecashbox.txt!

\n");//若打开失败,输出提示信息,退出

exit(0);

}

printf("howmanyrecordsdoyouwanttoadd?

\n");

scanf("%d",&n);

printf("inputCarfriends\'information\n");

for(i=1;i<=n;i++)

{

readNode(&data);

fwrite(&data,sizeCfr,1,fp);//将刚才读入的一条记录写入文件

printf("\n");

}

fclose(fp);//关闭文件

}

structnode*readFile(structnode*head)//将文件中的内容读出置于单链表中

{

Typedata;

FILE*fp;

head=NULL;

if((fp=fopen("E:

\\文件.txt","r"))==NULL)//以读的方式打开指定文件

{

printf("cannotopenfile!

\n");//如果打开失败输出提示信息,退出

exit(0);

}

fread(&data,sizeCfr,1,fp);//读出第一条记录

while(!

feof(fp))//文件结束时循环

{

head=InsertOrder(head,data,1);//从文件中读出后按年龄顺序插入链表

fread(&data,sizeCfr,1,fp);//再读出下一条记录

printf("\n");

}

fclose(fp);//关闭文件

returnhead;//返回单链表的头指针

}

voidsaveFile(structnode*head)//将链表中各结点的值依次写入文件

{

structnode*p=head;

FILE*fp;

if((fp=fopen("E:

\\文件.txt","w"))==NULL)//以写的方式打开指定文件

{

printf("cannotopenfile!

\n");//如果打开失败,输出提示信息,退出

exit(0);

}

if(head==NULL)//如果头指针为空输出提示信息,退出

{

printf("\nNoRecord\n");

return;

}

while(p)//p从head开始,如果链表未结束

{

fwrite(&p->next,sizeCfr,1,fp);//则将p所指的结点数据值写入文件中

p=p->next;//p指针后移,准备处理下一个结点

}

fclose(fp);//关闭文件

}

3、list.h

#include"prepare.h"//文件包含,本文件是对结点数据域为Type类型的单链表进行的处理

structnode*CreateBackward();//后插法新建链表

structnode*CreateForward();//前插法新建链表

structnode*CreateInsert();//按序插入法新建链表

structnode*printList(structnode*head);//链表的遍历

structnode*SearchNode(structnode*head,Typedata,intcondition);//单链表的查找

structnode*InsertAfter(structnode*head,Typedata);//尾部插入

structnode*InsertOrder(structnode*head,Typedata,intcondition);//有序插入

structnode*Delete(structnode*head,Typedata);//删除结点

structnode*Recerse(structnode*head);//单链表的逆置

structnode*printList(structnode*head)//链表的遍历

{

structnode*p;

if(head==NULL)//如果链表原来为空

{

printf("\nNoRecords\n");//输出提示信息,然后返回

returnNULL;

}

for(p=head;p;p=p->next)//p从头指针开始,每循环一次向后移1结点位置

{

printNode(p->data);//p非空时执行循环体,调用printNode函数输出结点的元素值

printf("\n");

}

printf("\n");//然后换行

returnhead;//返回头指针

}

structnode*CreateBackward()//后插法新建链表

{

structnode*head,*p,*tail;//tail用来定位于当前链表中最后一个结点位置

Typedata;

head=NULL;//链表未建时对头指针和尾指针进行清零处理

tail=NULL;

printf("Inputdataendwith0:

\n");

readNode(&data);//调用readNode输入一个结点的数据域的值

while(!

endWith(data))//endWith(data)函数值为真时结束链表结点的生成

{

p=(structnode*)malloc(size);//利用指针p申请结点的动态空间

p->data=data;//数据域赋值

p->next=NULL;//新结点的指针域赋值

if(head=NULL)//初始链为空时,要修改头文件

head=p;

else//链非空时,将p置于tail所指结点之后

tail->next=p;

tail=p;//使指向新的链尾,便于下次插入

readNode(&data);//继续读入下一个结点的数据域的值

}

returnhead;//返回头指针

}

structnode*CreateForward()//前插法新建链表

{

structnode*head,*p;

Typedata;

head=NULL;//链表未建时对头指针进行清零处理

printf("Inputdataendwith0:

\n");

readNode(&data);//调用readNode输入一个结点的数据域的值

while(!

endWith(data))//endWith(data)函数值为真时结束链表结点的生成

{

p=(structnode*)malloc(size);//利用指针p申请结点的动态空间

p->data=data;//数据域赋值

p->next=head;//新结点的指针域赋值为head

head=p;//修改头指针

readNode(&data);//继续读入下一个结点的数据域的值

}

returnhead;//返回头指针

}

voidRevise(structnode*head,chars[20],longa)

{

structnode*p;

intcount=0;

if(head==NULL)//如果链表原来就为空

{

printf("\nNORecords\n");//输出提示信息

return;//返回空指针

}

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

{

if(p->data.VIPnum==a&&strcmp(p->data.name,s)==0)

{

count=1;

readNode(&p->data);

break;

}

}

if(count==0)

printf("itisnotinthelist!

\n");

return;

}

structnode*SearchNode(structnode*head,Typedata,intcondition)//单链表的查找

{

structnode*p=head;//p从head开始

intcount=0;

if(head==NULL)//如果链表原来就为空

{

printf("\nNORecords\n");//输出提示信息

return0;//返回空指针

}

while(p)

{

if(equal(p->data,data,condition)==0)

{

printHead();

printNode(p->data);

printf("\n");

count++;

}

p=p->next;

}

if(count==0)

printf("itisnotinthelist!

\n");

return0;

}

structnode*InsertAfter(structnode*head,Typedata)//尾部插入

{

structnode*p,*p1;

p=(structnode*)malloc(size);//利用指针p申请动态空间

p->data=data;//数据域赋值

p->next=NULL;//指针域直接赋值为空,因为它是新链最后的结点

if(head==NULL)//如果链表原来为空

{

head=p;//修改头指针

returnhead;//返回头指针

}

p1=head;//链表原来非空,则指针p1从头指针开始

while(p1->next)//如果指针还没有指向链表的最后一个结点处

{

p1=p1->next;//p1顺着链向后移动

}//循环停止时,p1指向了链表的最后一个结点处

p1->next=p;//将新结点连在p1之后

returnhead;//返回头指针

}

structnode*InsertOrder(structnode*head,Typedata,intcondition)//有序插入法

{

structnode*p,*p1,*p2;

p2=head;

p=(structnode*)malloc(size);//利用指针p申请动态空间

p->data=data;//数据域赋值

p->next=NULL;//指针域直接赋值为空,以后根据插入位置再修改

if(head==NULL)//原链表为空时的插入

{

head=p;//新插入结点成为头结点

returnhead;

}

//原链表不为空时的插入,larger是一个通用函数

while(p2&&larger(p->data,p2->data,condition))//第一参数大于第二参数,返回真

{

p1=p2;//p1是p2的前趋结点,二者同时后移

p2=p2->next;

}

if(head==p2)//如果要在最前面插入,则要修改head指针

head=p;

else//否则p插在p1的后面

p1->next=p;

p->next=p2;//p2作为p的后继结点,即p插在p1和p2之间

returnhead;//返回头指针

}

structnode*CreateInsert()//按序插入法新建链表

{

structnode*head

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2