问题及代码:
/*
*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:王艺霖
*完成日期:2016年3月17日
*版 本 号:v1.0
*
*问题描述:提供10道加、减、乘、除四种基本算术运算题目,每道题中的操作数是随机的,且操作数
*不超过2位数的正整数。
*输入描述:输入答案
*输出描述:输出正确或错误和正确个数、得分
*/
#include <iostream>
#include<ctime>
#include<cstdlib>
int judge();
using namespace std;
int main()
{
int i,sum=0;
for(i=0;i<10;i++)
{
cout<<"第"<<i+1<<"题"<<endl;
sum=sum+judge();
}
cout<<"共答对"<<sum<<"道题,得分:"<<sum*10;
}
int judge()
{
int a,b,c,t,result,answer;
srand(time(0));
a=rand()%10+1;
b=rand()%10+1;
c=rand()%4;
if(a<b)
{
t=a;
a=b;
b=t;
}
if(c==3)
a=(a/b)*b;
switch(c)
{
case 0:
result=a+b;
cout<<a<<"+"<<b<<"="<<endl;
break;
case 1:
result=a-b;
cout<<a<<"-"<<b<<"="<<endl;
break;
case 2:
result=a*b;
cout<<a<<"×"<<b<<"="<<endl;
break;
case 3:
result=a/b;
cout<<a<<"÷"<<b<<"="<<endl;
break;
}
cin>>answer;
if(result==answer)
cout<<"right"<<endl;
else
cout<<"wrong"<<endl;
return answer==result;
}
运行结果:
知识点总结:
运用随机函数
学习心得:
以前就想整个这玩意给我弟弟