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

下载本文档

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

文档简介

1、C语言课程设计报告(报告+代码=班级通讯录系统) 河南理工大学计算机科学与技术学院课程设计报告 课程名称:高级语言程序设计 学生姓名:杨传华学 号:2021年 月日一、设计题目及要求设计题目:班级通讯录对象:信管10级一、技术参数和设计要求:1. 该系统主要处理通讯录的相关信息。2. 通讯录信息主要包括:姓名、班级、 、家庭 、电子邮件、通讯录地址、 等内容。3. 完成以下的操作:实现通讯录信息的添加、修改、删除和查询。二、设计内容与步骤1. 分析并建立满足上述要求的数据结构2. 算法设计与分析3. 程序设计、实现、调试4. 课程设计说明书二、算法设计分析因为一个班级里面有很多学生,而且每个学

2、生又包含很多信息如姓名、学号、 、邮箱等,这些信息又分别属于不同的数据类型,但是每个学生所包含的数据信息成分相同,所以要用到构造数据类型:结构体。用到结构体,应为要能实现查找、修改、删除等,所以又要用到链表的知识!要实现这些功能,要用到模块化设计思想,用函数来解决问题!三、具体函数分析一、插入新结点在插入新结点之前,先创立一个只有指针域的头结点,又指针p扫描全链表,实现尾插法,并返回头指针。二、删除结点用连个指针p,q扫描全链表,先通过学号找到要删除的结点q,然后将q结点从链表中删除,然后释放此结点!三、修改结点内容通过学号找到此学生,通过switch语句选择要修改的工程,然后进行修改。四、查

