求c++编写小学生数学测试软件的源代码
1.可选择题型为(+,-,*,/);
2.可选择每次答题的个数;
3.随机生成两个数进行运算;
4.每次在输入答案后应判断对错,若答案错误,应给出正确答案;
5.最后给出做对题目的总个数。
注意:产生随机数的方法——使用随机数函数 展开
//#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int i,j,k,l=0,n;
cout<<"************************************小学数学测试*******************************"<<endl;
cout<<"请选择想测试的题型:1.+ 2.- 3.* 4./:";
cin>>i;
if(i==1)
{
cout<<"请输入测试题的个数:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100;
int x2=rand()%100;
cout<<x1<<"+"<<x2<<"=:";
cin>>k;
if(k==x1+x2){
cout<<"回答正确!"<<endl;
l++;
}
else
cout<<"回答错误!正确答案为:"<<x1+x2<<endl;
}
}
else if(i==2)
{
cout<<"请输入测试题的个数:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100;
int x2=x1+rand()%50;
cout<<x2<<"-"<<x1<<"=:";
cin>>k;
if(k==x2-x1){
cout<<"回答正确!"<<endl;
l++;
}
else
cout<<"回答错误!正确答案为:"<<x2-x1<<endl;
}
}
else if(i==3)
{
cout<<"请输入测试题的个数:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100;
int x2=rand()%100;
cout<<x1<<"*"<<x2<<"=:";
cin>>k;
if(k==x1*x2){
cout<<"回答正确!"<<endl;
l++;
}
else
cout<<"回答错误!正确答案为:"<<x1*x2<<endl;
}
}
else if(i==4)
{
cout<<"请输入测试题的个数:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100+1;
int x2=x1*(rand()%10);
cout<<x2<<"/"<<x1<<"=:";
cin>>k;
if(k==x2/x1){
cout<<"回答正确!"<<endl;
l++;
}
else
cout<<"回答错误!正确答案为:"<<x2/x1<<endl;
}
}
cout<<"这次测试你作对的题目的个数为"<<l<<"个"<<endl;
cout<<"是否继续测试:0.退出 1.继续:";
cin>>n;
if(n==1){
return main();}
// system("PAUSE");
return 0;
}
测试过几次应该没错误的!
#include<stdio.h>
#include<time.h>
main()
{
int cn=0,i=0, s,n,j;
long int x1,x2,x;
printf("请输入你想答题的次数");
scanf("%d",&n);
while(i++<n)
{srand((unsigned)time(NULL));
x1=rand()%10; x2=rand()%10;
printf("第一个数字是%d",x1);printf("第二个数字是%d\n",x2);
printf( "1: + , 2: -, 3: * , 4:/ ");
printf("请输入你的提型\n");
scanf("%d",&j);
switch(j){
case 1:x=x1+x2;break;
case 2:x=x1-x2;break;
case 3:x=x1*x2;break;
case 4:x=x1/x2;break;
default:printf("输入错误\n");continue;}
printf("输入你的答案\n");
scanf("%d",&s);
if(s==x)
{printf("你做对了");cn++;} //printf("%d",cn);}
else
printf("回答错误!正确答案是%d",x);
}printf("你做对的这些题目,恭喜你啊对了=%d\n",cn);
//printf("%d",cn);
}
编程序的人啊!
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
char kind;
int size;
cin >> kind >> size;
int counter = 0;
srand( time( 0 ) );
while( size-- )
{
int fir = rand();
int sec = rand();
cout << fir << kind << sec << " ";
froat result;
cin >> result;
froat tr;
if( "+" == kind )
tr = fir + sec;
else if( "-" == kind )
tr = fir - sec;
else if( "*" == kind )
tr = fir * sec;
else
tr = fir / sec;
if( tr == result )
{
cout << "Yes!" << endl;
counter++;
}
else
cout << "No! Answer is " << tr << endl;
}
cout << "Your grade is " << counter << " of " << size << endl;
return 0;
}
写的也不算麻烦,不过希望有分加啦^_^