C语言课程设计报告_第1页
C语言课程设计报告_第2页
C语言课程设计报告_第3页
C语言课程设计报告_第4页
C语言课程设计报告_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

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

文档简介

1、c语言课程设计报告班 级: 电气091 学 号: 200909012姓 名: 闫娟玲 指导教师: 张廷荣 评语: 年 月 日1.基本题目1.1 题目有17个人围成一圈,从0号的人开始报数,凡报到3的倍数的人离开圈子,然后再数下去。直到最后只剩下一个人为止。问此人原来的位置是多少号1.2 题目分析流程图:图1 程序流程图1.3 源程序#include void main() int i,k,m,n,num50,*p; printf(enter n”:); scanf(%d,&n); p=num; for(i=0;in;i+) *(p+i)=i+1; /*以1至17为序给每个人编号*/ i=0 /

2、*i为每次循环时的计数变量*/ k=0; /*k为按1,2,3报数时的计数变量*/ m=0; /*m为退出人数*/ while(mn-1) /*当循环体人数比n-1少时(即未退出人数大于1时)执行循环体*/ if(*(p+i)!=0) k+; if(k=3) /*对退出的人的编号置0*/ *(p+i)=0; k=0; m+; i+; if(i=n) /*报数到尾后,i恢复0*/ i=0; while(*p=0) p+; printf(n,*p); return 0;1.4 程序的运行结果图2 程序运行结果2.改错题目2.1 改正后程序 #include #include void fun(ch

3、ar *s,int *a,*b) while(*s) if(*s=a&*s=a&*s=z) (*a)+; s+; main() char s100;int upper=0,lower=0; clrscr(); printf(please a string:);gets(s); fun(s,&upper,&lower); printf(upper=%d lower=%d,upper,lower); 2.2 程序运行结果图名?结果图的说明,解释3.综合题目3.1 题目六 通讯系统管理系统一 问题描述:通过该系统实现对通讯录进行录入,显示,修改,删除,插入,排序,保存等操作的管理。二 功能要求:1.

4、本系统采用一个包含n个数据的结构体数组,每个数据的结构应当包括:编号,姓名,电话号码,地址。2.本系统显示这样的菜单:请选择系统的功能表: g.通讯信息录入 h.通讯信息显示 i通讯信息保存 j.通讯信息删除 k通讯信息修改 l通讯信息查询 (1)按编号查询 (2)按姓名查询 (3)按电话号码查询 m.退出系统3 执行一个具体的功能之后,程序将重新显示菜单。4.将通讯信息保存到文件中。三 算法提示: 1.数据结构:结构体类型数组 2.数据库结构:下表构成该系统的基本数据库。编号姓名电话号码地址charcharcharchar四 测试数据: 记录数20五 其它:对该系统有兴趣的同学可以在实现上述

5、基本功能后,完善系统的其他功能。3.2 程序的主要功能 实现基本的通讯录数据管理,如:创建新数据文件,添加数据记录,查找数据记录,删除数据记录,显示所有的数据记录,以及数据的排序等等。(分别使用了new_friend(),search_friend(),search1_friend(),search2_friend(),fun(),xian_friend()等函数)。其中数据的查找,数据的删除又可以通过不同的方式如按学号或姓名等进行操作。(文中所有英文都使用time new romon字体)。主函数的模块图:图名?3.3 各函数的功能 1)new_friend()是将新的内容加入到通讯录中 ,

6、对进行其它的函数提供条件。 2)search_friend(),search1_friend(),search2_friend()都是用于查找的函数,且其各功能都按照不同的条件进行查找。 3)xian_friend()是对所有存在的通讯录进行查看。 调用函数流程图: 1 通讯信息录入: 图名?2 通信信息显示 3 通信信息保存4 通信信息删除 5 通信信息修改 6 按姓名查询 7 按编号查询8 按电话号码查询3.4 源程序#include#includestruct friends_listchar bian_hao20;char name20;char telephone20;char di

