C语言课程设计报告(报告+代码=班级系统)._第1页
C语言课程设计报告(报告+代码=班级系统)._第2页
C语言课程设计报告(报告+代码=班级系统)._第3页
C语言课程设计报告(报告+代码=班级系统)._第4页
C语言课程设计报告(报告+代码=班级系统)._第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、河南理工大学计算机科学与技术学院课程设计报告课程名称:高级语言程序设计设计题目:班级通讯录学生姓名:杨传华学    号:专业班级:信管1002班指导教师:于金霞2021年  09 月 10  日一、设计题目及要求设计题目:班级通讯录对象:信管10级一、技术参数和设计要求:1. 该系统主要处理通讯录的相关信息。2. 通讯录信息主要包括:姓名、班级、 、家庭 、电子邮件、通讯录地址、 等内容。3. 完成以下的操作:实现通讯录信息的添加、修改、删除和查询。二、设计内容与步骤1. 分析并建立满足上述要求的数据结构2. 算法

2、设计与分析3. 程序设计、实现、调试4. 课程设计说明书二、算法设计分析因为一个班级里面有很多学生,而且每个学生又包含很多信息如姓名、学号、 、邮箱等,这些信息又分别属于不同的数据类型,但是每个学生所包含的数据信息成分相同,所以要用到构造数据类型:结构体。用到结构体,应为要能实现查找、修改、删除等,所以又要用到链表的知识!要实现这些功能,要用到模块化设计思想,用函数来解决问题!三、具体函数分析一、插入新结点在插入新结点之前,先创立一个只有指针域的头结点,又指针p扫描全链表,实现尾插法,并返回头指针。二、删除结点用连个指针p,q扫描全链表,先通过学号找到要删除的结点q,然后将q结点从链表中删除,

3、然后释放此结点!三、修改结点内容通过学号找到此学生,通过switch语句选择要修改的工程,然后进行修改。四、查找并输出通过学号找到此学生,然后分别访问并输出此结点各项内容。五、输出通讯录顺序访问链表各个结点,并输出结点信息。六、保存为文件现在d盘里面创立一个读写类型文件“,然后通过文件类型指针fp访问此文件并写入通讯录信息。七、释放结点并结束程序从头结点开始,使头结点不断后移,并将前面的结点释放。四、算法流程图goto:start开始start:输入操作符czcz=?1新建2删除3修改4查询5输出7退出系统结束6保存五、 函数运行情况及局部代码一、主函数框架主函数要用到根本输入输出、switc

