作业要求:
提交内容包括可以运行的程序或安装包;
源程序代码;
软件使用说明书;
结对成员简介和分工说明;
程序源代码:
1 #include<iostream>
2 #include<stdlib.h>
3 #include<time.h>
4 using namespace std;
5
6
7 char get_oper(int a)
8 {
9 switch(a)
10 {
11 case 0:return '+';
12 case 1:return '-';
13 case 2:return '*';
14 case 3:return '/';
15 }
16 }
17 int main()
18
19 {
20 srand(time(NULL));
21 int num1=0;
22 int num2=0;
23 int operators=0;
24 int cpl; //定义每行输出题目个数
25 int range; //定义数值范围
26 int Tanswer; //定义计算结果
27 int num; //定义题目个数
28 int JG; //定义每行间隔
29 char m; //是否有乘除法
30 char n; //加减有无负数
31 int answer;
32 int wrang=0;
33 int right=0;
34 cout<<"请输入输出题目个数:";
35 cin>>num;
36 cout<<"请输入数值范围:";
37 cin>>range;
38 cout<<"请输入每行题目个数:";
39 cin>>cpl;
40 cout<<"请输入每行间隔:";
41 cin>>JG;
42 cout<<"是否有乘除法(Y/N)?";
43 cin>>m;
44 cout<<"是否有负数(Y/N)?";
45 cin>>n;
46 for(int i=1;i<=num;i++)
47 { //随机产生运算的数和运算符。
48 num1=rand()%range;
49 num2=rand()%range;
50 if(m=='Y')
51 {
52 operators=rand()%4;
53 switch(operators)
54 {
55 case 0:Tanswer=num1+num2;break;
56 case 1:Tanswer=num1-num2;break;
57 case 2:Tanswer=num1*num2;break;
58 case 3:Tanswer=num1/num2;
59 }
60 }
61 else if(m=='N')
62 {
63 operators=rand()%2;
64 switch(operators)
65 {
66 case 0:Tanswer=num1+num2;break;
67 case 1:Tanswer=num1-num2;break;
68 }
69 }
70 if(answer<range)
71 {
72 if(n=='Y')
73 {
74 cout<<num1<<get_oper(operators)<<num2<<"=";
75
76 cin>>answer;
77 if(answer==Tanswer)
78 {
79 cout<<"对";
80 right++;
81 }
82 else
83 {
84 cout<<"错";
85 wrang++;
86 }
87 for(int j=0;j<=JG;j++)
88 {
89 cout<<" ";
90 }
91 cout<<"\t";
92 if(i%cpl==0)
93 {
94 cout<<endl;
95 }
96 }
97 else if(n=='N')
98 {
99 i--;
100 }
101 }
102 else
103 {
104 i--;
105 }
106 }
107 cout<<"作对数量:"<<right<<"错题数量:"<<wrang;
108 return 0;
109 }