广东工业大学c语言课程设计技术报告1389

上传人:r****d 文档编号:89258654 上传时间:2022-05-12 格式:DOC 页数:41 大小:329.50KB
收藏 版权申诉 举报 下载
广东工业大学c语言课程设计技术报告1389_第1页
第1页 / 共41页
广东工业大学c语言课程设计技术报告1389_第2页
第2页 / 共41页
广东工业大学c语言课程设计技术报告1389_第3页
第3页 / 共41页
资源描述:

《广东工业大学c语言课程设计技术报告1389》由会员分享,可在线阅读,更多相关《广东工业大学c语言课程设计技术报告1389(41页珍藏版)》请在装配图网上搜索。

1、课 程 设 计 C语言程序设计课程设计课程名称_水电气费用管理系统题目名称_自动化学院学生学院_电子信息科学与技术专业班级_学 号_学生姓名_指导教师_2012 年 6月 6日需求分析:设计题目:水电气费用管理系统设计内容:编程建立一个水电气费用管理系统,使其能对每月的水电气进行系统管理。包含删除,增加用户,查询,缴费功能。整个系统分为二个软件:主机和客户端。主机负责计算,客户端面向用户。系统功能:主机:接收每个月的数据并处理。把每个月的数据写到文件等待客户端操作。客户端:打开时初始化用户数据。接收主机输送的数据,整合给用户。提供删除用户功能。增加用户。查询最近三个月数据和缴费情况。缴费。退出

2、时保存用户数据。具体功能程序打开时初始化原有用户数据。进入循环体选择界面。三月数据读入;总费用读入;总人数写出;删除的用户排行写出,如无删除写出-1,否则主机删除排行所对应的总费用数组元素,并立刻写出-1;标志位写出,主机接收后总费用清零。选择操作:删除用户:链表中寻找对应账号,检查缴费情况,若成功删除把删除账号写入存放删除用户账号数组,否则删除失败标记位置位增加用户:检查是否达到最大用户数量,申请内存加到链尾,检测是否有已删除账号,用户数据写入查询:缴费:返回选择界面若退出循环体,保存用户数据数据结构设计链表存放用户数据结构体数组保存用户数据存放用户三个月数据用的是三个二维数组一维数组存放总

3、费用一维数组存放删除用户账号目录:程序下载地址3客户端5主函数5增加删除函数8对主机输送数据处理函数12数据输送函数14初始化用户数据函数19保存用户数据函数21查询函数22结构体定义24主机25主函数25截图30客户端30总结31程序下载地址:流程图:选择界面选择删除用户增加用户查询缴费输入用户名成功删除是否欠费否输入姓名是是否达到最大用户数否窗口显示选择次月份最近月份次次月份缴费情况输入账号输出账号输入交易额是初始化用户数据退出程序保存用户数据源程序:客户端:主函数:#include stdafx.h#include stdlib.h#include string.h#include st

4、ruct.h /自定义头文件#include adddelete.h#include search.h#include save.h#include deal.h#include string1.h#include getnane.h#include putname.h#include filework.h#include define.hvoid main() /test or text 为测试语句,软件推出后删除/initfloat table11MAX4=0,/test 软件推出时初始化为0 , 20为最多用户数量,可改 table22MAX4=0, table33MAX4=0;floa

5、t tablepayMAX=0;/存放总费用int monthtable3=0;struct init inittableMAX=0;/test 软件推出时初始化为0char choice1;int sign=-1;int *psign=&sign;FILE *fp1=NULL;int tableaccountMAX=0,total=0,choice,time;/tableaccount存放删除的用户的账号,total为总人数int account,*paccount,rank,*prank,*ptotal;/*paccount为账号指针,*prank为删除的用户链表中对应的排行,ptotal

6、为总人数struct link *head;paccount=&account;ptotal=&total;prank=&rank;rank=-1;head=NULL;/*-分割线1-*/del(tableaccount);/*-分割线1-*/head=init(inittable,ptotal);/初始化原有用户数据system(color 1e);/while(1)printf(nt请选择:nt1 删除用户nt2 增加用户nt3 查询nt4 缴费nt5 退出nt);scanf(%d,&choice);/*-分割线2-*/File(ptotal,prank,tablepay,table11,

7、table22,table33,monthtable,total,psign);/*-分割线2-*/rank=-1;/文件操作包括最近三月数据写入,总费用写入tablepay,总人数*ptotal输出,删除的用户链表中对应的排行*prank,prank为-1时无删除readdata(head,table11,table22,table33);/读最近三月数据if(rank!=-1)for(time=rank;time20;time+)tablepaytime-1=tablepaytime;rank=-1;readpay(head,tablepay);/总费用/文件操作,标志位置位。主机里的总费

