C++编写程序实现小学生数学测验功能 5
二、功能要求:1、电脑随机出10道题,每题10分,程序结束时显示学生得分;2、确保算式没有超出1~2年级的水平,只允许进行50以内的加减法,不允许两数之和/差超出0~50...
二、功能要求: 1、电脑随机出10道题,每题10分,程序结束时显示学生得分; 2、确保算式没有超出1~2年级的水平,只允许进行50以内的加减法,不允许两数之和/差超出0~50的范围,负数更是不允许的;3、每道题学生有三次机会输入答案,当学生输入错误答案时,提醒学生重新输入,如果三次机会结束则输出正确答案; 4、对于每道题,学生第一次输入正确答案得10分,第二次输入正确答案得7分,第三次输入正确答案得5分,否则不得分; 5、总成绩90以上显示“SMART”,80-90显示“GOOD”,70-80显示“OK”,60-70显示“PASS”,60以下“TRY AGAIN”。的源代码
展开
2个回答
推荐于2017-09-24
展开全部
参考实例源码如下:
//#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 <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;
}
展开全部
按照你的要求,我已经完成了这个程序,我测试过了,应该没什么问题。不过这只能在C++集成开发环境中运行,如果你是一位小学教师的话,建议做一个带图形界面的测试程序。
//2015/3/12 by LDSD
#include<iostream.h>;
#include<stdlib.h>
#include "windows.h"
struct node
{
int num1;
char ope;
int num2;
int res;
node *next;
};
void generator(node *head)
//用来随机产生10道计算题,并通过链表保存数据
{
int c;
int count=0;
srand((unsigned)GetCurrentTime());
while(count!=10)
{
int a=rand()%48+1; //产生随机数
int b=rand()%48+1;
node *data=new node; //申请存储节点
int i=rand()%2;
if(i==0&&b>a)
{
data->num1=b;data->ope='-';data->num2=a;data->res=b-a;
}
else if(i==0&&a>b)
{
data->num1=a;data->ope='-';data->num2=b;data->res=a-b;
}
else if(i==1&&a<b)
{
data->num1=a;data->ope='+';data->num2=b-a;data->res=b;
}
else if(i==1&&a>b)
{
data->num1=b;data->ope='+';data->num2=a-b;data->res=a;
}
else if(a==b)
continue;
data->next=head->next;
head->next=data;
count++;
}
}
void test(node *head)
//测试程序
{
int count,que_num=1;
int sum=0;
int result;
node *data=head->next;
while(data!=NULL)
{
count=3;
cout<<"请计算第"<<que_num++<<"道题目: "<<data->num1<<data->ope<<data->num2<<endl;
cin>>result;
while(result!=data->res&&count!=1)
{
count--;
cout<<"请重新计算,你还有"<<count<<"次机会。"<<endl;
cin>>result;
}
if(count==3)
sum=sum+10;
else if(count==2)
sum=sum+7;
else if(count==1&&result==data->res)
sum=sum+5;
else if(count==1&&result!=data->res)
cout<<"本题的正确答案是:"<<data->num1<<data->ope<<data->num2<<"="<<data->res<<endl;
data=data->next;
}
cout<<"本次测试你的总分是"<<sum<<endl;
cout<<"—————————"<<endl;
if(sum>=90)
cout<<"SMART!"<<endl;
else if(sum>=80)
cout<<"GOOD!"<<endl;
else if(sum>=70)
cout<<"OK!"<<endl;
else if(sum>=60)
cout<<"PASS!"<<endl;
else
cout<<"TRY AGAIN!"<<endl;
cout<<"—————————"<<endl;
}
void main()
{
node *head=new node;
head->next=NULL;
generator(head);
test(head);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询