码迷,mamicode.com
首页 > 其他好文 > 详细

测试四则运算

时间:2015-03-17 23:27:09      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

我这次测试的为取值范围

分别取都为正数 负数 正负数都有 已经到10000取值是是否正确

  1 #include<iostream.h>
  2 #include<stdlib.h>
  3 #include<time.h>
  4 int main()
  5 {
  6     srand(time(NULL));
  7     int a, b, c,d,f,g,h,p,q,r,s;
  8     cout<<"请输入计算的数值范围(min):";
  9         cin>>p;
 10     cout<<"请输入计算的数值范围(max):";
 11         cin>>q;
 12     cout<<"请输入题目数量i= ";
 13         cin>>d;
 14     cout<<"是否需要乘除法1/0 :";
 15         cin>>f;
 16     cout<<"是否需要加入括号1/0:";
 17         cin>>g;
 18         if (f==1)
 19     {
 20         if(g==1)
 21             for(int i = 1; i <= d; i++)
 22             {
 23              a = rand() % (q-p+1)+p;
 24              b = rand() % (q-p+1)+p;
 25              h = rand() % (q-p+1)+p;
 26              c = rand() % 6;
 27                 switch (c)
 28              {
 29             case 0:
 30                 cout<< a << "+" << b << "=" << endl;
 31                 break;
 32             case 1:
 33                 cout<< a << "-" << b << "=" << endl;
 34                 break;
 35             case 2:
 36                 cout<< a << "*" << b << "=" << endl;
 37                 break;
 38             case 3:
 39                 cout<< a << "/" << b << "=" << endl;
 40                 break;
 41             case 4:
 42                 cout<<"("<<a<<"+"<<b<<")"<<"-"<<h<<"="<<endl;
 43                 break;
 44             case 5:
 45                 cout<<"("<<a<<"-"<<b<<")"<<"+"<<h<<"="<<endl;
 46              }
 47             }
 48         else
 49             for(int i = 1; i <= d; i++)
 50             {
 51              a = rand() % (q-p+1)+p;
 52              b = rand() % (q-p+1)+p;
 53              c = rand() % 4;
 54                 switch (c)
 55              {
 56             case 0:
 57                 cout<< a << "+" << b << "=" << endl;
 58                 break;
 59             case 1:
 60                 cout<< a << "-" << b << "=" << endl;
 61                 break;
 62             case 2:
 63                 cout<< a << "*" << b << "=" << endl;
 64                 break;
 65             case 3:
 66                 cout<< a << "/" << b << "=" << endl;
 67                 break;
 68              }
 69             }
 70     }
 71     else
 72         if(g==1)
 73         for(int i = 1; i <= d; i++)
 74         {
 75         a = rand() % (q-p+1)+p;
 76         b = rand() % (q-p+1)+p;
 77         h = rand() % (q-p+1)+p;
 78         c = rand() % 4;
 79         switch (c)
 80         {
 81             case 0:
 82               cout<< a << +<< b << "=" << endl;
 83               break;
 84             case 1:
 85               cout<< a << "-" << b << "=" << endl;
 86               break;
 87             case 2:
 88                 cout<<"("<<a<<"+"<<b<<")"<<"-"<<h<<"="<<endl;
 89                 break;
 90             case 3:
 91                 cout<<"("<<a<<"-"<<b<<")"<<"+"<<h<<"="<<endl;
 92         }
 93         }
 94         else
 95             for(int i = 1; i <= d; i++)
 96             {
 97              a = rand() % (q-p+1)+p;
 98              b = rand() % (q-p+1)+p;
 99              c = rand() % 2;
100              switch (c)
101              {
102             case 0:
103               cout<< a << "+" << b << "=" << endl;
104               break;
105             case 1:
106               cout<< a << "-" << b << "=" << endl;
107               break;
108              }
109             }
110         return 0;
111 }

技术分享技术分享技术分享技术分享

 此次测试全部正确 没有出现错误。就这样。。。

测试四则运算

标签:

原文地址:http://www.cnblogs.com/gaiiiiiiii/p/4345676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!