8、用数组清零system(cls);/清屏switch (choice)case 1:head=deletenode(head,prank,tableaccount,table11,table22,table33,tablepay,ptotal);break;case 2:head=insertnode(head,tableaccount,ptotal);break;case 3:search(head,monthtable);break;case 4:pay(head);break;case 5:break;default:printf(input errorn);printf(nt离开?(Y

9、/N):);scanf(%s,&choice1);if(choice1=Y | choice1=y)break;system(cls);/清屏 fp1=fopen(flag.txt,w);if(fp1=NULL)printf(打开flag.txt文件出错!);fprintf(fp1,%2d,*ptotal);fprintf(fp1,%2d,*prank);fprintf(fp1,%2d,1);fclose(fp1);for(time=0;timedata.water11=0; pr-data.elect11=0; pr-data.gas11=0; pr-data.cost11=0;pr-dat

10、a.water22=0; pr-data.elect22=0; pr-data.gas22=0; pr-data.cost22=0;pr-data.water33=0; pr-data.elect33=0; pr-data.gas33=0; pr-data.cost33=0;pr-data.pay=0;/*-增加用户函数-功能:把申请的新用户添加到链表末尾head1为原链表头指针,account为账号指针-*/struct link *insertnode(struct link *head1,int tableaccountMAX,int *ptotal)/p始终指向申请内存int a=1,

11、*account,time,*table=tableaccount;struct link *head,*p,*pr;account=&a;pr=head1;head=head1;if(*ptotaldata.name);system(cls);/清屏if(pr=NULL)/若申请的节点为首节点head=p;p-next=NULL;else/若申请的节点非首节点*account=2;while(pr-next!=NULL)pr=pr-next;*account=*account+1;pr-next=p;p-next=NULL;if(*table=0)/检验删除的用户账号数组是否为空,并赋值申请

12、的用户账号以及数据p-data.account=*account;elsewhile(*table!=0 & timedata.account=*(table-1);*(table-1)=0;*ptotal=*ptotal+1;/总人数加1initnode(p);printf(nt欢迎您,%s: 请记住您的账号: %3dn,p-data.name,p-data.account);elseprintf(用户数量已达到最大);return head;/*-删除用户函数- 删除用户,并返回删除用户在链表中的排行 *account为用户账号,*prank为用户排行-*/struct link *del

13、etenode(struct link *head,int *prank,int tableaccountMAX,float table114,float table224,float table334,float tablepayMAX,int *ptotal)int *paccount=NULL,account,time=0,*table=tableaccount;struct link *pr,*p;float *pr11,*pr22,*pr33;/二维数组列指针pr11=*table11,pr22=*table22,pr33=*table33;paccount=&account;*pr

14、ank=1;pr=head;p=head;printf(nt请输入您的账号:);scanf(%d,&account);system(cls);/清屏if(head=NULL)/若链表为空printf(t无用户n);*prank=-1;/删除失败标记位置位else if(pr-data.account=*paccount)/若删除的为第一节点if(pr-data.pay=0.0)head=pr-next;free(pr);elseprintf(nt未支付全部费用,请支付后再删除n);*prank=-1;/删除失败标记位置位elsewhile(pr-data.account!=*paccount

15、& pr-next!=NULL)/找对应账号p=pr;pr=pr-next;(*prank)+;if(pr-data.account=*paccount & pr-data.pay=0)p-next=pr-next;free(pr);elseif(pr-data.pay0.0)printf(nt未支付全部费用,请支付后再删除n);*prank=-1;/删除失败标记位置位elseprintf(nt账号错误,请确认您的账号n);/账号错误*prank=-1;/删除失败标记位置位if(*prank!=-1)printf(nt成功删除n);*ptotal=*ptotal-1;/总人数-1if(*pra

16、nk!=-1)/删除用户后用户二维数组顺序与链表排行对应for(time=*prank-1;timeMAX;time+)/20为main中的最多用户数量,与main中一致,也可由总人数代替pr11time*4=pr11(time+1)*4;pr11time*4+1=pr11(time+1)*4+1;pr11time*4+2=pr11(time+1)*4+2;pr11time*4+3=pr11(time+1)*4+3;pr22time*4=pr22(time+1)*4;pr22time*4+1=pr22(time+1)*4+1;pr22time*4+2=pr22(time+1)*4+2;pr22

17、time*4+3=pr22(time+1)*4+3;pr33time*4=pr33(time+1)*4;pr33time*4+1=pr33(time+1)*4+1;pr33time*4+2=pr33(time+1)*4+2;pr33time*4+3=pr33(time+1)*4+3;tablepaytime=tablepaytime+1;if(*prank!=-1)/把成功删除的用户账号写入删除的用户账号数组time=0;while(*table!=0 & timedata.water11=pr11time*4;/最近月份 p-data.elect11=pr11time*4+1;p-data.

18、gas11=pr11time*4+2;p-data.cost11=pr11time*4+3;p-data.water22=pr22time*4;p-data.elect22=pr22time*4+1;p-data.gas22=pr22time*4+2;p-data.cost22=pr22time*4+3;p-data.water33=pr33time*4;p-data.elect33=pr33time*4+1;p-data.gas33=pr33time*4+2;p-data.cost33=pr33time*4+3;time+;p=p-next;/*-读缴费函数-*/void readpay(s

19、truct link *head,float tablepayMAX)struct link *pr=head;int time=0;while(pr!=NULL)pr-data.pay=pr-data.pay-tablepaytime;time+;pr=pr-next;/*-读缴费函数-*/*void readpay(struct link *head,float tablepay20)ystruct link *pr=haead;int time=0;while(pr!=NULL)pr-data.pay=tablepaytime;tiem+;pr=pr-next;*/*-释放内存函数,形参

20、为链表头指针-*/void freelink(struct link *head)struct link *p=head,*pr=NULL;while(p!=NULL)pr=p;p=p-next;free(pr);数据输送函数:#define USER_NUM 20 /用户最大数量为20/*函数功能:把一个月的数据赋给二维数组 函数参数:浮点型二维数组str,用来保存一个月的数据指针变量*fp,文件file1的文件指针 函数返回值:无*/ void CreatStr(float strUSER_NUM4,FILE *fp)int i;int j;float data;float numflag

21、;for(i=0;iUSER_NUM;i+)/*从文件的后面开始移动,第一次文件指针比以后多移4个数据位*/if(i=0)fseek(fp,-30L,SEEK_CUR);fscanf(fp,%6f,&numflag);elsefseek(fp,-54L,SEEK_CUR); fscanf(fp,%6f,&numflag);/*把4个数据依次赋给二维数组中的一维*/for(j=0;j4;j+)fscanf(fp,%6f,&data);strij=data;/*如果读到标记-1,则该次赋完后退出*/if(numflag0)break;int i1;int i2;int n;int m;float

22、temp1;m=i;n=(m+1)/2;/*因从文件后面读起,现把二维数组倒置,变回正常顺序*/for(i1=0,i2=m;i1n;i1+,i2-)for(j=0;j4;j+)temp1=stri2j;stri2j=stri1j;stri1j=temp1;/*函数功能:判断现在的月份,并把最近三月的数据赋给二维数组 函数参数:字符型变量monthflag,表示上月的月份浮点型二维数组str_month1,用来保存上月数据浮点型二维数组str_month2,用来保存上第二月数据浮点型二维数组str_month3,用来保存上第三月数据指针变量*fp,文件file1的文件指针 函数返回值:无*/vo

23、id FinalStr(char monthflag,float str_month1USER_NUM4,float str_month2USER_NUM4,float str_month3USER_NUM4,FILE *fp,int monthtable3,int total)int n=0;switch(monthflag)case A:n=fseek(fp,-260L,SEEK_END);if(n!=0)fseek(fp,-1L,SEEK_END);/跳过月份标记位CreatStr(str_month1,fp);monthtable0=1;elsefseek(fp,-1L,SEEK_EN

24、D);CreatStr(str_month1,fp);monthtable0=1;fseek(fp,-31L,SEEK_CUR);/跳过月份标记位和下月的最后一个用户数据和结束标记位-1CreatStr(str_month2,fp);monthtable1=12;fseek(fp,-31L,SEEK_CUR);CreatStr(str_month3,fp);monthtable2=11;break;case B:n=fseek(fp,-520L,SEEK_END);if(n!=0)fseek(fp,-1L,SEEK_END);CreatStr(str_month1,fp);monthtable

25、0=2;fseek(fp,-31L,SEEK_CUR);CreatStr(str_month2,fp);monthtable1=1;elsefseek(fp,-1L,SEEK_END);CreatStr(str_month1,fp);monthtable0=2;fseek(fp,-31L,SEEK_CUR);CreatStr(str_month2,fp);monthtable1=1;fseek(fp,-31L,SEEK_CUR);CreatStr(str_month3,fp);monthtable2=12;break;case C:case D:case E:case F:case G:cas

26、e H:case i:case J:case K:case L:monthtable0=monthflag-64;monthtable1=monthflag-65;monthtable2=monthflag-66;fseek(fp,-1L,SEEK_END);CreatStr(str_month1,fp);fseek(fp,-31L,SEEK_CUR);CreatStr(str_month2,fp);fseek(fp,-31L,SEEK_CUR);CreatStr(str_month3,fp);break;default:;void File(int *ptotal,int *prank, f

27、loat tablepay20,float table11204,float table22204,float table33204,int monthtable3,int total,int *sign)char monthflag; FILE *fp=NULL;/定义文件指针FILE *fp1=NULL;FILE *fp2=NULL;fp=fopen(file1.txt,r); /打开主程序写出的数据文件if(fp=NULL)!);/*移动文件指针,判断上月的月份*/fseek(fp,-1L,SEEK_END);fscanf(fp,%c,&monthflag); FinalStr(mont

28、hflag,table11,table22,table33,fp,monthtable,total);/把水、电、气数据赋给二维数组fp1=fopen(flag.txt,w);if(fp1=NULL)printf(打开flag.txt文件出错!);fprintf(fp1,%2d,*ptotal);fprintf(fp1,%2d,*prank);fprintf(fp1,%2d,*sign);fp2=fopen(total.txt,r); /打开主程序写出的数据文件if(fp2=NULL)printf(打开total.txt出错!);int i;for(i=0;i20;i+)fscanf(fp2,

29、%13f,&tablepayi);fclose(fp); /关闭文件fclose(fp1); /关闭文件fclose(fp2); /关闭文件初始化用户数据函数: 函数参数:结构体变量inttable,用来保存用户名和对应账号 函数返回值:无*/#include define.hvoid name(struct init inittableMAX)FILE *fp=NULL;fp=fopen(name.txt,r);/以只读方式打开文件if(fp=NULL)printf(打开用户姓名号码文件出错!);int i;for(i=0;i20;i+)fscanf(fp,%10s,&inittablei.

30、name);fscanf(fp,%2d,&inittablei.account);fscanf(fp,%13f,&inittablei.pay);fclose(fp);void del(int tableaccountMAX)FILE *fp=NULL;fp=fopen(del.txt,r);/以只读方式打开文件if(fp=NULL)printf(打开用户姓名号码文件出错!);int i;for(i=0;iaccount!=0)p=(struct link *)malloc(sizeof(struct link);/申请内存if(p=NULL)printf(t内存不够);exit(0);els

31、e if(flag=0)/链表首节点head=p;pr=head;p-next=NULL;p-data.account=pinit-account;/赋值strcpy(p-data.name,pinit-name);p-data.pay=pinit-pay;flag=1;pinit=pinit+1;/指针指向数组下一位pr=head;while(pr-next!=NULL)/组建链表pr=pr-next;pr-next=p;p-next=NULL;*ptotal=*ptotal+1;return head;保存用户数据函数:#include define.h/*函数功能:把用户名和账号写入na

32、me.txt文件,使程序关闭时这些数据不丢失 函数参数:指针变量writehead,用来指向用户名账号结构体 函数返回值:无*/void name1 (struct init tableMAX)int i;FILE *fp=NULL; fp=fopen(name.txt,w);/以只写方式打开文件if(fp=NULL)printf(关闭程序时,打开用户姓名号码文件出错!);for(i=0;iMAX;i+)fprintf(fp,%-10s,tablei.name);fprintf(fp,%2d,tablei.account);fprintf(fp,%13.1f,tablei.pay);fprin

33、tf(fp,n);fclose(fp);void add(int tableaccountMAX)int i;FILE *fp=NULL; fp=fopen(del.txt,w);/以只写方式打开文件if(fp=NULL)printf(关闭程序时,打开用户姓名号码文件出错!);for(i=0;iaccount=pr-data.account;/写数据strcpy(p+time)-name,pr-data.name);(p+time)-pay=pr-data.pay;pr=pr-next;time+;查询函数:/*-查询函数-*/void search(struct link *head,int

34、 table3)struct link *pr=head;int *account,accountdata,choile;if(head=NULL)printf(nt无用户n);elseaccount=&accountdata;printf(nt请输入您的账号:);scanf(%d,&accountdata);system(cls);/清屏while(pr-data.account!=*account & pr-next!=NULL)/找对应账号pr=pr-next;if(pr-data.account=*account)/账号存在printf(nt欢迎您:%snt您可选择最近三个月份和缴费情

35、况,请选择:nt1 为最近月份nt2 为次月份nt3 为次次月份nt4 为缴费情况nt,pr-data.name);/选择查询月份scanf(%d,&choile);system(cls);/清屏switch (choile)case 1:printf(nt%d月nt水 电 气 总费用nt%-7.1f%-7.1f%-7.1f%-7.1f,table0,pr-data.water11,pr-data.elect11,pr-data.gas11,pr-data.cost11);break;case 2:printf(nt%d月nt水 电 气 总费用nt%-7.1f%-7.1f%-7.1f%-7.1

36、f,table1,pr-data.water22,pr-data.elect22,pr-data.gas22,pr-data.cost22);break;case 3:printf(nt%d月nt水 电 气 总费用nt%-7.1f%-7.1f%-7.1f%-7.1f,table2,pr-data.water33,pr-data.elect33,pr-data.gas33,pr-data.cost33);break;case 4:printf(nt%-7.1f,pr-data.pay);break;default :printf(nt选择错误n);elseprintf(nt账号错误n);/*-缴

37、费函数-head为链表头指针-*/void pay(struct link *head)int account;float money;struct link *pr=head;printf(nt请输入您的账号: );scanf(%d,&account);system(cls);/清屏while(pr-data.account!=account & pr-next!=NULL)/找对应账号pr=pr-next;if(pr-data.account=account)printf(nt您好:%snt请输入交易额并刷卡: ,pr-data.name);scanf(%f,&money);system(

38、cls);/清屏pr-data.pay=money+pr-data.pay;printf(nt交易成功!n);elseprintf(nt账号错误,请核对n);结构体定义:struct nemberint account;char name10;float water11;float elect11;float gas11;float cost11;float water22;float elect22;float gas22;float cost22;float water33;float elect33;float gas33;float cost33;float pay;typedef s

39、truct nember nember;struct linknember data;struct link *next;struct initint account;char name10;float pay;主机:主函数:/ 123uy.cpp : Defines the entry point for the console application./#include stdafx.h#include #include #include void main()int n=0;int i;int ii;int j;int k;int rank;int sign;int del_flag;f

40、loat num=-1;int num1=1;float sum;float cash20=0;char flag=65;sum=0;float x204=0;FILE *fp=NULL;FILE *fp1=NULL;FILE *fp2=NULL;system(color 04);printf(nt关闭主机为非法操作n);while (1)fp1=fopen(flag.txt,r+);if(fp1=NULL)printf(打开flag.txt错误!);rewind(fp1);fscanf(fp1,%2d,&n);fclose(fp1);/srand(unsigned)time(NULL); x

41、00 = rand() % 100 +350;for (i=0;in;i+)Lab: xi0 = rand() % 100 +350; for (j=0;ji;j+) / 比较一下,相同数则不要 if (xi0 = xj0) goto Lab; x01 = rand() % 20 +30;for (i=0;in;i+)cab: xi1 = rand() % 20 +30; for (j=0;ji;j+) / 比较一下,相同数则不要 if (xi1 = xj1) goto cab;/printf(%8.1f, xi1);/printf(n); x02 = rand() % 20 +20;for (i=0;in;i+)Lcab: xi2 = rand() % 20 +20; for (j=0;ji;j+) / 比较一下,相同数则不要 if (xi2 = xj2) goto Lcab;/printf(%8.1f, xi2);/printf(n);for (i=0;in;i+)sum=0;sum=sum+

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!