首页 《c语言程序设计》课程设计

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

举报
开通vip

《c语言程序设计》课程设计华中科技大学控制科学与工程系 华中科技大学控制科学与工程系 《c语言程序设计》课程设计 实验报告 课题: 实验室元器件管理系统(LMS) 专业: 自动化 班级: 自动化0702 姓名: 赵旭峰 周润康 学号: u200713925 成绩: 完成时间:2008年10月24日 目 录 系统开发背景介绍...............3 系统功能模块图.................4 3.系统工程文件组成...............5 4.工作量说明.....................5 5.数据结构设计......

《c语言程序设计》课程设计
华中科技大学控制科学与工程系 华中科技大学控制科学与工程系 《c语言程序设计》课程设计 实验 报告 软件系统测试报告下载sgs报告如何下载关于路面塌陷情况报告535n,sgs报告怎么下载竣工报告下载 快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题 : 实验室元器件管理系统(LMS) 专业: 自动化 班级: 自动化0702 姓名: 赵旭峰 周润康 学号: u200713925 成绩: 完成时间:2008年10月24日 目 录 系统开发背景介绍...............3 系统功能模块图.................4 3.系统工程文件组成...............5 4.工作量说明.....................5 5.数据结构设计...................6 6.程序流程图.....................7 7.程序开发历程..................12 8.系统的亮点....................13 9.系统的不足....................13 10.编程规范.....................14 11.系统源码.....................17 (报告制作人:赵旭峰 周润康) 系统开发背景 系统名:实验室元件器管理系统 NAME:Lab Manage System(LMS) 系统缘起:我们专业的课程设计 系统开发时间:第三周至第二周 开发人员:赵旭峰(组长) 周润康 总代码量:2435行 (计算 标准 excel标准偏差excel标准偏差函数exl标准差函数国标检验抽样标准表免费下载红头文件格式标准下载 :函数与函数之间空一行,函数内无空行) 参考资料: 周纯杰,刘正林等. 《标准C语言程序及应用》. 武汉: 华中科技大学出版社. 2005 刘玮玮,汪晓平.《C语言高级实例解析》.清华大学出版社.2005 飞思科技.《C语言范例开发宝典》.2008 王为青 刘变红.《c语言高级编程及实例剖析》.2007 系统功能模块组成图 系统文件组成 简介:工程共包括八个文件,其中包括两个.h文件和六个.cpp文件 文件名 文件类型 文件行数 文件包含 Code by DRAWELEM .CPP 325 绘制元件 相关函数 赵旭峰 ELEMDATA .cpp 497 元件信息存储 读取相关函数 赵旭峰 CHINESE .cpp 143 操作汉字库 相关函数 周润康 key .h 8 键盘扫描码 宏定义 周润康 UI .cpp 979 UI界面图形下输入输出函数 赵旭峰 LMS .h 120 结构体声明 函数声明等 周润康 MAIN .cpp 68 主函数及文件检测函数 赵旭峰 USERDATA .cpp 295 用户信息存储 读取相关函数 周润康 工作量说明 赵旭峰:负责元件模块,图形界面的编码,并负责后期代码整合 累计代码量1869/2435 周润康:考虑到周润康同学是澳门籍学生,负责用户模块,工程头文件及系统汉化的编码工作 累计代码量566/2436 数据结构设计 管理员用户 用户信息存储文件:userinfo.dat 存储方式:文本 元件信息 元件信息存储文件:eleinfo.dat 存储方式:文本 程序流程图 主流程图 管理员用户模块流程图 普通用户流程图 元件管理模块 用户管理模块 查看元件模块 程序开发日历 第三周:进行初步需求分析,并讨论系统开发所需要的自习决定学习目标 第四周:学习图形,文件处理,链 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 等方面知识 第五周:详细系统分析,划分系统模块,分配开发任务,规划工程文件建立工程 第六周:开始正式编码,完成用户模块大部分编码,并制作全部菜单完成系统流程接口 第七周:汉化模块的实现,完成元件模块数据存储部分,并攻关实现图形方式下文本输入 第八周:元件信息分页显示的攻关实现,键盘元件绘制系统的攻关实现,代码的最后整合和测试修改 系统历程: 实现文本下用户操作→添加图形菜单→添加文本元件操作→删除文本元件添加图形下添加元件→汉化系统→添加图形下搜索文件及显示元件具体信息→添加图形下编辑元件→添加图下元件信息的统计列表→添加图形下列表显示全部元件部分信息→添加元件列表的分页,导出功能→添加元件列表的六种排序功能→添加从元件列表进入元件详细信息功能→添加选择元件类型显示列表功能→添加键盘绘制元件图形模块→完 系统亮点 上下菜单,左右菜单,上下左右菜单的实现 图形下文本输入框,密码输入框的实现 图像下支持自动换行支持空格的文本域输入框的实现 支持换页,统计页数,显示当前页码的信息列表的实现 在键盘操作下绘制元件,拥有联动的效果展示区和四倍作图区,并能以设定格式保存图形信息 提取绘制元件文件的内部数据,实现元件图形显示功能 系统的不足 由于各种原因我们有如下设想功能还未实现 文件存储信息的加密和解密 鼠标绘制元件图形 输入框的非空验证 输入信息的格式验证 导出文件空格置换问题(为了解决读取不出空格问题,在存储元件信息是,我们用@置换掉空格,但在用户导出txt时候没有把@置换回空格) 编程规范 函数命名规范: 术语解释: Pascal 大小写 将标识符的首字母和后面连接的每个单词的首字母都大写。可以对三字符或更多字符的标识符使用Pascal 大小写。例如: BackColor 函数命名: 采用Pascal命名,名称应该说明“做什么”而不是“如何做”。 例如:void MediaPlay() { //method } 代码规范: 每行一个语句 每行最多包含一个语句。如 a++; //推荐 b--; //推荐 a++; b--; //不推荐 复合语句 复合语句是指包含"父语句{子语句;子语句;}"的语句,使用复合语句应遵循以下几点 1 子语句要缩进。 2 左花括号“{” 在复合语句父语句的下一行并与之对齐,单独成行。 3 即使只有一条子语句要不要省略花括号“ {}”。 如 while (d + = s++) { n++; } return 语句 return语句中不使用括号,除非它能使返回值更加清晰。如 return; return myDisk.size(); return (size ? size : defaultSize); if、 if-else、if else-if 语句 if、 if-else、if else-if 语句使用格式 if (condition) { statements; } if (condition) { statements; } else { statements; } if (condition) { statements; } else if (condition) { statements; } else { statements; } for 语句 for 语句使用格式 for (initialization; condition; update) { statements; } 空的 for 语句(所有的操作都在initialization、condition 或 update中实现)使用格式 for (initialization; condition; update); 注意 1在循环过程中不要修改循环计数器。 2对每个空循环体给出确认性注释。 while 语句 while 语句使用格式 while (condition) { statements; } 空的 while 语句使用格式 while (condition); switch - case 语句 switch - case 语句使用格式 switch (condition) { case 1: statements; break; case 2: statements; break; default: statements; break; } 注意: 1、语句switch中的每个case各占一行。 2、语句switch中的case按字母顺序排列。 3、为所有switch语句提供default分支。 4、所有的非空 case 语句必须用 break; 语句结束。 系统源码 LMS.H文件 //Code by 周润康 #include #include #include #include #include #include #include #include #include #include "key.h" #define BGIFILE "c:\\BORLANDC\\BGI"//BGI文件路径的宏定义 #define UserFile "userinfo.dat" //用户信息存储文件宏定义 #define ElementFile "eleinfo.dat" //元件信息存储文件宏定义 #define HZKU "c:\\zxf\\HZK16"//汉字库文件路径宏定义 //管理员结构体 struct User { char UserName[20]; char UserPwd[20]; }; //元件结构体 typedef struct { char EleName[20]; char EleClass[20]; char TotalNum[6]; char year[5]; char month[3]; char day[3]; char ElePrice[6]; char Content[200]; }Element; //元件链表节点 typedef struct elelink { Element elem; struct elelink *next; }EleNode; //在main.cpp内的函数 void Welcome();//检查文件是否存在不存在则创建若用户文件不存在调用第一次使用相关步骤 //在 userdata.cpp内的函数 int CheckAllFile();//检查文件是否存在不存在则创建 void AddNewAdmin(int);//添加一个新管理员 void ShowNewAdmin(struct User);//显示刚添加的管理员信息 void OutPutAdminInfo(struct User);//格式化输出管理员信息 void SaveNewAdmin(struct User);//把新管理员信息存进文档 int AdminLogin(struct User);//管理员登陆 void InPutAdminInfo(int);//编辑和删除管理员的接口 void EditAdminByName(struct User);//按用户名修改管理员 void ShowAllAdmin();//显示文件中所有存在的管理员信息 void DelAdminByName(struct User);//按用户名删除管理员 //在 elemdata.cpp内的函数 void InsertOneElement(Element);//插入一个元件 void InsertElelink(EleNode *,int);//插入一个元件链表 void CreateTxt(EleNode *,int );//以txt形式导出链表 void GetAllElement(EleNode *,int *);//获取所有元件信息 void GetElementByClass(EleNode *,int *,char *);//按类型获取元件链表 void SearchElementByName(Element *);//按元件名搜索元件 void EditElementByName(Element,Element );//按原件名编辑元件 void DelElementByName(Element );//按元件名删除元件 void CountByClass(char *,long *,double *,int *);//统计元件信息 void SortByNum(EleNode *,int,int);//按元件总数升降序排列 void SortByPrice(EleNode *,int,int);//按元件价格升降序排列 void SortByTime(EleNode *,int ,int);//按元件购买时间升降序排列 void ChangeValue(EleNode *,EleNode *);//交换两个元件节点的元件值 Element * GetElementByNum(EleNode *head,int num,Element *ele);//在链表中获取指定节点 void GetElementList(int classid,EleNode *head,int *num);//获取元件链表的接口 void ChoseSort(int ,EleNode *,int);//选择排序方式 void FreeAll(EleNode *,int);//释放链表占用的所有内存 //在 ui.cpp内的函数 int ui_welcome();//显示初始菜单 int ShowMenu(char menu[][20],int,int);//上下菜单函数 void AboutLMS();//关于LMS void LeaveLMS();//欢迎下次使用 LMS int ui_AdminLogin();//管理员 LMS void PwdError();//提示密码错误 int ui_Admin();//管理员主界面 int ui_CommonUser();//普通用户主界面 void ui_UserManage();//用户管理界面 void ui_ElementManage();//元件管理界面 int ShowClass();//显示元件种类 void ui_AddElement();//添加元件前台界面 void SeeElement(int );//查看元件信息 void SearchElement(int );//按名字搜索元件前台 void ShowElementList(int ,int);//显示元件列表 void ShowElement(int ,Element *);//显示单个元件具体信息 void ui_Count();//显示统计列表 void ui_EditElement(Element *);//编辑单个元件 void DoEditElement();//编辑元件入口 void InputTextBox(int ,int ,int ,char *,int,int);//单行文本输入框 void InputPassWord(int ,int ,int ,char *,int);//密码输入框 void ChoiceClass(int,int,char *);//选择种类并提够上下左右选择 void InputTextArea(int ,int ,int ,int ,char *,int,int);//多行文本输入框 //在 DRAWELEM.CPP内的函数 void IC(int ,int ,int);//画ic类通用图 void DianZhu(int ,int ,int);//画电阻类通用图 void DianRong(int ,int ,int);//画电容类通用图 void DianGan(int ,int ,int);//画电感类通用图 void DianLuBan(int ,int ,int);//画电路板类通用图 void DianYuan(int ,int ,int);//画电源类通用图 void ShowPic(int ,int ,int,Element *);//显示元件图片 void DrawElement(Element *);//用户自己画元件 void ShowPixel(int ,int ,int *);//显示画笔焦点 void DelPixel(int ,int ,int *);//删除画笔焦点 void SetColorlList(int *,int );//设置删除颜色 void ShowXY(int ,int ,int ,int );//输出画笔坐标 //在 Chinese.CPP内的函数 void ShowHz(int,int,unsigned char,unsigned char,int);//获取点阵并输出 void OutHzxy(int ,int ,char *,int);//输出16*16汉字接口 void ShowBigHz(int,int,unsigned char,unsigned char,int);//放大获取点阵并输出 void OutBigHzxy(int ,int ,char *,int);////输出32*32汉字接口 KEY.H //code by 周润康 #define KEY_ESC 0x011b #define KEY_ENTER 0x1c0d #define KEY_UP 0x4800 #define KEY_DOWN 0x5000 #define KEY_LEFT 0x4b00 #define KEY_RIGHT 0x4d00 #define KEY_BACK 0x0e08 #define CTRL_S 0x1f13 Main.cpp //code by 赵旭峰 #include "LMS.H" void main() { int i=0,j=0; Welcome(); while(1)//进入程序主循环 { i=ui_welcome(); switch(i) { case 0: break; case 1: while(1)//进入管理员用户模块循环 { j=ui_Admin(); if(j==3) { break; } switch(j) { case 1: ui_UserManage(); break; case 2: ui_ElementManage(); break; case 4: exit(0); } } break; case 2: while(1)//进入普通用户模块循环 { j=ui_CommonUser(); if(j==3) { break; } switch(j) { case 1: SeeElement(0); break; case 2: SearchElement(0); break; case 4: exit(0); } } break; default: exit(0); } } } void Welcome() { if(CheckAllFile()) { AddNewAdmin(1); } } USERDATA.cpp //code by 周润康 #include "LMS.H" int CheckAllFile() { int i=0; FILE * fp; clrscr(); window(1, 1, 80, 25); textbackground(2); clrscr(); textcolor(0x24); if((fp=fopen(UserFile,"rt"))==NULL) { i=1; fp=fopen(UserFile,"wt"); } if((fp=fopen(ElementFile,"at"))==NULL) { if((fp=fopen(ElementFile,"wt"))==NULL) { printf("Error,can not creat the file\n"); printf("press any key to exit......"); getch(); exit(1); } } fclose(fp); return i; } void AddNewAdmin(int i) { struct User newuser; if(i) { clrscr(); printf("This is the first time use Lab Manage System!\n"); printf("You should set the admin's name and admin's password:\n"); printf("New Admin Name:\n"); printf("PassWord:\n"); gotoxy(16,3); gets(newuser.UserName); gotoxy(10,4); gets(newuser.UserPwd); ShowNewAdmin(newuser); } else { clrscr(); printf("Please set the new admin's name and new admin's password:\n"); printf("New Admin Name:\n"); printf("PassWord:\n"); gotoxy(16,2); gets(newuser.UserName); gotoxy(10,3); gets(newuser.UserPwd); ShowNewAdmin(newuser); } } void ShowNewAdmin(struct User newuser) { char choice; clrscr(); printf("This is the total infomation you just input:\n"); OutPutAdminInfo(newuser); printf("Are you sure to save it?\n"); printf("Press 'y' to save it,'n' to input it again:"); while(1) { choice=getch(); if(choice=='y') { SaveNewAdmin(newuser); break; } else if(choice=='n') { AddNewAdmin(0); } } } void OutPutAdminInfo(struct User newuser) { printf("----------------------------------------\n"); printf("* Admin Name:%s\n",newuser.UserName); printf("* Password:%s\n",newuser.UserPwd); printf("----------------------------------------\n"); } void SaveNewAdmin(struct User newuser) { FILE *fp; if((fp=fopen(UserFile,"at"))==NULL) { fp=fopen(UserFile,"wt"); } fprintf(fp,"%-24s%-24s\n",newuser.UserName,newuser.UserPwd); fclose(fp); } int AdminLogin(struct User userinfo) { int i=0; struct User tempuser; FILE *fp; if((fp=fopen(UserFile,"rt"))==NULL) { return i; } while(!feof(fp)) { fscanf(fp,"%s%s\n",tempuser.UserName,tempuser.UserPwd); if(strcmp(userinfo.UserName,tempuser.UserName)==0&&strcmp(userinfo.UserPwd,tempuser.UserPwd)==0) { i=1; break; } } return i; } void InPutAdminInfo(int i) { struct User userinfo; clrscr(); if(i) { printf("Please Input The Admin Name which you want to Edit:"); gets(userinfo.UserName); EditAdminByName(userinfo); } else { printf("Please Input The Admin Name which you want to Del:"); gets(userinfo.UserName); DelAdminByName(userinfo); } } void EditAdminByName(struct User userinfo) { int k; long offset; FILE *fp; struct User tempuser; clrscr(); if((fp=fopen(UserFile,"rt+"))==NULL) { printf("Error,Can not open the file!\n"); printf("Press any key to exit......."); getch(); exit(1); } while(!feof(fp)) { offset=ftell(fp); fscanf(fp,"%s%s\n",tempuser.UserName,tempuser.UserPwd); if(!strcmp(userinfo.UserName,tempuser.UserName)) { k=1; break; } } if(k) { printf("We have searched the infomation:\n"); OutPutAdminInfo(tempuser); printf("now please input the new info\n"); printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); printf("* new Admin Name:"); gets(userinfo.UserName); printf("* new Admin PassWord:"); gets(userinfo.UserPwd); fseek(fp,offset,0); fprintf(fp,"%-24s%-24s\n",userinfo.UserName,userinfo.UserPwd); } else { printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); printf("we can not find the person whose name is %s\n",userinfo.UserName); printf("so, you can not edit it\n"); printf("maybe you can add a new admin\n"); printf("\n\npress any key to contuine....."); getch(); } fclose(fp); } void ShowAllAdmin() { int k=0; long offset; FILE *fp; struct User tempuser; clrscr(); if((fp=fopen(UserFile,"rt"))==NULL) { printf("Error,Can not open the file!\n"); printf("Press any key to exit......."); getch(); exit(1); } while(!feof(fp)) { fscanf(fp,"%s%s\n",tempuser.UserName,tempuser.UserPwd); OutPutAdminInfo(tempuser); k++; } if(!k) { printf("sorry,we can not find any admin!\n"); } printf("press any key to go back........\n"); fclose(fp); getch(); } void DelAdminByName(struct User userinfo) { int k; char choice; long offset; FILE *fp; struct User tempuser; clrscr(); if((fp=fopen(UserFile,"rt+"))==NULL) { printf("Error,Can not open the file!\n"); printf("Press any key to exit......."); getch(); exit(1); } while(!feof(fp)) { offset=ftell(fp); fscanf(fp,"%s%s\n",tempuser.UserName,tempuser.UserPwd); if(!strcmp(userinfo.UserName,tempuser.UserName)) { k=1; break; } } if(k) { printf("We have searched the infomation:\n"); OutPutAdminInfo(tempuser); printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); printf("Are you sure to del it?\n"); printf("Press 'y' to del,'n' to return:"); while(1) { choice=getch(); if(choice=='y') { fseek(fp,offset,0); fprintf(fp,"%-24s%-24s\n","",""); break; } else if(choice=='n') { break; } } } else { printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); printf("we can not find the person whose name is %s\n",userinfo.UserName); printf("so, you need not to del it\n"); printf("\n\npress any key to contuine....."); getch(); } fclose(fp); } ELEMDATA.cpp //code by 赵旭峰 #include "LMS.H" void InsertOneElement(Element ele) { FILE *fp; if((fp=fopen(ElementFile,"at"))==NULL) { fp=fopen(ElementFile,"wt"); } fprintf(fp,"%-22s%-22s%-8s%-7s%-5s%-5s%-8s%-202s\n",ele.EleName,ele.EleClass,ele.TotalNum,ele.year,ele.month,ele.day,ele.ElePrice,ele.Content); fclose(fp); } void InsertElelink(EleNode *head,int i) { EleNode *p; FILE *fp; if(i) { fp=fopen(ElementFile,"wt"); } else { if((fp=fopen(ElementFile,"at"))==NULL) { fp=fopen(ElementFile,"wt"); } } p=head; while(p!=NULL) { fprintf(fp,"%-22s%-22s%-8s%-7s%-5s%-5s%-8s%-202s\n",p->elem.EleName,p->elem.EleClass,p->elem.TotalNum,p->elem.year,p->elem.month,p->elem.day,p->elem.ElePrice,p->elem.Content); p=p->next; } fclose(fp); } void CreateTxt(EleNode *head,int num) { EleNode *p; FILE *fp; int i; if((fp=fopen("C:\\LMSRecord.txt","wt"))==NULL) { printf("Can't create file in disk c:"); getch(); exit(1); } fprintf(fp,"%-22s%-22s%-8s%-7s%-5s%-5s%-8s%-202s\n","元件名","元件类别","元件总数","购进年","购进月","购进日","元件单价","元件简介"); p=head; for(i=0;ielem.EleName,p->elem.EleClass,p->elem.TotalNum,p->elem.year,p->elem.month,p->elem.day,p->elem.ElePrice,p->elem.Content); p=p->next; } fclose(fp); } void GetAllElement(EleNode *head,int *num) { EleNode *p,*q; FILE *fp; *num=0; p=head; if((fp=fopen(ElementFile,"rt"))==NULL) { clrscr(); printf("Error,Can not open the file!\n"); getch(); exit(1); } while(!feof(fp)) { fscanf(fp,"%s%s%s%s%s%s%s%s\n",p->elem.EleName,p->elem.EleClass,p->elem.TotalNum,p->elem.year,p->elem.month,p->elem.day,p->elem.ElePrice,p->elem.Content); q=(EleNode *)malloc(sizeof(EleNode)); if(q==NULL) { printf("no enought meory"); getch(); exit(1); } p->next=q; p=q; *num=*num+1; } q=NULL; p=NULL; fclose(fp); } void GetElementByClass(EleNode *head,int *num,char * classname) { Element tempele; EleNode *p,*q; FILE *fp; *num=0; p=head; if((fp=fopen(ElementFile,"rt"))==NULL) { clrscr(); printf("Error,Can not open the file!\n"); getch(); exit(1); } while(!feof(fp)) { fscanf(fp,"%s%s%s%s%s%s%s%s\n",tempele.EleName,tempele.EleClass,tempele.TotalNum,tempele.year,tempele.month,tempele.day,tempele.ElePrice,tempele.Content); if(!strcmp(tempele.EleClass,classname)) { strcpy(p->elem.EleName,tempele.EleName); strcpy(p->elem.EleClass,tempele.EleClass); strcpy(p->elem.TotalNum,tempele.TotalNum); strcpy(p->elem.year,tempele.year); strcpy(p->elem.month,tempele.month); strcpy(p->elem.day,tempele.day); strcpy(p->elem.ElePrice,tempele.ElePrice); strcpy(p->elem.Content,tempele.Content); q=(EleNode *)malloc(sizeof(EleNode)); if(q==NULL) { printf("no enought meory"); getch(); exit(1); } p->next=q; p=q; *num=*num+1; } } p=NULL; fclose(fp); } void SearchElementByName(Element *ele) { Element tempele; FILE *fp; if((fp=fopen(ElementFile,"rt"))==NULL) { clrscr(); printf("Error,Can not open the file!\n"); getch(); exit(1); } while(!feof(fp)) { fscanf(fp,"%s%s%s%s%s%s%s%s\n",tempele.EleName,tempele.EleClass,tempele.TotalNum,tempele.year,tempele.month,tempele.day,tempele.ElePrice,tempele.Content); if(!strcmp(tempele.EleName,ele->EleName)) { strcpy(ele->EleName,tempele.EleName); strcpy(ele->EleClass,tempele.EleClass); strcpy(ele->TotalNum,tempele.TotalNum); strcpy(ele->year,tempele.year); strcpy(ele->month,tempele.month); strcpy(ele->day,tempele.day); strcpy(ele->ElePrice,tempele.ElePrice); strcpy(ele->Content,tempele.Content); break; } } fclose(fp); } void EditElementByName(Element oldele,Element newele) { int k; long offset; FILE *fp; Element tempele; if((fp=fopen(ElementFile,"rt+"))==NULL) { printf("Error,Can not open the file!\n"); getch(); exit(1); } while(!feof(fp)) { offset=ftell(fp); fscanf(fp,"%s%s%s%s%s%s%s%s\n",tempele.EleName,tempele.EleClass,tempele.TotalNum,tempele.year,tempele.month,tempele.day,tempele.ElePrice,tempele.Content); if(!strcmp(oldele.EleName,tempele.EleName)) { k=1; break; } } if(k) { fseek(fp,offset,0); fprintf(fp,"%-22s%-22s%-8s%-7s%-5s%-5s%-8s%-202s\n",newele.EleName,newele.EleClass,newele.TotalNum,newele.year,newele.month,newele.day,newele.ElePrice,newele.Content); } else { printf("can't find the element"); getch(); } fclose(fp); } void DelElementByName(Element oldele) { char str[24]; int k,len; long offset; FILE *fp; Element tempele; strcpy(str,oldele.EleName); len=strlen(str); str[len]='.'; str[len+1]='p'; str[len+2]='i'; str[len+3]='c'; str[len+4]='\0'; if((fp=fopen(ElementFile,"rt+"))==NULL) { printf("Error,Can not open the file!\n"); getch(); exit(1); } while(!feof(fp)) { offset=ftell(fp); fscanf(fp,"%s%s%s%s%s%s%s%s\n",tempele.EleName,tempele.EleClass,tempele.TotalNum,tempele.year,tempele.month,tempele.day,tempele.ElePrice,tempele.Content); if(!strcmp(oldele.EleName,tempele.EleName)) { k=1; break; } } if(k) { fseek(fp,offset,0); fprintf(fp,"%-22s%-22s%-8s%-7s%-5s%-5s%-8s%-202s\n","","","","","","","",""); remove(str); } else { printf("can't find the element"); getch(); } fclose(fp); } void CountByClass(char *classname,long *total,double *money,int *num) { Element tempele; FILE *fp; *total=0; *money=0; *num=0; if((fp=fopen(ElementFile,"rt"))==NULL) { clrscr(); printf("Error,Can not open the file!\n"); getch(); exit(1); } while(!feof(fp)) { fscanf(fp,"%s%s%s%s%s%s%s%s\n",tempele.EleName,tempele.EleClass,tempele.TotalNum,tempele.year,tempele.month,tempele.day,tempele.ElePrice,tempele.Content); if(!strcmp(tempele.EleClass,classname)) { float price; long n; n=atol(tempele.TotalNum); price=atof(tempele.ElePrice); *money+=price*n; *total+=n; *num=*num+1; } } fclose(fp); } void SortByNum(EleNode *head,int flag,int num) { EleNode *p,*q; long num1,num2; p=head; int i,j; for(i=0;inext; num1=atol(p->elem.TotalNum); for(j=i+1;jelem.TotalNum); if(flag==0&&num1>num2) { ChangeValue(p,q); } else if(flag==1&&num1next; } p=p->next; } } void SortByPrice(EleNode *head,int flag,int num) { EleNode *p,*q; float price1,price2; p=head; int i,j; for(i=0;inext; price1=atof(p->elem.ElePrice); for(j=i+1;jelem.ElePrice); if(flag==0&&price1>price2) { ChangeValue(p,q); } else if(flag==1&&price1next; } p=p->next; } } void SortByTime(EleNode *head,int flag,int num) { EleNode *p,*q; int year1,year2; int month1,month2; int day1,day2; p=head; int i,j; for(i=0;inext; year1=atoi(p->elem.year); month1=atoi(p->elem.month); day1=atoi(p->elem.day); for(j=i+1;jelem.year); month2=atoi(q->elem.month); day2=atoi(q->elem.day); if(flag==0&&year1>year2) { ChangeValue(p,q); } else if(flag==1&&year1month2)) { ChangeValue(p,q); } else if((year1==year2)&&(flag==1&&month1day2)) { ChangeValue(p,q); } else if((year1==year2)&&(month1==month2)&&(flag==1&&day1next; } p=p->next; } } void ChangeValue(EleNode *p,EleNode *q) { Element tempele; strcpy(tempele.EleName,p->elem.EleName); strcpy(tempele.EleClass,p->elem.EleClass); strcpy(tempele.TotalNum,p->elem.TotalNum); strcpy(tempele.ye
本文档为【《c语言程序设计》课程设计】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_285380
暂无简介~
格式:doc
大小:768KB
软件:Word
页数:73
分类:工学
上传时间:2010-11-12
浏览量:90