第四周项目3①-小学生算术能力测试系统

来源:互联网 发布:sql count用法详解 编辑:程序博客网 时间:2024/05/17 08:07

/*
*Copyright (c) 2015,烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:陈腾
*完成日期:2015年3月24日
*版本号:v1.0
*
*问题描述:设计小学生的加减乘除的十道题随机产生
*输入描述:输入十个整数
*程序输出:输出结果是否正确及正确个数
*/ 
#include <iostream> 
#include<ctime> 
#include<cstdlib> 
using namespace std; 
int main() 

    int i,right=0,sum,amount=1,m; 
    int x,y; 
    for(i=0;i<10;i++) 
    { 
       x=rand()%100; 
       y=rand()%100+1; 
       if(x<y) 
       { 
           m=x; 
           x=y; 
           y=m; 
       } 
        cout<<"第"<<amount<<"题:"; 
        srand(time(0)); 
        switch(x%4) 
        { 
            case 0: 
                { 
                    cout<<x<<"+"<<y<<"="; 
                    cin>>sum; 
                    if(sum==(x+y)) 
                    { 
                        cout<<"right"<<endl; 
                        right++; 
                    } 
 
                    else cout<<"wrong"<<endl; 
                    break; 
                } 
            case 1: 
                { 
                    cout<<x<<"-"<<y<<"="; 
                    cin>>sum; 
                    if(sum==(x-y)) 
                    { 
                         cout<<"right"<<endl; 
                         right++; 
                    } 
 
                    else cout<<"wrong"<<endl; 
                    break; 
                } 
            case 2: 
            { 
                    cout<<x<<"*"<<y<<"="; 
                    cin>>sum; 
                    if(sum==(x*y)) 
                    { 
                        cout<<"right"<<endl; 
                        right++; 
                    } 
 
                    else cout<<"wrong"<<endl; 
                    break; 
                } 
            case 3: 
                { 
                    x=(y)*(rand()%10); 
                    cout<<x<<"/"<<y<<"="; 
 
                    cin>>sum; 
 
                    if(sum==(x/y)) 
                    { 
                        cout<<"right"<<endl; 
                        right++; 
                    } 
 
                    else cout<<"wrong"<<endl; 
                    break; 
                } 
        } 
        amount++; 
 
    } 
    cout<<"做对了:"<<right<<"道题,得分为:"<<right*10; 
    return 0; 
0 0
原创粉丝点击