4、h语句转换操作命令,然后用goto语句实现循环操作。具体如下:int main()int cz;/操作符struct stu *head,*q;head=(struct stu*)malloc(sizeof(struct stu);head->next=NULL;system("color 2e");/修改dos窗口前背景色,用两个十六进制数表示printf("n*C语言课程设计*n");printf(" *班级通讯录*nnn");printf("*1:新建通讯录*n");printf("*2:删除

5、通讯录*n");printf("*3:修改通讯录*n");printf("*4:查询通讯录*n");printf("*5:显示全部记录*n");printf("*6:保存为文件*n");printf("*7:释放链表并结束程序*n");printf("*n");start :printf("输入操作符1-7:");scanf("%d",&cz);switch(cz)case 1:q=(struct stu *)mall

6、oc(sizeof(struct stu);printf("t输入姓名:");scanf("%s",q->name);printf("t输入学号:");scanf("%d",&q->xh);printf("t输入班级:");scanf("%d",&q->grade);printf("t 号:");scanf("%s",q->cel);printf("t家庭 :");scanf(

7、"%s",q->tel);printf("t输入电子邮件:");scanf("%s",q->mail);printf("t通讯录地址:");scanf("%s",&q->add);printf("t输入 :");scanf("%s",&q->post);charu(head,q);printf("插入成功!n");break;case 2:/删除head=del(head); break;case

8、 3:change(head);break;case 4:search(head);break;case 5:printall(head);break;case 6:printf("n");baoc(head); break;case 7:sf(head);exit (0);default: printf("输入操作错误,重新"); goto start;return 0;其中用到输出*来美化系统运行页面,然后用system("color 2e");语句来修改dos界面前背景颜色,如; 二、插入函数struct stu *charu(

9、struct stu *head,struct stu *q)/插入新结点struct stu *p;for(p=head;p->next!=NULL;p=p->next);p->next=q;q->next=NULL;return head;运行界面如图:本局部采用尾插法。三、删除结点代码如下:struct stu *del(struct stu *head)/删除结点struct stu *p,*q;int a;/要删除学生的学号if(head->next=NULL)printf("*通讯录为空!*nnn");elseprintf(&quo

10、t;t输入要删除学生学号:");scanf("%d",&a);for(p=head,q=p->next;q->xh!=a&&q->next!=NULL;)p=p->next;q=p->next;if(q->xh=a)p->next=q->next;free(q);printf("删除成功!n");else printf("no people have found!");return head;运行界面:通讯录为空时:不为空时:四、查找输入要查找学生学号,

11、找到后将其输出,如图:五修改学生信息先通过学号找到该学生,然后用switch语句选择修改项,再用switch和goto语句实现是否循环,运行如图:六、保存文件在D:盘中创立一个读写文件,顺序将各节点信息保存进去,代码为:struct stu *baoc(struct stu *head)/保存文件FILE *fp;struct stu *p=head;if(head->next=NULL)printf("*通讯录为空!*nnn");else if(fp=fopen("D:班级通讯录.txt","w")=NULL)printf(&

12、quot;can't open file!n");exit(0);while(p->next!=NULL)fwrite(p->next,sizeof(struct stu),1,fp);p=p->next;fclose(fp);printf("保存文件成功!nn");return head;运行如图:七、释放结点退出系统用指针p扫描链表,头指针逐步后移,释放结点p,代码如下:void sf(struct stu *head)struct stu *p=head ;printf("释放链表:n");while(p!=NU

13、LL)head=head->next;free(p);p=head;printf("释放链表成功!n");运行如图; 六、附录:完整原代码#include<stdio.h>#include<string.h>#include<stdlib.h>#include<windows.h>struct stu char name100;/姓名int xh;/学号int grade;/年级char cel15;/ char tel50;/ char mail50;/邮件char add100;/地址char post15;/ st

14、ruct stu *next;struct stu *charu(struct stu *head,struct stu *q)/插入新结点struct stu *p;for(p=head;p->next!=NULL;p=p->next);p->next=q;q->next=NULL;return head;void search(struct stu *head)/查找结点并输出struct stu *p;int a;/要查找学生的学号if(head->next=NULL)printf("*通讯录为空!*nnn");elseprintf(&q

15、uot;t输入要查询学生学号:");scanf("%d",&a);for(p=head->next;p->next!=NULL;p=p->next)if(p->xh=a)printf(" 要查找的学生信息为:n");printf(" 姓名:");puts(p->name);printf("t学号: ");printf("%d",p->xh);printf("t年级:");printf("%dn",p-&

16、gt;grade);printf("t :");puts(p->cel);printf("t :");puts(p->tel);printf("t邮箱:");puts(p->mail);printf("t地址");puts(p->add);printf("t :");puts(p->post);printf("t查找成功!"):printf("nnn");break;if(p->xh=a)printf(" 要查

17、找的学生信息为:n");printf(" 姓名:");puts(p->name);printf("t年级:");printf("%dn",p->grade);printf("t :");puts(p->cel);printf("t :");puts(p->tel);printf("t邮箱:");puts(p->mail);printf("t地址");puts(p->add);printf("t :&q

18、uot;);puts(p->post);printf("t查找成功!"):printf("nnn");else printf("no people have found!n");struct stu *del(struct stu *head)/删除结点struct stu *p,*q;int a;/要删除学生的学号if(head->next=NULL)printf("*通讯录为空!*nnn");elseprintf("t输入要删除学生学号:");scanf("%d&quo

19、t;,&a);for(p=head,q=p->next;q->xh!=a&&q->next!=NULL;)p=p->next;q=p->next;if(q->xh=a)p->next=q->next;free(q);printf("删除成功!n");else printf("no people have found!");return head;struct stu *change(struct stu *head)/修改结点内容int b,a,c;struct stu *p;if(

20、head->next=NULL)printf("*通讯录为空!*nnn");elseprintf(" 输入要修改学生学号:");scanf("%d",&a);for(p=head->next;p!=NULL;p=p->next)if(p->next->xh=a)start:printf(" 输入想要修改什么?n");printf("ttt1:修改姓名n");printf("ttt2:修改学号n");printf("ttt3:修改

21、年级n");printf("ttt4: n");printf("ttt5: n");printf("ttt6:邮件n");printf("ttt7:地址n");printf("ttt8: n");printf(" 请输入你的选择:");scanf("%d",&b);switch(b)case 1:printf("t输入新姓名:");scanf("%s",p->name);break;case

22、2:printf("t输入新学号:");scanf("%d",&p->xh);break;case 3:printf("t输入新的班级:");scanf("%d",&p->grade);break;case 4:printf("t输入新的 号:");scanf("%s",p->cel);break;case 5:printf("t输入新的 号:");scanf("%s",p->tel);break

23、;case 6:printf("t输入新的邮箱:");scanf("%s",p->mail);break;case 7:printf("t输入新的地址:");scanf("%s",p->add);break;case 8:printf("t输入新的 ;");scanf("%s",p->post);break;default: printf("输入操作错误,请重新输入:"); printf("修改成功!n");print

24、f(" 是否要修改其他项? 1:是 2:否n");printf(" 请输入你的选择:");scanf("%d",&c);switch(c)case 1:goto start;case 2:break;return head;void printall(struct stu *head)/输出全部通讯录struct stu *p=head->next;while(1)if(p=NULL) printf("*通讯录为空!*nnn");break;else if(p->next=NULL)printf

25、(" 姓名:");puts(p->name);printf("t学号:");printf("%dn",p->xh);printf("t年级:");printf("%dn",p->grade);printf("t :");puts(p->cel);printf("t :");puts(p->tel);printf("t邮箱:");puts(p->mail);printf("t地址:"

26、);puts(p->add);printf("t :");puts(p->post);printf("输出成功!n");printf("nnn");break;else printf(" 姓名:");puts(p->name);printf("t学号:");printf("%dn",p->xh);printf("t年级:");printf("%dn",p->grade);printf("t :&q

27、uot;);puts(p->cel);printf("t :");puts(p->tel);printf("t邮箱:");puts(p->mail);printf("t地址:");puts(p->add);printf("t :");puts(p->post);printf("n");p=p->next;continue;printf("输出成功!n");struct stu *baoc(struct stu *head)/保存文件FILE

28、 *fp;struct stu *p=head;if(head->next=NULL)printf("*通讯录为空!*nnn");else if(fp=fopen("D:班级通讯录.txt","w")=NULL)printf("can't open file!n");exit(0);while(p->next!=NULL)fwrite(p->next,sizeof(struct stu),1,fp);p=p->next;fclose(fp);printf("保存文件成功!n

29、n");return head;void sf(struct stu *head)struct stu *p=head ;printf("释放链表:n");while(p!=NULL)head=head->next;free(p);p=head;printf("释放链表成功!n");int main()int cz;/操作符struct stu *head,*q;head=(struct stu*)malloc(sizeof(struct stu);head->next=NULL;system("color 2e");/修改dos窗口前背景色,用两个十六进制数表示printf("n*C语言课程设计*n");printf(" *班级通讯录*nnn");printf("*1:新建通讯录*n");printf("*2:删除通讯录*n");printf("*3:修改通讯录*n");printf("*4:查询通讯录*n");printf("*5:显示全部记录*n");print

温馨提示

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

评论

0/150

提交评论