C语言课程设计报告.docx
- 文档编号:10460678
- 上传时间:2023-02-13
- 格式:DOCX
- 页数:25
- 大小:480.96KB
C语言课程设计报告.docx
《C语言课程设计报告.docx》由会员分享,可在线阅读,更多相关《C语言课程设计报告.docx(25页珍藏版)》请在冰豆网上搜索。
C语言课程设计报告
C语言课程设计报告
班级:
电气091
学号:
200909012
姓名:
闫娟玲
指导教师:
张廷荣
评语:
年月日
1.基本题目
1.1题目
有17个人围成一圈,从0号的人开始报数,凡报到3的倍数的人离开圈子,然后再数下去。
直到最后只剩下一个人为止。
问此人原来的位置是多少号
1.2题目分析
流程图:
图1程序流程图
1.3源程序
#include
voidmain()
{
inti,k,m,n,num[50],*p;
printf("entern”:
);
scanf("%d",&n);
p=num;
for(i=0;i *(p+i)=i+1;/*以1至17为序给每个人编号*/ i=0/*i为每次循环时的计数变量*/ k=0;/*k为按1,2,3报数时的计数变量*/ m=0;/*m为退出人数*/ while(m { 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); return0; } 1.4程序的运行结果 图2程序运行结果 2.改错题目 2.1改正后程序 #include #include voidfun(char*s,int*a,*b) { while(*s) { If(*s<='A'&&*s<='Z') (*a)++; if(*s>='a'&&*s<='z') (*a)++; s++; } } main() { chars[100];intupper=0,lower=0; clrscr(); printf("Pleaseastring: ");gets(s); fun(s,&upper,&lower); printf("upper=%dlower=%d",upper,lower); }_ 2.2程序运行结果 图名? 结果图的说明,解释 3.综合题目 3.1题目 六通讯系统管理系统 一问题描述: 通过该系统实现对通讯录进行录入,显示,修改,删除,插入,排序,保存等操作的管理。 二功能要求: 1.本系统采用一个包含N个数据的结构体数组,每个数据的结构应当包括: 编号,姓名,电话号码,地址。 2.本系统显示这样的菜单: 请选择系统的功能表: g.通讯信息录入 h.通讯信息显示 i.通讯信息保存 j.通讯信息删除 k.通讯信息修改 l.通讯信息查询 (1)按编号查询 (2)按姓名查询 (3)按电话号码查询 m.退出系统 3执行一个具体的功能之后,程序将重新显示菜单。 4.将通讯信息保存到文件中。 三算法提示: 1.数据结构: 结构体类型数组 2.数据库结构: 下表构成该系统的基本数据库。 编号 姓名 电话号码 地址 Char char char char 四测试数据: 记录数20 五其它: 对该系统有兴趣的同学可以在实现上述基本功能后,完善系统的其他功能。 3.2程序的主要功能 实现基本的通讯录数据管理,如: 创建新数据文件,添加数据记录,查找数据记录,删除数据记录,显示所有的数据记录,以及数据的排序等等。 (分别使用了new_friend(),search_friend(),search1_friend(),search2_friend(),fun(),xian_friend()等函数)。 其中数据的查找,数据的删除又可以通过不同的方式如按学号或姓名等进行操作。 (文中所有英文都使用timenewRomon字体)。 主函数的模块图: 图名? 3.3各函数的功能 1)new_friend() 是将新的内容加入到通讯录中,对进行其它的函数提供条件。 2)search_friend(),search1_friend(),search2_friend() 都是用于查找的函数,且其各功能都按照不同的条件进行查找。 3)xian_friend() 是对所有存在的通讯录进行查看。 调用函数流程图: 1通讯信息录入: 图名? 2通信信息显示 3通信信息保存 4通信信息删除 5通信信息修改 6按姓名查询 7按编号查询 8按电话号码查询 3.4源程序 #include #include structfriends_list{ charbian_hao[20]; charname[20]; chartelephone[20]; chardi_zhi[20]; }; intcount=0; voidnew_friend(structfriends_listfriends[]); voidsearch2_friend(structfriends_listfriends[],char*di_zhi); voidsearch1_friend(structfriends_listfriends[],char*bian_hao); voidsearch_friend(structfriends_listfriends[],char*name); voidchange(friends(friends[i],intn); voidwritetotext(structfriends_listfriends[],intn); intdelete_friend_record(structfriends_listfriends[],intn); voidfun(); voidxian_friend(structfriends_listfriends[]); intmain(void) { charchoice; charbian_hao[20],name[20],telephone[20],di_zhi[20]; structfriends_listfriends[50]; do{ printf("g.xin_xi_lu_ru: \n"); printf("h.xin_xi_xian_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': writetotext(friends,count); break; case'j': delete_friend_record(friends,count); break; case'k': change(friends[],count); break; case'l': fun(); break; case'm': printf("xiexieshiyong\n"); break; } }while(choice! ='m'); return0; } voidnew_friend(structfriends_listfriends[]) { structfriends_listName; if(count==50){ printf("man! \n"); return; } printf("shu_ru_bian_hao: \n"); scanf("%s",Name.bian_hao); printf("shu_ru_name: \n"); scanf("%s",Name.name); printf("shu_ru_telephone: \n"); scanf("%s",Name.telephone); printf("shu_ru_di_zhi: \n"); scanf("%s",Name.di_zhi); friends[count]=Name; count++; } voidfun() { intchoice; charname[20],bian_hao[20],telephone[20]; structfriends_listfriends[50]; printf("[1]: anbian_haocha: \n"); printf("[2]: annamecha: \n"); printf("[3]: antelephonecha: \n"); printf("[0]exit: \n"); printf("enterchoice: "); scanf("%d",&choice); switch(choice){ case1: printf("shurubian_hao: "); scanf("%s",bian_hao); search1_friend(friends,bian_hao); break; case2: printf("shuruname: "); scanf("%s",name); search_friend(friends,name); break; case3: printf("shhurutelephone: "); scanf("%s",telephone); search2_friend(friends,telephone); break; case0: break; } } voidsearch_friend(structfriends_listfriends[],char*name) { intj,flag=0; if(count==0){ printf("Nofoundperson! \n"); return; } for(j=0;j if(strcmp(name,friends[j].name)==0){ flag=1; break; } if(flag){ printf("bian_hao: %s\t",friends[j].bian_hao); printf("name: %s\t",friends[j].name); printf("telephone: %s\t",friends[j].telephone); printf("di_zhi: %s\t",friends[j].di_zhi); } else printf("No! "); } voidxian_friend(structfriends_listfriends[]) { inti; if(count==0){ printf("Noprson! "); return; } for(i=0;i printf("bian_hao: %s: name: %s: telephone: %s: di_zhi: %s\n",friends[i].bian_hao,friends[i].name,friends[i].telephone,friends[i].di_zhi); } voidsearch1_friend(structfriends_listfriends[],char*bian_hao) { intj,flag=0; structfriends_listfriend[50]; if(count==0){ printf("Nofoundperson! \n"); return; } for(j=0;j if(strcmp(bian_hao,friend[j].bian_hao)==0){ flag=1; break; } if(flag){ printf("bian_hao: %s\t",friends[j].bian_hao); printf("name: %s\t",friends[j].name); printf("telephone: %s\t",friends[j].telephone); printf("di_zhi: %s\t",friends[j].di_zhi); } else printf("No! "); } voidsearch2_friend(structfriends_listfriends[],char*telephone) { intj,flag=0; structfriends_listfriend[50]; if(count==0){ printf("Nofoundperson! \n"); return; } for(j=0;j if(strcmp(telephone,friend[j].telephone)==0){ flag=1; break; } if(flag){ printf("bian_hao: %s\t",friends[j].bian_hao); printf("name: %s\t",friends[j].name); printf("telephone: %s\t",friends[j].telephone); printf("di_zhi: %s\t",friends[j].di_zhi); } else printf("No! "); } voidwritetotext(structfriends_listfriends[],intn) { structfriends_listfriends[50]; inti=0; FILE*fp; charfilename[20]; printf("\tbaocundaowenjian\n"); printf("\tshuruyaobaocundewenjianming: "); scanf("\t%s",filename); if((fp=fopen(filename,"w"))NULL); { printf("\tdabukai! \n"); system("pause"); return; } fprintf(fp,"tongxunlu\n"); fprintf(fp,"bian_haonamedian_hua_hao_madi_zhi\n"); fprintf(fp,"\n"); while(i { fprintf(fp,"%-20s\t%-20s\t%-20s\t%-20s\n",friends[i].bian_hao,friends[i].name,friends[i].dian_hua_hao_ma,friends[i].di_zhi); i++; } fprintf(fp,"\n"); fprintf(fp,"gongyou%dtiaojilu\n"); fclose(fp); printf("baocunchenggong! \n"); } intdelete_friend_record(structfriends_listfriends[],intn); { chars[20]; inti=0,j; prntf("\tshuruname: "); scanf("%s",s); while(strcmp(friends[i].name,s)! =0&&i i++; if(i==0) { printf(\ttrongxunluwu! \n"); return(n); } for(j=i; j { strcpy(friends[j].bian_hao=friends[j+1].bian_hao); strcpy(friends[j].name=friends[j+1].name); strcpy(friends[j].telephone=friends[j+1].telephone); strcpy(friends[j].di_zhi=friends[j+1].di_zhi); friends[j].bian_hao=friends[j+1].bian_hao); } printf("chenggongshanchu! \n"); return(n-1); } voidchange(structfriends_listfriends[],intn); { chars[20]; inti=0; printf("dhuruname: "); scanf("%s",s); while(strcmp(friends[i].name,s)! =0&&i i++; if(i==n) { printf("bian_hao: "); scanf("%s",friends[i].bian_hao); printf("name: "); scanf("%s",friends[i].name); printf("telephone: "); scanf("%s",friends[i].telephone); printf("di_zhi: "); scanf("%s",friends[i].di_zhi); printf("xiugaichenggong\n: ); }__ 3.5程序运行结果 1)显示通讯录主菜单界面 2.显示通讯录信息界面 3通讯录保存界面 4通讯录删除界面 5通讯录修改界面 6通讯录查询界面 (1)按姓名查询 (2)按电话号码查询 (3)按编号查询 4.结论与体会 这次的程序设计试验是对我们进入大学以来学习程序设计语言结果的一次大检验。 自己动手,自己发现和解决问题。 发现了自己的许多不足。 平时没有掌握好的知识在这次试验中彻底暴露出来,经过不断思考,不断查阅资料和上机运行,解决其中大部分问题,当然还存在一些问题没有解决。 我相信在以后的学习能够解决好他们。 但是,收获还是不小的,我不仅对C的操作有了进一步了解,还了解到了程序设计的书写风格及其注释的格式。 当我选择通讯录这个题目时,一开始想运用大量链表及指针来完成,但是在慢慢琢磨之后,觉得这个不一定要用链表,于是改变了变成思路。 当然还有不少文件的读写问题,不过还是通过不断的测试之后顺利的解决了。 另外一点要说的是这个程序用了很多的循环,因此对于循环的控制要十分小心,有时while和do-while的区别也是十分重要的。 还有一点体会就是,树上和老师教的知识是有限的,我们需要不断靠自己学习,向他人请教,了解和掌握更多的知识,这样我们才能编出更好的C程序。 总体来说,这次的C语言程序课程设计还是比较成功的,虽然最终程序还存在一些不足,但能取得这样的成果我还是比较高兴的。 最后,要感谢学校为我们提供这次课程设计机会,谢谢老师在学习中对我的指导。 参考书目 [1]何钦铭,颜晖.C语言程序设计.北京: 高教出版社,2008.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 课程设计 报告