跪求高人完成C语言程序设计课程——算术练习(高分悬赏!!)

2024-12-26 06:09:37
推荐回答(2个)
回答1:

#include
#include
#include
struct cysj
{
char name[10];
int tms;
int tm1[50],tm2[50],tm3[50],tm4[50];
float fs;
int xh[50];
int da;
int T;
int F;
}cysj[100];
//**********查看***************//
void look()
{
FILE *fp;
int i;
fp=fopen("测验信息.txt","r");
for(i=0;fread(&cysj[i],sizeof(struct cysj),1,fp)!=0;i++)
{
printf("姓名:%s\t分数%d\t答对:%d题\t答错:%d题\t共%d题\n",cysj[i].name,cysj[i].fs,cysj[i].T,cysj[i].F,cysj[i].tms);
}
fclose(fp);
}
//**********题目查看************//
void mue(int js[])
{
FILE *fp;
fp=fopen("测验信息.txt","r");
printf("题目:\n");
for(int i=0;i<=50;i++)
{
js[i];
if(i==6||i==12||i==18||i==24||i==30||i==36||i==42||i==48)
{
printf("\n");
}
if(js[i]==0)
printf("%d.%d+%d=\t",i,cysj[i].tm1[i],cysj[i].tm1[i+1]);
if(js[i]==1)
printf("%d.%d-%d=\t",i,cysj[i].tm1[i],cysj[i].tm1[i+1]);
if(js[i]==2)
printf("%d.%d*%d=\t",i,cysj[i].tm1[i],cysj[i].tm1[i+1]);
if(js[i]==3)
printf("%d.%d/%d=\t",i,cysj[i].tm1[i],cysj[i].tm1[i+1]);
}
printf("答案:\n");
for(int t=0;t<=50;t++)
{
if(t==10||t==20||t==30||t==40||t==50)
{
printf("\n");
}
if(js[t]==0)
printf("%d.%d\t",t,cysj[t].tm1[t]+cysj[t].tm1[t+1]);
if(js[t]==1)
printf("%d.%d\t",t,cysj[t].tm1[t]-cysj[t].tm1[t+1]);
if(js[t]==2)
printf("%d.%d\t",t,cysj[t].tm1[t]*cysj[t].tm1[t+1]);
if(js[t]==3)
printf("%d.%d\t",t,cysj[t].tm1[t]/cysj[t].tm1[t+1]);
}
fclose(fp);
}
//**********END****************//
int cc(int R,int t1,int t2,int da[],int T,int js[],int da1[],int da2[],int da3[])
{
//*********测验内容*************//
FILE *fp;
int i=0,t=0;
fp=fopen("测验信息.txt","at+");
{
cysj[i].tms=R;
cysj[i].tm1[t]=da[t];
cysj[i].tm2[t]=da1[t];
cysj[i].tm3[t]=da2[t];
cysj[i].tm4[t]=da3[t];
cysj[i].xh[t]=js[t];
cysj[i].T=T;
cysj[i].F=R-T;
cysj[i].fs=(100/R)*T;
fwrite(&cysj[i],sizeof(struct cysj),1,fp);
fclose(fp);
printf("输入完毕,任意键返回\n");
getchar();
}
}