3、找并输出通过学号找到此学生,然后分别访问并输出此结点各项内容。 五、输出通讯录顺序访问链表各个结点,并输出结点信息。六、保存为文件现在d盘里面创立一个读写类型文件“班级通讯录.txt,然后通过文件类型指针fp访问此文件并写入通讯录信息。七、释放结点并结束程序从头结点开始,使头结点不断后移,并将前面的结点释放。四、算法流程图 五、 函数运行情况及局部代码一、主函数框架主函数要用到根本输入输出、switch语句转换操作命令,然后用goto语句实现循环操作。具体如下:int main()int cz;/操作符struct stu *head,*q;head=(struct stu*)malloc(s

4、izeof(struct stu);head->next=NULL;system("color 2e");/修改dos窗口前背景色,用两个十六进制数表示*n"); printf("n*C语言课程设 printf(" *班级通讯录*nnn"); printf(" * 1:新建通讯录 *n");printf(" * 2:删除通讯录 *n");printf(" * 3:修改通讯录 *n&am

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

6、);switch(cz)case 1:q=(struct stu *)malloc(sizeof(struct stu);printf("t输入姓名:");scanf("%s",q->name);printf("t输入学号:");scanf("%d",&q->xh);printf("t输入班级:");scanf("%d",&amp

7、;q->grade);printf("t 号:");scanf("%s",q->cel);printf("t家庭 :");scanf("%s",q->tel);printf("t输入电子邮件:");scanf("%s",q->mail);printf("t通讯录地址:");scanf(&am

8、p;quot;%s",&q->add);printf("t输入 :");scanf("%s",&q->post); 计 charu(head,q); printf("插入成功!n");break; case 2:/删除 head=del(head); break; change(head);break; search(head);break; printall(head); break; printf(&

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

10、/插入新结点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(&q

11、uot;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) else printf("no people have found!"); p->next=q->next; fr

12、ee(q); printf("删除成功!n"); return head; 行界面:通讯录为空时:不为空时:四、查找输入要查找学生学号,找到后将其输出,如图: 五修改学生信息先通过学号找到该学生,然后用switch语句选择修改项,再用switch和goto语句实现是否循环,运行如图: 六、保存文件在D:盘中创立一个读写文件,顺序将各节点信息保存进去,代码为: struct stu *baoc(struct stu *head)/保存文件 FILE *fp; struct stu *p=head; if(head->next=NULL)通讯录为

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

14、功!nn"); return head; 行如图: 七、释放结点退出系统用指针p扫描链表,头指针逐步后移,释放结点p,代码如下:void sf(struct stu *head) 运行如图;struct stu *p=head ; printf("释放链表:n"); while(p!=NULL) printf("释放链表成功!n"); head=head->next; free(p); p=head; 六、附录:完整原代码#include<stdio.h>#inc

15、lude<string.h>#include<stdlib.h> #include<windows.h>struct stuchar name100;/姓名int xh;/学号int grade;/年级char cel15;/ char tel50;/ char mail50;/邮件char add100;/地址char post15;/ struct stu *next;struct stu *charu(struct stu *head,struct stu *q)/插入新结点 struct stu *p;

16、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)空!*nnn"); printf("*通 elseprintf("t输入要查询学生学号:");scanf("%d&quo

17、t;,&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年级:&quot

18、;);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 :")

19、;puts(p->post); printf("t查找成功!"):printf("nnn");break;if(p->xh=a)printf(" 要查找的学生信息为:n");printf(" 姓名:");puts(p->name); printf("t年级:");printf("%dn",p->grade); printf(&

20、amp;quot;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(&am

21、p;quot;nnn");else printf("no people have found!n");struct stu *del(struct stu *head)/删除结点struct stu *p,*q;int a;/要删除学生的学号if(head->next=NULL)空!*nnn"); printf("*通 elseprintf("t输入要删除学生学号:");scanf("%d",&a);fo

22、r(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(st

23、ruct stu *head)/修改结点 输入要修改学生学号:");scanf("%d",&a);for(p=head->next;p!=NULL;p=p->next)if(p->next->xh=a)start: printf(" 输入想要修改什么?n"); printf("ttt 1:修改姓名n");printf("ttt 2:修改学号n");printf(&

24、amp;quot;ttt 3:修改年级n");printf("ttt 4: n");printf("ttt 5: n");printf("ttt 6:邮件n");printf("ttt 7:地址n");printf("ttt 8: n");printf(" 请输入你的选择:"); scanf("%d",&b);s

25、witch(b)case 1:printf("t输入新姓名:");scanf("%s",p->name);break; case 2:printf("t输入新学号:"); scanf("%d",&p->xh);break; case 3: 讯录为 printf("t输入新的班级:"); scanf("%d",&p-&

26、;gt;grade);break; printf("t输入新的 号:"); scanf("%s",p->cel);break; printf("t输入新的 号:"); scanf("%s",p->tel);break; case 4: case 5:case 6:printf("t输入新的邮箱:");scanf("%s",p->mail);

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

28、否要修改其他项? 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)空!*nnn"); printf("*通讯为录 break;el

29、se if(p->next=NULL)printf(" 姓名:");puts(p->name); printf("t学号:");printf("%dn",p->xh); printf("t年级:");printf("%dn",p->grade); printf("t :");puts(p->cel);printf

30、("t :");puts(p->tel);printf("t邮箱:");puts(p->mail);printf("t地址:");puts(p->add);printf("t :");puts(p->post);printf("输出成功!n");printf("nnn");break;elseprintf("

31、 姓名:");puts(p->name); printf("t学号:");printf("%dn",p->xh); printf("t年级:");printf("%dn",p->grade); printf("t :");puts(p->cel); printf("t :");puts(p->t

32、el);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)/保存文件FIL

33、E *fp;struct stu *p=head;if(head->next=NULL)空!*nnn"); printf("*通 else 讯录为 if(fp=fopen("D:班级通讯录.txt","w")=NULL)printf("cant open file!n");exit(0);while(p->next!=NULL)fwrite(p->next,sizeof(struct stu),1,fp);p=

34、p->next;fclose(fp);printf("保存文件成功!nn");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 s

35、tu*)malloc(sizeof(struct stu);head->next=NULL;system("color 2e");/修改dos窗口前背景色,用两个十六进制数表示 *n"); printf("n*C语言课程 printf(" *班级通讯录*nnn"); printf(" * 1:新建通讯录 *n");printf(" * 2:删除通讯录 *n");printf(" * 3:修改通讯录 *n");printf(" * 4:查询通讯录 *n");printf(" * 5:显示全部记录 *n"); 设计 printf(" * printf(" * 6:保存为文件 *n"); *n"); 7:释放链表并结束程序 prin

温馨提示

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

评论

0/150

提交评论