




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C语言作业管理程序设计报告院系 班级 姓名 学号 一C语言作业管理程序的要求定义结构体:Struct studentint num; /序号char *name; / 姓名long phone;/电话char *homework; /作业进入菜单前,密码3次校验。菜单:printf(=n);printf( 1. Openn);printf( 2. Listn);printf( 3. Addn);printf( 4. Saven);printf( 5. Exitn);printf(=n);输入每位同学的信息,当输入的序号=0,结束返回主菜单。用文件保存起来,下次可以打开,显示,并添加新的记录。要求工程管理若干文件,每个文件有若干函数。二 程序设计思路1. 每一个菜单的功能可以用一个函数实现,主函数用switch语句调用函数实现open,list,add,save功能,exit通过当输入5时函数退出循环实现2. 程序源文件分为7个文件,头文件student.h,主函数一个文件main.c,子函数password.c,open.c,list.c,add.c,save.c各一个文件。3.流程图三 源代码/*-student.h-*/struct student /头文件包含结构体定义和函数申明 int num; char name20; long phone; char homework20;int password();void open(struct student *stu);void list(struct student *stu);void add(struct student *stu,int *n);void save(struct student *stu,int *n);/*-main.c-*/# include # include # include # include # include student.h# define N 100void main() struct student stuN; /定义结构体数组 int i,j,t,flag; int *n; clrscr(); t=password(); /调用password函数,返回值赋给t if(t) printf(password error!n); return; printf( MENU n); /打印菜单 printf(=n); printf(1.openn); printf(2.listn); printf(3.addn); printf(4.saven); printf(5.exitn); printf(0.returnn); printf(=n); printf(please choose the function); scanf(%d,&flag); while(flag!=5) /当输入5时,退出循环,即可退出整个程序 switch(flag) case 0: printf( MENU n); /输入0时返回主菜单 printf(=n); printf(1.openn); printf(2.listn); printf(3.addn); printf(4.saven); printf(5.exitn); printf(0.returnn); printf(=n); printf(please choose the function); scanf(%d,&flag); break;case 1: open(stu); /输入1时调用open函数,打或新建文档 printf(press 0 to returnn); scanf(%d,&flag); break;case 2:list(stu); /输入2时调用list函数,列出文档内容 printf(press 0 to returnn); scanf(%d,&flag); break;case 3: add(stu,n); /输入3时调用add函数,向文档中加入内容scanf(%d,&flag);break;case 4:save(stu,n); /输入4时调用save函数,保存文档 printf(press 0 to returnn); scanf(%d,&flag); break;default :printf(error in input datan); /如果输入的不是1,2,3,4,5,则 printf(press 0 to returnn);/显示此信息 scanf(%d,&flag); break; /*-password.c-*/# include /password函数通过循环校验3次密码,如果3此都# include /输错则返回1# include # include # define N 100int password() char *str=12345; char *password; int i,j; clrscr(); for(i=0;i3;i+) printf(Please input password:);gets(password);if(strcmp(password,str)=0) break;else printf(password errorn); if(i=3)return 1;/*-open.c-*/# include / open函数,打开或新建文档# include # include # include # include student.h# define N 100void open() FILE *fp; clrscr(); if(fp=fopen(c:grade.txt,rt+)=NULL) if(fp=fopen(c:grade.txt,wt+)=NULL) printf(cant open or creat the filen);else printf(the file has been created in c: n); fclose(fp); else fclose(fp);printf(nfile opened successfullyn); /*-list.c-*/# include /list函数列出文档内容# include # include # include # include student.h# define N 100void list(struct student *stu) FILE *fp; int j,i; clrscr(); for(i=0;inum=0; if(fp=fopen(c:grade.txt,r)=NULL) printf(cant open the filen); getch(); exit(1); rewind(fp); for(i=0;i+) fscanf(fp,%d%s%ld%s, &(stu+i)-num,(stu+i)-name,&(stu+i)-phone,(stu+i)-homework); if(stu+i)-num=0) break; printf(numbertnametphonethomeworkn); printf(-n); for(j=0;jnum,(stu+j)-name,(stu+j)-phone,(stu+j)-homework); fclose(fp);/*-add.c-*/# include /add函数向文档中添加内容# include # include # include # include student.h# define N 100void add(struct student *stu,int *n) FILE *fp; int i; clrscr(); if(fp=fopen(c:grade.dat,at+)=NULL) printf(cant open the filen); getch(); exit(1); printf(Please input the number of students:); scanf(%d,n); printf(nnumbertnametphonethomeworkn); for(i=0;inum,(stu+i)-name,&(stu+i)-phone,(stu+i)-homework); fclose(fp); printf(tPress 4 to save );/*-save.c-*/# include /save函数保存文档# include # include # include # define N 100# include student.hvoid save(struct student *stu,int *n) FILE *fp; int i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 离异父母子女抚养费用及生活费用支付协议
- 离婚协议彩礼退还与房产分割执行范本
- 车辆抵押贷款业务业务流程优化与风险控制服务合同
- 短途接送服务合同范本含司机专业操作标准
- 离婚协议中包含子女学业资助与成长保障
- 装修合同签订前合同主体资格审核要点
- 离婚协议中虚拟货币分割与风险控制协议样本
- 人物花瓶黏土课件
- 辽沈战役精简课件
- 个人有关事项培训
- 统编版四年级上册第四单元快乐读书吧 《中国古代神话故事》 课件
- GRE强化填空36套精练与精析
- 公司质量培训计划方案
- 供应商审计培训课件
- 循环经济的环保意义
- 发展汉语初级综合1:第3课课件
- 第二十章-颅内和椎管内血管性疾病
- 中国秘书史(第二版)全套教学课件
- 建筑工程质量安全检查记录表
- GB/T 42866-2023煤化工废水处理与回用技术导则
- 病原生物与免疫学知识点
评论
0/150
提交评论