您好,欢迎来到微智科技网。
搜索
您的当前位置:首页c程序课设

c程序课设

来源:微智科技网
 目录

一、 需求分析…………………………………………………………2 二、 概要设计…………………………………………………………3 三、 详细设计…………………………………………………………6 四、 调试分析…………………………………………………………7 五、 用户手册…………………………………………………………8 六、 测试结果…………………………………………………………13 七、 附录………………………………………………………………17

1

一、需求分析

设计内容:设计一个小学生测试系统,面向小学1~2年级学生,随即选择两个整数和加减法形成算式,要求学生解答。 任务和要求

(1)电脑每次测试出10道题,每题10分,结束后能够显示分数。 (2)只进行50以内的加减法。确保不能出现负数。

(3) 每题有三次输入的机会,当学生输入错误答案,给出错误提示提醒学生重新输入,三次机会结束给出正确答案。

(4)对于每道题,学生第一次正确输入得10分,第二次得7分,第三次得5分,否则不得分。

(5)总成绩90分以上显示SMART,80~90显示GOOD,70~80显示OK,60~70显示PASS,60一下显示TRY AGAIN。

(要求:1.源文件采用多文件的工程结构2.数据存储采用文件形式3.标准的C输入输出4.功能完善,适当的注释)

2

二、概要设计

1.定义一个结构体数组来存放学生的学号、姓名、成绩 struct student {

char name;

int num; int score; }stu[SIZE];

2.本程序用到的标准函数名称、自定义函数名称int start_test(); save();

start_output( stu[SIZE]);

3

三、 详细设计