7、_zhi20;int count=0;void new_friend(struct friends_list friends);void search2_friend(struct friends_list friends,char *di_zhi);void search1_friend(struct friends_list friends,char *bian_hao);void search_friend(struct friends_list friends,char *name);void change(friends(friendsi,int n);void writeto te

8、xt(struct friends_list friends,int n);int delete_friend_record(struct friends_list friends,int n);void fun();void xian_friend(struct friends_list friends);int main(void)char choice;char bian_hao20,name20,telephone20,di_zhi20;struct friends_list friends50;doprintf(g.xin_xi_lu_ru:n);printf(h.xin_xi_xi

9、an_shi:n);printf(i.xin_xi_bao_cun:n);printf(j.xin_xi_shan_chu:n);printf(k.xin_xi_xiu_gai:n);printf(l.xin_xi_cha_xun:n);printf(m.tui_chu_xi_tonng:n);printf(xuan_ze_gong_neng:n);scanf(%c,&choice);switch(choice)case g:new_friend(friends);break;case h:xian_friend(friends);break;case i:writeto text(frien

10、ds,count);break;case j:delete_friend_record(friends,count);break;case k:change(friends,count);break;case l:fun ();break;case m:printf(xie xie shi yongn);break;while(choice!=m);return 0;void new_friend(struct friends_list friends)struct friends_list name;if(count=50)printf(man!n);return;printf(shu_ru

11、_bian_hao:n);scanf(%s,name.bian_hao);printf(shu_ru_name:n);scanf(%s,n);printf(shu_ru_telephone:n);scanf(%s,name.telephone);printf(shu_ru_di_zhi:n);scanf(%s,name.di_zhi);friendscount=name;count+;void fun()int choice;char name20,bian_hao20,telephone20;struct friends_list friends50;printf(1:an

12、bian_hao cha:n);printf(2:an name cha:n);printf(3:an telephone cha:n);printf(0 exit:n);printf(enter choice:);scanf(%d,&choice);switch(choice)case 1:printf(shu ru bian_hao:);scanf(%s,bian_hao);search1_friend(friends,bian_hao);break;case 2:printf(shu ru name:);scanf(%s,name);search_friend(friends,name)

13、;break;case 3:printf(shhu ru telephone:);scanf(%s,telephone);search2_friend(friends,telephone);break;case 0:break;void search_friend(struct friends_list friends,char *name)int j,flag=0;if(count=0)printf(no found person!n);return;for(j=0;jcount;j+)if(strcmp(name,)=0)flag=1;break;if(flag)

14、printf(bian_hao:%st,friendsj.bian_hao);printf(name:%st,);printf(telephone:%st,friendsj.telephone);printf(di_zhi:%st,friendsj.di_zhi);elseprintf(no!);void xian_friend(struct friends_list friends)int i;if(count=0)printf(no prson!);return;for(i=0;icount;i+)printf(bian_hao:%s:name:%s:teleph

15、one:%s:di_zhi:%sn,friendsi.bian_hao,,friendsi.telephone,friendsi.di_zhi);void search1_friend(struct friends_list friends,char *bian_hao)int j,flag=0;struct friends_list friend50;if(count=0)printf(no found person!n);return;for(j=0;jcount;j+)if(strcmp(bian_hao,friendj.bian_hao)=0)flag=1;b

16、reak;if(flag)printf(bian_hao:%st,friendsj.bian_hao);printf(name:%st,);printf(telephone:%st,friendsj.telephone);printf(di_zhi:%st,friendsj.di_zhi);elseprintf(no!);void search2_friend(struct friends_list friends,char *telephone)int j,flag=0;struct friends_list friend50;if(count=0)待添加的隐藏文字

17、内容3printf(no found person!n);return;for(j=0;jcount;j+)if(strcmp(telephone,friendj.telephone)=0)flag=1;break;if(flag)printf(bian_hao:%st,friendsj.bian_hao);printf(name:%st,);printf(telephone:%st,friendsj.telephone);printf(di_zhi:%st,friendsj.di_zhi);elseprintf(no!);void writeto text(stru

18、ct friends_list friends,int n)struct friends_list friends50;int i=0;file *fp;char filename20;printf(tbao cun dao wen jiann);printf(tshu ru yao bao cun de wen jian ming:);scanf(t%s,filename);if(fp=fopen(filename,w)null);printf(tda bu kai!n);system(pause);return;fprintf(fp,tong xun lun);fprintf(fp,bia

19、n_hao name dian_hua_hao_ma di_zhin);fprintf(fp,n);while(in)fprintf(fp,%-20st%-20st%-20st%-20sn,friendsi.bian_hao,,friendsi.dian_hua_hao_ma,friendsi.di_zhi);i+;fprintf(fp,n);fprintf(fp,gong you %d tiao ji lun);fclose(fp);printf(bao cun cheng gong!n);int delete_friend_record(struct friend

20、s_list friends,int n);char s20;int i=0,j;prntf(tshu ru name:);scanf(%s,s);while(strcmp(,s)!=0&in)i+;if(i=0)printf(ttrong xun lu wu!n);return(n);for(j=i;jn;j+)strcpy(friendsj.bian_hao=friendsj+1.bian_hao);strcpy(=friendsj+1.name);strcpy(friendsj.telephone=friendsj+1.telephon

21、e);strcpy(friendsj.di_zhi=friendsj+1.di_zhi);friendsj.bian_hao=friendsj+1.bian_hao);printf(cheng gong shan chu!n);return(n-1);void change(struct friends_list friends,int n);char s20;int i=0;printf(dhu ru name:);scanf(%s,s);while(strcmp(,s)!=0&in)i+;if(i=n)printf(bian_hao:);scanf(%s,friendsi.bian_hao);printf(name:);scanf(%s,);printf(telephone:);scanf(%s,friendsi.telephone);printf(di_zh

温馨提示

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

评论

0/150

提交评论