c语言课程设计设计报告.docx

上传人:小飞机 文档编号:3155415 上传时间:2023-03-11 格式:DOCX 页数:21 大小:43.04KB
返回 下载 相关 举报
c语言课程设计设计报告.docx_第1页
第1页 / 共21页
c语言课程设计设计报告.docx_第2页
第2页 / 共21页
c语言课程设计设计报告.docx_第3页
第3页 / 共21页
c语言课程设计设计报告.docx_第4页
第4页 / 共21页
c语言课程设计设计报告.docx_第5页
第5页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《c语言课程设计设计报告.docx》由会员分享,可在线阅读,更多相关《c语言课程设计设计报告.docx(21页珍藏版)》请在三一办公上搜索。

1、c语言课程设计设计报告C语言课程设计报告 姓名: 学号: 年 月 目录: 程序功能简介 题目分析 函数的调用关系图及主要算法 源程序及注释 测试流程 心得感想 程序一:简单数学问题 一、程序功能简介: 实现多个简单数学问题的求解。 二、题目分析 完成与菜单项对应的功能设计 1、void FindNum( ); /*用穷举法找到被咬掉的数字*/ 2、void FindRoot( ); /*求解方程ax2+bx+c=0的根*/ 3、void Detective( ); /*根据线索用穷举法找出牌照号码*/ 4、void Monkey( ); /*根据天数循环求出第一天所摘桃子数*/ 5、void

2、Diamond( ); /*调用函数Print_Diamond( )输出line行的钻石图案*/ 6、void Calculator( ); /*实现两个整数简单的加减乘除四则运算*/ 三、函数的调用关系图: menu menu_select FindNum FindRoot Detective Monkey Diamond Calculator Print_Diamond 四、源程序及注释: #include #include #include #include int menu_select; void main /*主函数*/ for(;) switch(menu_select) cas

3、e 1: FindNum; system(pause); break; case 2: FindRoot; system(pause); break; case 3: Detective; system(pause); break; case 4: Monkey; system(pause); break; case 5: Diamond; system(pause); break; case 6: Calculator; system(pause); break; case 0: printf(Goodbye!n); system(pause); exit(0); int menu_sele