main() {

int num,i,j;

char b[10]={'z','c','w','q','v','k','l','p','d','r'}; /*存储学生姓名*/ int a[10]={0,1,2,3,4,5,6,7,8,9}; FILE *fp;

fp=fopen(\"c:\\\\stu_list.txt\ /*打开文件*/ for(i=0;i<3;i++) /*控制学生测试的人数*/ { printf(\"Input num:\\n\"); /*输入学生学号*/ scanf(\"%d\ for(j=0;j<10;j++) if(a[j]==num) break; /*判断输入的学号是否和已知的学号相符*/ if(j>=10) printf(\"The num is not in!\\n\"); else { stu[i].name=b[j]; /*把学生姓名重新赋给结构体*/ stu[i].num=num; /*把学生学号重新赋给结构体*/ stu[i].score=start_test(); /*把学生的成绩转到结构体里*/ } }

save(); /*文件保存的函数*/

start_output( stu[SIZE]); /*输出学生信息的函数*/ fclose(fp); }

int start_test(/*struct student stu[SIZE]*/) /*开始测试*/ {

int i,j,a,b,c,n,score=0;

srand(time(NULL)); /*产生随机数*/

for(i=0;i<3;i++) /*控制测试的题目数量*/ { a=rand()%51; /*随即输出0-50之间的数*/ b=rand()%51; n=rand()%2; if(n==0 && (a+b)<=50) /*判断两数之和是否小于50*/ { printf(\"%d: %d+%d= \ j=0; do {

4

scanf(\"%d\ /*输入答案*/ if(c==(a+b)) { if(j==0) score+=10; else if(j==1) score+=7; else score+=5; } else if(j<2) printf(\"The answer is wrong,please try again!\\n\"); j++; }while(c!=(a+b) && j<3); } else if(n==1) { if(a!=b) { a=(a>b)?a:b; b=(aprintf(\"The final score=%d\\n\ /*输出最后得分*/ return score;

}

save()

{ int i=0;

5

FILE *fp;

if((fp=fopen(\"c:\\\\stu_list.txt\ /*打开文件*/ { printf(\"cannot open this file\\n\"); return; }

for(i=0;i<3;i++)

{ fprintf(fp,\"%c,%d,%d\ } fclose(fp); }

int start_output(struct student stu[SIZE]) /*开始输出学生信息*/ {

FILE *fp; int i=0;

if((fp=fopen(\"c:\\\\stu_list.txt\

{ printf(\"cannot open this file\\n\"); exit(0); }

printf(\"The data stored in file is:\\n\");

printf(\"Input all %d student's data.\\n\ printf(\"|num | name | score |\\n\"); printf(\"|-------|-------|-------|\\n\");

while(fscanf(fp,\"%c,%d,%d\ { printf(\"%d,%c,%d\\n\ i++; } fclose(fp); }

6

四、 调试分析

按照老师的要求,这个程序本该是两个星期就要完成的,而我做这个

程序时间花的更多。在做这个程序的时候碰到过很多的问题,我也和同学讨论过,向老师请教过。 在编写这个程序的时候碰到过许多问题,但另我最感到最难的是在文

件存储是碰到的困难。刚开始是文件打不开,之后是打开了是乱码,在改了下输出形式后问题才得以解决。

在输出算式的时候没有顺序,画面不太好看,也是老师帮忙改了下才

有了较流畅的画面。

经过这次课设,我懂得了分布运行程序的重要性,同时自己学会了。

7

五、 用户手册

1. 首先输入学生学号

2. 判断输入的学号是否与已知的学号相符 3. 开始测试 4. 输出结果

8

六、 测试数据

1.当答案全正确,测试结束时的数据

9

1中的文件存储的数据

10

2.当学生输入不相符的学号时的数据

11

3.当学生输入错误的答案时的数据

12

3中的文件中的数据

13

七、 附录

#include #include #include #define SIZE 3 struct student {

char name; int num; int score; }stu[SIZE]; void main() {

int num,i,j;

char b[10]={'z','c','w','q','v','k','l','p','d','r'}; int a[10]={0,1,2,3,4,5,6,7,8,9}; FILE *fp;

fp=fopen(\"c:\\\\stu_list.txt\ for(i=0;i<3;i++) { printf(\"Input num:\\n\"); scanf(\"%d\ for(j=0;j<10;j++)

if(a[j]==num) break; if(j>=10) printf(\"The num is not in!\\n\"); else { stu[i].name=b[j]; stu[i].num=num; stu[i].score=start_test(); } }

save();

start_output( stu[SIZE]); fclose(fp); }

int start_test(/*struct student stu[SIZE]*/) {

int i,j,a,b,c,n,score=0;

14

srand(time(NULL)); for(i=0;i<3;i++) { a=rand()%51; b=rand()%51; n=rand()%2; if(n==0 && (a+b)<=50) { printf(\"%d: %d+%d= \ j=0; do { scanf(\"%d\ if(c==(a+b)) { if(j==0) score+=10; else if(j==1) score+=7; else score+=5; } else if(j<2) printf(\"The answer is wrong,please try again!\\n\"); j++; }while(c!=(a+b) && j<3); } else if(n==1) { if(a!=b) { a=(a>b)?a:b; b=(a} else i--; }

printf(\"The final score=%d\\n\ return score; }

save()

{ int i=0; FILE *fp;

if((fp=fopen(\"c:\\\\stu_list.txt\

{ printf(\"cannot open this file\\n\"); return; }

for(i=0;i<3;i++)

{ fprintf(fp,\"%4c,%4d,%4d\ } fclose(fp); }

int start_output(struct student stu[SIZE]) {

FILE *fp; int i=0;

if((fp=fopen(\"c:\\\\stu_list.txt\ { printf(\"cannot open this file\\n\"); exit(0); }

printf(\"The data stored in file is:\\n\");

printf(\"Input all %d student's data.\\n\ printf(\"|num | name | score |\\n\"); printf(\"|-------|-------|-------|\\n\");

while(fscanf(fp,\"%4c,%4d,%4d\ { printf(\"%4d,%4c,%4d\\n\ i++;

16

printf(\"wrong,try again!\\n\"); j++;

}while(c!=(a-b) && j<3);

} fclose(fp); }

17

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务