#include<stdlibh>
#include<stdioh>
#include<conioh>
void main()
{
int a[10],b[10],d[10],c[10],num=0,result,add=0;
float val;
char fa[5]={'+','-','','/'};
srand((unsigned)time(NULL));
/ 出10道题 /
while(1)
{
d[num]=abs(rand())%4;
while(1)
{
c[num]=-1;
a[num]=abs(rand())%100;
b[num]=abs(rand())%100;
if(d[num]==0) c[num]=a[num]+b[num];
else if(d[num]==1) c[num]=a[num]-b[num];
else if(d[num]==2) c[num]=a[num]b[num];
else if(d[num]==3)
{
if(b[num]>0)val=10a[num]/b[num];
}
if(d[num]<=2)
{
if(c[num]>=0 && c[num]<=100) break;
}
else
{
if(a[num]==int(val)b[num])
{c[num]=val; break;}
}
}
num++;
if(num==10) break;
}
/ 回答 /
num=0;
while(1)
{
printf("%d %c %d= ",a[num],fa[d[num]],b[num]);
scanf("%d",&result);
if(result==c[num])
{
printf("回答正确!\n");
add+=10;
}
else
printf("错误,正确答案: %d\n",c[num]);
num++;
if(num==10) break;
}
printf("\n得分:%d\n",add);
getch();
}
你自己修改修改:
#include <stdioh>
#include <ctypeh>
#include <timeh>
#include <stdlibh>
#include <windowsh>
#define IDNO_LENGTH 6
#define CALC_KIND 4
#define CALC_NUM 10
bool checkNo(char idNo[]);
char getSignal();
int getResult(int,int,char);
void takeTest();
//main函数
void main()
{
printf("Please input your four digit ID no(begin with two letters):");
char idNo[IDNO_LENGTH];
do
{
scanf("%s",&idNo);
fflush(stdin);
} while(checkNo(idNo)==false);
printf("1Start a test\t2Exitb\n");
int choose;
do
{
printf("选择:");
scanf("%d",&choose);
fflush(stdin);
} while(choose!=1 && choose!=2);
if(choose==1)
takeTest();
else
exit(0);
}
//获取随机运算符
char getSignal()
{
char signal[CALC_KIND]={'+','-','','/'};
srand((unsigned)time(NULL));
return signal[rand()%4];
}
//获取随机数
int random(double start, double end)
{
return (int)(start+(end-start)rand()/(RAND_MAX+ 10));
}
//运算
int getResult(int num1,int num2,char signal)
{
int res;
switch(signal)
{
case '+':
res=num1+num2;break;
case '-':
res=num1-num2;break;
case '':
res=num1num2;break;
case '/':
res=num1/num2;break;
default:
res=0;
printf("运算符不符合规则\n");
}
return res;
}
//列出10道题
void takeTest()
{
clock_t startTime;
startTime=clock();
int index;
int giveRes;
int num1;
int num2;
char signal;
for(index=0;index<CALC_NUM;index++)
{
srand((unsigned)time(NULL));
signal=getSignal();
num1=random(0,100);
num2=random(1,100);
printf("%d%c%d=",num1,signal,num2);
scanf("%d",&giveRes);
fflush(stdin);
if(getResult(num1,num2,signal)==giveRes)
{
printf("correct\n");
}
else
{
printf("wrong\n");
}
}
printf("解10道题用了%lf秒\n",(double)(clock()- startTime)/CLOCKS_PER_SEC);
}
//检测idNo是否合规则,合规则返回true
bool checkNo(char idNo[])
{
int index;
bool flag;
flag=true;
for(index=0;index<IDNO_LENGTH;index++)
{
if(index<2)
{
if(!isalpha(idNo[index]))
{
flag=false;
printf("ID no 不符合规则,重新输入:");
break;
}
}
else
{
if(!isdigit(idNo[index]))
{
flag=false;
printf("ID no 不符合规则,重新输入:");
break;
}
}
}
return flag;
}
#include <stdioh>
#include <stdlibh>
#include <timeh>
void main()
{
int a,b,op,term;
int x,i=0;
int counter = 0; /初始答对题数为0/
char opchar;
srand(time(NULL)); /为函数rand()设置随机数种子/
a= rand()%10+1;
b= rand()%10+1;
for(i= 0;i < 10;i++)
{
a= rand()%10+1;
b= rand()%10+1;
op=rand()%4+1;
switch(op) /根据运算符号不同进行不同的运算/
{
case1:opchar='+';
term=a+ b;
break;
case2: opchar='-';
term=a - b;
break;
case3: opchar='';
term=a
b;
break;
case
4:
opchar='/';
term=a/b;
break;
default:
printf("Wrong
operator!");
}
printf("%d%c%d=",a,opchar,b);
scanf("%d",&x);
if(x==term)
{
printf("Right!\n");
counter++;
}
else
printf("Wrong!\n");
}
printf("Total
score is %d\n",counter10);
printf("Rate
of correctness is %d%%\n",counter10);
}
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int randint()
{
int t = random();
return t % 70 + 10;
}
int run(int a, int b, int c, int t)
{
switch(t)
{
case 0:
return a - b - c;
case 1:
return a - b + c;
case 2:
return a + b - c;
default:
return a + b + c;
}
}
void output(int a, int b, int c, int t)
{
switch(t)
{
case 0:
cout<<a<<" - "<<b<<" - "<<c<<" = ";
return;
case 1:
cout<<a<<" - "<<b<<" + "<<c<<" = ";
return;
case 2:
cout<<a<<" + "<<b<<" - "<<c<<" = ";
return;
default:
cout<<a<<" + "<<b<<" + "<<c<<" = ";
}
}
int main()
{
srand(time(0));
while(1)
{
int a = randint(), b = randint(), c = randint();
int t = randint() % 4;
int r = run(a,b,c,t);
if (r >= 1 && r <= 200)
{
output(a,b,c,t);
int in;
cin>>in;
if (in == r)
{
cout<<"^_^答对了"<<endl;
}
else
{
cout<<"T_T打错了,答案是"<<r<<endl;
}
}
}
return 0;
}
以上就是关于设计小学生四则运算测试程序,要求随机产生10题四则运算题,答完后给出得分。用C语言做,有人会吗很急全部的内容,包括:设计小学生四则运算测试程序,要求随机产生10题四则运算题,答完后给出得分。用C语言做,有人会吗很急、求大神用C语言设计一个程序帮助小学生练习数学。(具体要求见问题补充)、C程序课程设计题目:小学生计算机辅助教学系统。 详情如下,望各位高手帮忙给出源代码!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)