您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > 学生籍贯信息记录簿(课程设计报告)
山东交通学院面向过程课程设计学生籍贯信息记录簿软件院(系)别信息工程系班级电气102班学号100819208姓名杨其杭指导教师时间2011-8-29—2011-9-2课程设计任务书题目学生籍贯信息记录簿系(部)信息工程系专业电气类班级102班学生姓名杨其杭学号1008192088月29日至9月2日共1周指导教师(签字)系主任(签字)年月日一、设计内容及要求编制一个学生籍贯信息记录簿,每个学生信息包括:学号、姓名、籍贯。具体功能:(1)创建信息链表并以磁盘文件保存;(2)读取磁盘文件并显示输出所有学生的籍贯信息;(3)按学号或姓名查询其籍贯;(4)按籍贯查询并输出该籍贯的所有学生;(5)能添加、删除和修改学生的籍贯信息;(6)显示输出四川籍和非四川籍学生的信息并可分别存盘。二、设计原始资料1、链表基础知识2、文件处理基础知识三、设计完成后提交的文件和图表1.计算说明书部分数据库设计分析#includestdio.h#includestring.h#includestdlib.h#defineLENsizeof(structStudent)structStudent{charnum[21];charname[256];charaddress[562];structStudent*next;};intn;//n为全局变量,本文件模块中各函数均可使用它structStudent*creat()//定义函数。此函数返回一个指向链表头的指针{structStudent*head;structStudent*p1,*p2;n=0;p1=p2=(structStudent*)malloc(LEN);printf(请依次输入学生的信息,输入学号为零时退出。\n);printf(请输入学生的学号:\n);gets(p1-num);printf(请输入学生的姓名:\n);gets(p1-name);printf(请输入学生的地址:\n);gets(p1-address);head=NULL;while(p1-num[0]!='0')//当学号是0时,退出{n=n+1;if(n==1)head=p1;elsep2-next=p1;p2=p1;p1=(structStudent*)malloc(LEN);//开辟动态存储区,把起始地址付给p1printf(请输入学生的学号:\n);gets(p1-num);//输入其他学生的学号和成绩printf(请输入学生的姓名:\n);gets(p1-name);printf(请输入学生的地址:\n);gets(p1-address);}p2-next=NULL;system(cls);return(head);}voidprint_save(structStudenthead){FILE*fp;structStudent*p;fp=fopen(D:\\stduent.txt,ab+);//打开文件if(fp==NULL){printf(文件无法打开\n);exit(0);}printf(\n现在,有%d条记录,分别是:\n,n);p=&head;if(&head!=NULL)do{printf(\n学号:);puts(p-num);printf(\n姓名:);puts(p-name);printf(\n地址:);puts(p-address);fseek(fp,0,2);if(fwrite(p,sizeof(structStudent),1,fp)!=1)printf(文件无法写入\n);p=p-next;}while(p!=NULL);fclose(fp);//关闭文件getchar();system(cls);}structStudent*pt;//定义一个Student类型的指针charcomp[3];//comp为保存输入的变量intmain()//一个调用这个creat函数的main函数c{voidShowView();//界面显示voidname_surch();//按姓名查找voidnum_surch();//按学号查找voidNativePlace_surch();//按籍贯查找voidDelete_shiyan();//删除学生信息voidmodification_shiyan();//修改学生信息voidshowSzechwan_No();//分别显示四川和非四川籍学生并非别存盘voidfileout(structStudent*p);//文件输出voidprint_save(structStudenthead);while(1){ShowView();if(strnicmp(comp,1,3)==0)//strnicmp比较两个字符串的函数{pt=creat();//函数返回链表第一个结点的地址}elseif(strnicmp(comp,6,3)==0){print_save(*pt);}elseif(strnicmp(comp,3,3)==0)//输出文件内容{fileout(pt);}elseif(strnicmp(comp,2,3)==0){name_surch();}elseif(strnicmp(comp,7,3)==0){num_surch();}elseif(strnicmp(comp,9,3)==0){//modification();modification_shiyan();//修改学生信息}elseif(strnicmp(comp,4,3)==0){//Delete();Delete_shiyan();}elseif(strnicmp(comp,5,3)==0){showSzechwan_No();}elseif(strnicmp(comp,8,3)==0){NativePlace_surch();}elseif(strnicmp(comp,0,3)==0){break;}else{printf(输入错误!!!!!!\n);}getchar();system(cls);}return0;}voidfileout(structStudent*p){FILE*fp;printf(现在有%d条记录,分别是:\n,n);fp=fopen(D:\\stduent.txt,rb);//0x00429af0if(fp==NULL){printf(文件无法打开\n);exit(0);}rewind(fp);while(!feof(fp)){fread(p,sizeof(structStudent),1,fp);//从文件中读取一块数据printf(%-15s,p-num);printf(%-15s,p-name);printf(%-15s,p-address);puts(\n);}fclose(fp);getchar();system(cls);}voidShowView()//主菜单{printf(*******************************************************************************\n);printf(**********************欢迎进入学生籍贯信息记录簿*******************************\n);printf(*******************************************************************************\n);printf(****1、cin添加*****\n);printf(****2、namesurch按名字搜索*****\n);printf(****3、fileout显示文件中的信息*****\n);printf(****4、delete删除学生信息*****\n);printf(****5、showSzechwan_No分别显示四川和非四川籍学生并非别存盘*****\n);printf(****6、save保存当前信息*****\n);printf(****7、numsurch按学号搜索*****\n);printf(****8、nativeplace安籍贯查询*****\n);printf(****9、modif修改学生信息*****\n);printf(****0、break退出*****\n);printf(*******************************************************************************\n);printf(********************请输入您的选择¥¥:);gets(comp);system(cls);//清屏}voidname_surch(){FILE*fp;charsurch[256];printf(请输入要查询的人的名字:\n);gets(surch);fp=fopen(D:\\stduent.txt,r);//0x00429af0if(fp==NULL){printf(不能打开文件\n);exit(0);}rewind(fp);//指向文件的开始while(!feof(fp))//查找{Studenta;while(!feof(fp)){fread(&a,sizeof(Student),1,fp);//从p指向的文件读入一组数据if(!strcmp(a.name,surch)){printf(%s,%s,%s\n,a.num,a.name,a.address);break;}}if(!feof(fp)){return;}else{printf(查无此人····\n);}}fclose(fp);getchar();system(cls);}voidnum_surch(){FILE*fp;charsurch[256];printf(请输入要查询的人的学号:);gets(surch);fp=fopen(D:\\stduent.txt,rb);//0x0042aab8if(fp==NULL){printf(ERROR);exit(0);}rewind(fp);//指向文件的开始while(!feof(fp))//查找{Studenta;while(!feof(fp)){fread(&a,sizeof(Student),1,fp);//从p指向的文件读入一组数据if(!strcmp(a.num,surch)){printf(%s,%s,%s\n,a.num,a.name,a.address);break;}}if(!feof(fp)){return;}else{printf(查无此人····\n);}}fclose(fp);getchar();system(cls);}voidNativePlace_surch()//按籍贯查询{FILE*fp;charsurch[256];printf(请输入要查询的人的籍贯:\n);gets(surch);fp=fopen(D:\\stduent.txt,rb);//0x00429af0if(fp==NULL){printf(文件打不开\n);exit(0);}rewind(fp);//指向文件的开始Studenta;while(!feof(fp)){fread(&a,sizeof(structStudent),1,fp);//从p指向的文件读入一组数据if(!strcmp(a.address,surch))//相当于strcmp(a.address,surch)==0{printf(%s,%s,%s\n,a.num,a.name,a.address);}}if(!feof(fp)){return;}fclose(fp);getchar();system(cls);}voidshowSzechwan_No()//分别显示四川和非四川籍学生并非别存盘{FILE*fp;FILE*sfp;//指向四川籍学生文件
本文标题:学生籍贯信息记录簿(课程设计报告)
链接地址:https://www.777doc.com/doc-5006002 .html