4、ct /*主函数菜单*/ char c; do system(cls); printf(1.FindNumn); printf(2.FindRootn); printf(3.Detectiven); printf(4.Monkeyn); printf(5.Diamondn); printf(6.Calculatorn); printf(0.Goodbye!n); c=getchar; while(c6); return(c-0); FindNum /*找数字*/ int i; for(i=1;i=9;i+) /*穷举*/ if(30+i)*6237=(10*i+3)*3564) printf(

5、%dn,i); FindRoot /*找方程的根*/ float a10,b10,c10,disc,x1,x2,real,image; /*定义abc三个数组存放方程的系数*/ int i,k,j; for(i=0;i10;i+) /*循环输入方程的三个系数*/ printf(please input three real numbers:n); scanf(%f%f%f,&ai,&bi,&ci); printf(press 1 to continuenpress 2 to calculaten); scanf(%d,&k); if (k=2) break; /*判断是否继续输入*/ for(

6、j=0;j=i;j+) printf(The equation %d,j+1); if (fabs(aj)=1e-7) /*a=0的情况*/ printf( is not quadratic, solution is %.2fn,-cj/bj); else disc=bj*bj-4*aj*cj; if (fabs(disc)1e-7) /*有两个不等实根的情况*/ x1=(-bj+sqrt(disc)/(2*aj); x2=(-bj-sqrt(disc)/(2*aj); printf( has distinct real roots: %.2f and %.2fn,x1,x2); else /

7、*有两个虚根的情况*/ real=-bj/(2*aj); image=sqrt(-disc)/(2*aj); printf( has complex roots:n); printf(%.2f+%.2f in,real,image); printf(%.2f-%.2f in,real,image); Detective /*找牌照*/ int i,a,b,c,d;long m; for(i=32;i=1;i-) x=(x+1)*2; printf(%ldn,x); void print_diamond(int line) int i,j,k,m,n,p,q,a,b; for(i=1;i=(49

8、-line)/2;i+) /*输出(49-line)/2行的空格*/ printf(n); for(j=1;j=(line+1)/2;j+) for(m=1;m=(80-line)/2;m+) /*先输出(80-line)/2个空格*/ printf( ); for(a=1;a=(line-(2*j-1)/2;a+) /*行数j从1到中间一行输出(line-(2*j-1)/2个空格*/ printf( ); for(n=1;n=2*j-1;n+) /*中间行及上面每行输出2*j-1个*/ printf(*); printf(n); for(k=1;k=(line-1)/2;k+) /*同理输出

9、中间行下面的钻石图案*/ for(p=1;p=(80-line)/2;p+) printf( ); for(b=1;b=k;b+) printf( ); for(q=1;q=line-2*k;q+) printf(*); printf(n); Diamond /*钻石*/ int line; scanf(%d,&line); print_diamond(line); /*调用print_diamond输出钻石图案*/ Calculator /*简单计算器*/ int a4,b4,c4,i,j,k; /*定义ab两个数组存放数*/ char ch4; /*定义c存放运算符*/ FILE *fp1

10、,*fp2; fp1=fopen(expres.txt,r); /*打开expres文件*/ if(fp1=NULL) /*判断打开成功*/ printf(Can not open file expresn); exit(1); for(i=0;i=3;i+) fscanf(fp1,%d%c%d,&ai,&chi,&bi); /*循环读入四道题*/ for(j=0;j=3;j+) switch(chj) /*判断运算符*/ case +:cj=aj+bj; break; case -:cj=aj-bj; break; case *:cj=aj*bj; break; case /:cj=aj/b

11、j; break; fp2=fopen(result.txt,w); /*打开文件result*/ if(fp2=NULL) /*判断打开文件是否成功*/ printf(Can not open file expresn); exit(2); for(k=0;k=3;k+) /*循环向文件中输入结果*/ fprintf(fp2,%d%c%d=%dn,ak,chk,bk,ck); printf(succeed!n); 五、测试流程: 运行程序 屏幕显示:1.FindNum 2.FindRoot 3.Detective 4.Monkey 5.Dismond 6.Calculator 0.Goodb

12、ye! 输入:1回车 显示:9 Press any key to continue 按任意键返回菜单 输入:2回车 显示:please input three real number: 输入:0回车 1回车 2回车 显示:press 1 to continue press2 to calculate 输入:1回车 显示:please input three real number: (按照以上方法再输入三组数据:1,2,1;1,3,2;1,0,4后选择2,回车) 显示:The equation 1 is not quadratic, solution is -2.00 The equation

13、 2 is not quadratic, solution is -1.00 The equation 3 has distinct real roots: -1.00and-2.00 The eauation 4 has complex roots: -0.00+2.00 i -0.00-2.00 i Press and key to continue 按任意键返回菜单 输入:3 回车 显示:317744 Press and key to continue 按任意键返回菜单 输入:4 回车 10 回车 显示:1534 Press and key to continue 按任意键返回菜单 输入

14、:5 回车 5 回车 输出: * * * * * Press and key to continue 按任意键返回菜单 输入:6 回车 显示:succeed! Press and key to continue 按任意键返回菜单 输入:0 回车 显示:Goodbye! Press and key to continue 按任意键结束程序 程序二:学生成绩简单管理 一、 程序功能简介: 用结构体数组结构实现简单的学生管理成绩管理功能,要求具有数据输入、数据输出、数组排序、元素插入、元素删除、查询等功能。 二、 题目分析 完成与菜单项对应的功能设计 1、int Input(struct stude

15、nt stu,int n); /*从键盘输入若干条纪录,依次存放到结构体数组stud中,n为数组原有纪录数,程序运行初始纪录数为0,函数返回纪录数.*/ 2、Display(struct student stu,int n); /*显示所有记录,每10个暂停一下,n为数组元素个数*/ 3、Sort_by_Name(struct student stu,int n); /*按姓名作升序排序,要求用选择排序法*/ 4、 int Insert_a_record(struct student stu,int n); /*输入待插入的姓名和成绩,按姓名作有序插入,输出插入成功信息,返回纪录个数*/ 5、

16、int Delete_a_record(struct student stu,int n); /*输入待删除的姓名,经确认后删除该姓名的纪录,输出删除成功与否的信息.返回数组中的纪录数*/ 6、 int Query_a_recored(struct student stu,int n);/*输入待查找的姓名,查找该姓名的纪录,输出查找成功与否的信息和该学生的信息*/ 7、int Addfrom Text(struct student stud,int n); /*从文件filename添加一批纪录到数组中 ,返回添加纪录后的新的纪录数*/ 8、Write to Text(struct stud

17、ent stu,int n); /*将数组中的纪录全部写入文件records.txt*/ 三、函数调用关系图: main menu_select Input Display Sort_by_Name Delete_a_record AddfromText WritetoText Insert_a_record Delete Query_a_recorSort_by_name Query Input_one_record Insert 四、源程序及注释: #include #include #include #include typedef struct student /*定义结构体数组*/

18、char name20; float score; ; int menu_select; struct student Input_one_record /*输入一个学生的成绩记录*/ struct student stud; printf(please input the name:n); scanf(%s,&stud.name); printf(please input the score:n); scanf(%f,&stud.score); return stud; int Input(struct student stu,int n) /*输入学生成绩记录*/ for(n=0;n=39

19、;n+) stun=Input_one_record; /*调用函数Input_ont_record输入学生成绩记录*/ printf(do you want to continue:(YorN); getchar; if(toupper(getchar)=N) break; return n+1; void Display(struct student stu, int n) /*输出所有学生的成绩记录*/ int i,j; for(i=0;i3;i+) /*每屏显示十个记录然后暂停*/ system(cls); for(j=10*i;jn-1) break; printf(%s%20fn,

20、stuj.name,stuj.score); if(jn-1) break; printf(press any key to display the next ten records:n); system(pause); void Sort_by_Name(struct student stu,int n) /*排序*/ int i,j,p; struct student t; for(i=0;i=n-2;i+) /*选择排序法*/ p=i; for(j=i+1;j=n-1;j+) /*找到最小数据的下标*/ if(strcmp(stuj.name,stup.name)0) p=j; if(p

21、!=i) /*判断最小数据是否在第一个*/ t=stup;stup=stui;stui=t; printf(succeed!n); int Insert_a_record(struct student stu,int n) /*插入一个学生成绩记录*/ struct student new; struct student *s; printf(please input a name:n); scanf(%s,&new.name); printf(please input the score:n); scanf(%f,&new.score); s=&new; n=Insert(stu,n,s);

22、 /*调用函数Insert作有序插入*/ return n; int Insert(struct student stu,int n,struct student *s) /*有序插入*/ int i,j; for(i=0;iname)0) break; for(j=n-1;j=i;j-) stuj+1=stuj; stui=*s; return n+1; int Delete_a_record(struct student stu,int n) /*删除一个学生的成绩记录*/ int k; struct student name_to_delete; struct student *name

23、; printf(please input the name you want to delete:n); scanf(%s,&name_to_delete.name); name=&name_to_delete; printf(Delete %ss record(YorN):n,name_to_delete.name); getchar; if(toupper(getchar)=Y) k=Delete(stu,n,name); /*调用函数Delete查找数据,若存在做删除*/ if(k=-1) /*判断是否存在*/ printf(The record does not exist!n);

24、else n=k; return n; int Delete(struct student stu,int n,struct student *name) int i,j; for(i=0;iname)=0) break; /*找到需要删除的数据下标i*/ if(i=n+1) /*判断要删除的数据是否存在*/ return -1; /*不存在,返回提示信息*/ else /*存在,做删除*/ for(j=i;j=n;j+) stuj=stuj+1; printf(succeed!n); return n-1; void Query_a_record(struct student stu,int

25、 n) /*查找一个学生的成绩记录*/ struct student *name; struct student name_to_query; printf(please input the name you want to query:n); scanf(%s,&name_to_query.name); name=&name_to_query; if(Query(stu,n,name)=-1) /*调用函数Query判断要查找的记录是否存在*/ printf(%s does not exist!n); /*不存在输出提示信息*/ else /*存在,输出记录*/ name_to_query=

26、stuQuery(stu,n,name); printf(succeed!n%st%fn,name_to_query.name,name_to_query.score); int Query(struct student stu,int n,struct student *name) /*查找记录*/ int i; for(i=0;iname)=0) break; if(i=n-1) /*判断要查找的记录时候存在*/ return i; /*存在,返回下标i*/ else return -1; /*不存在,返回提示信息*/ int AddfromText(struct student stu,

27、int n) /*从文件中整批输入*/ int i,num; FILE *fp; /*定义文件指针*/ char filename20; printf(Input the filename:n); scanf(%s,filename); if(fp=fopen(filename,r)=NULL) printf(cannt open the file!n); system(pause); return n; fscanf(fp,%d,&num); for(i=0;inum;i+) /*循环读入文件内容*/ fscanf(fp,%s%f,&stun+i.name,&stun+i.score); n

28、+=num; fclose(fp); Sort_by_Name(stu,n); /*调用函数Sort_by_Name排序*/ return n; void WritetoText(struct student stu,int n) /*将记录写到文件*/ int i; FILE *fp; char filename20; printf(Write the records to a Text Filen); printf(Input the filename:); scanf(%s,filename); if(fp=fopen(filename,w)=NULL) printf(cannt ope

29、n the filen); system(pause); return; fprintf(fp,%dn,n+1); for(i=0;i=n-1;i+) /*循环将记录写到文件中*/ fprintf(fp,%st%fn,stui.name,stui.score); fclose(fp); printf(succeed!n); void Quit void main /*主函数*/ struct student stu40; int n=0; for(;) switch(menu_select) case 1: n=Input(stu,n); system(pause); break; Displ

30、ay(stu, n); system(pause); break; Sort_by_Name(stu,n); system(pause); case 2: case 3: break; n=Insert_a_record(stu,n); system(pause); break; n=Delete_a_record(stu,n); system(pause); break; Query_a_record(stu,n); system(pause); break; n=AddfromText(stu,n); system(pause); break; WritetoText(stu,n); sy

31、stem(pause); break; Quit; system(pause); case 4: case 5: case 6: case 7: case 8: case 0: exit(0); int menu_select /*显示主菜单*/ char c; do system(cls); printf(1.Input Recordsn); printf(2.Displayn); printf(3.Sort by Namen); printf(4.Insert a recordn); printf(5.Delete a recordn); printf(6.Queryn); printf(

32、7.AddfromTextn); printf(8.WritetoTextn); printf(0.Goodbye!n); printf(Give your choice (1-8,0):); c=getchar; while(c8); return(c-0); 五、测试流程: 运行程序 屏幕显示:1.Input Records 2.Display 3.Sort by Name 4.Insert a record 5.Delete a record 6.Query 7.AddfromText 8.WritetoText 0 .Goodbye! Give your choice (1-8,0):

33、 输入:1 回车 显示:please input the name: 输入:hhm 回车 显示:please input the score: 输入:75 回车 显示:Do you want to continue: (YorN) 输入:y 回车 屏幕显示:press any key to continue 按任意键返回主菜单 输入:2 回车 显示:hhm 75.000000 gm 95.000000 zy 95.000000 zbn 95.000000 Press any key to continue 按任意键返回主菜单 输入:3回车 显示:succeed! Press any key t

34、o continue 按任意键返回主菜单 输入:2回车 显示:gm 95.000000 hhm 75.000000 zbn 95.000000 zy 95.000000 Press any key to continue 按任意键返回主菜单 输入:4 回车 显示:please input a name: 输入:xjj回车 显示:please input the score: 输入:88回车 显示:Press any key to continue 按任意键返回主菜单 输入:2 回车 显示:gm 95.000000 hhm 75.000000 xjj 88.000000 zbn 95.00000

35、0 zy 95.000000 Press any key to continue 按任意键返回主菜单 输入:5 回车 显示:please input the name you want to delete: 输入:hhm 显示:Delete hhms record(YorN): 输入:y回车 显示:succeed! Press any key to continue 按任意键返回主菜单 输入:5 回车 显示:please input the name you want to delete: 输入:jj回车 显示:Delete jjs record(YorN): 输入:y回车 显示: The record does not exist! Press any key to continue 按

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号