//===============测验===============
int cy()//姓名,总的题数、题目、
//测验后的结果、参考答案、答对几题、错几题
{
//*********测验内容*************//
printf("测验题目数20~50内随机变化\n");
int t1,t2,R,t=1,jjcc,T=0,s,js[50];
char da[50],da1[50],da2[50],da3[50];//存放答案
R=rand()%51;
if(R<20)
{
R=20;
}
fgh:srand((unsigned)time(NULL));
t1=rand()%100;t2=rand()%100;
jjcc=rand()%4;
for(;t<=R;t++)
{
js[t]=jjcc;
if(jjcc==0){
printf("%d.%d+%d=\t",t,t1,t2);
scanf("%d",&s);
da[t]=t1;
da[t+1]=t2;
da1[t]=0;
da1[t+1]=0;
da2[t]=0;
da2[t+1]=0;
da3[t]=0;
da3[t+1]=0;
if(t1+t2==s)
T++;}

if(jjcc==1){
printf("%d.%d-%d=\t",t,t1,t2);
scanf("%d",&s);
da1[t]=t1;
da1[t+1]=t2;
da[t]=0;
da[t+1]=0;
da2[t]=0;
da2[t+1]=0;
da3[t]=0;
da3[t+1]=0;
if(t1-t2==s)
T++;}

if(jjcc==2){
printf("%d.%d*%d=\t",t,t1,t2);
scanf("%d",&s);
da2[t]=t1;
da2[t+1]=t2;
da1[t]=0;
da1[t+1]=0;
da[t]=0;
da[t+1]=0;
da3[t]=0;
da3[t+1]=0;
if(t1*t2==s)
T++;}

if(jjcc==3)
vbn:if(t1%t2==0)
{
printf("%d.%d/%d=\t",t,t1,t2);
scanf("%d",s);
da3[t]=t1;
da3[t+1]=t2;
da1[t]=0;
da1[t+1]=0;
da2[t]=0;
da2[t+1]=0;
da[t]=0;
da[t+1]=0;
if(t1/t2==s)
T++;
}else
{
t2=rand()%100;
goto vbn;
}
if(t==6||t==12||t==18||t==24||t==30||t==36||t==42||t==48)
{
printf("\n");
}
goto fgh;
}
//*********测验内容*************//
FILE *fp;
int i=0;
fp=fopen("测验信息.txt","at+");
{
printf("请输入你的名字:\n");
scanf("%s",cysj[i].name);
fwrite(&cysj[i],sizeof(struct cysj),1,fp);
fclose(fp);
look();
printf("输入完毕,任意键返回\n");
getchar();
}
}
//===============练习===============
int sum(int b,int c,float &T)//加法
{
int i;
printf("%d + %d = ",b,c);
scanf("%d",&i);
if(i==b+c)
{
printf("正确\n");
T++;
}else
{
printf("错误\n");
printf("正确答案为:%d\n",b+c);
}
}

int jian(int b,int c,float &T)//减法1
{
int i;
printf("%d - %d = ",b,c);
scanf("%d",&i);
if(i==b-c)
{
printf("正确\n");
T++;
}else
{
printf("错误\n");
printf("正确答案为:%d\n",b-c);
}
}

int cheng(int b,int c,float &T)//乘法
{
int i;
printf("%d X %d = ",b,c);
scanf("%d",&i);
if(i==b*c)
{
printf("正确\n");
T++;
}else
{
printf("错误\n");
printf("正确答案为:%d\n",b*c);
}
}

int chu(int b, int c, float &T)//除法
{
int i,s;
qwe:if(b%c==0)
{
printf("%d / %d = \n",b,c);
scanf("%d",&i);
if(b/c==i)
{
printf("正确\n");
T++;
}else
{
s=b/c;
printf("错误\n正确答案为:%d\n",s);
}
}
if(b%c!=0)//判断是否是偶数
{
c=rand()%100;
goto qwe;
}
}
//===============程序入口===============
int main(int argc, char *argv[])
{
srand((unsigned)time(NULL));
int b,c,d,i=0,w1,w2,oh,e=100;
float T,a,s=0;
zxc:printf("请选择你要干什么?\n1.练习\n2.测验\n3.设置\n4.查看测验成绩\n5.按0退出\n");
scanf("%d",&oh);
switch(oh)
{
case 1:
printf("输入需要测试的题目数!\n");
scanf("%f",&a);
asd:
b=rand()%e;c=rand()%e;
d=rand()%4;
for(;i {
i++;
srand((unsigned)time(NULL));
if(d==0)
sum(b,c,T);
if(d==1)
jian(b,c,T);
if(d==2)
cheng(b,c,T);
if(d==3)
chu(b,c,T);
goto asd;
}
s=(T/a)*100;
printf("正确率:百分之%d\n",(int)s);
break;
case 2:
cy();
break;
case 3:
printf("请设置位数:个位输入10\t十位输入100\t百位输入1000其他一次类推\n");
scanf("%d",&e);
goto zxc;
break;
case 4:
break;
}
}
只能写到这里了再改一下就好了~

回答2:

获取随机数的方式
#include
#include
/*获取区间[a,b]中的10个随机值(aint a[10];
srand((unsigned)time(NULL));
int i=0;
for(i=0;i<10;i++)
a[i]=rand()%(int)(b-a+1)+a;

写入文件的方法
FILE *fp;
fp=fopen("test.txt","a"); /*文件名和打开方式*/
fprintf(fp,"格式化字符串",变量); /*后2个参数和printf一样*/
fclose(fp);