这次的编程给了我很大的收获让我知道了我的很多不足,所以我很享受这次编程的过程。这次的练习让我对C++这一语言有了更深的认识,我会继续努力去学习这门语言的。
在刚编程时很多语言格式忘了,在经过翻书复习后有了编程的想法去编写了程序。在编程结束后有不少错误,让我意识到了自己的很多不足。经过仔细的检查排除的错误,编程完成后的自豪感是很强,虽然这个程序并不难。这次的编程我的收获还是很大的。
我编写的这个程序是提供给2、3年级的学生用的。代码很简单,界面也很朴素,使用起来也十分简单。使用者只需要根据提示操作就可以得到四则运算的题目。试题有整数和分数两种选择。用户可以自行选择,当输入1时便出现30道整数试题。当输入2时变输入30道分数试题。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
int d1, d2, d3, d4, d5, d6, D, i;
int op;
cout << "请选择要做要做的题的类型\n" << endl;
cout << "做整数四则运算输入1 \n" << "做分数四则运算输入2\n" << endl;
cin >> D;
srand(time(NULL));
switch (D){
case 1:
{
for (i = 1; i< 30; i++)
{
op = rand() % 4;
switch (op)
{
case 0:
d1 = rand() % 100;
d2 = rand() % 100;
cout << d1 << "+ " << d2 << "=" << endl;
break;
case 1:
d1 = rand() % 100;
d2 = rand() % 100;
if (d1 > d2)
cout << d1 << "-" << d2 << "=" << endl;
else
cout << d2 << "-" << d1 << "=" << endl;
break;
case 2:
d1 = rand() % 100;
d2 = rand() % 100;
cout << d1 << "*" << d2 << "=" << endl;
break;
case 3:
d1 = rand() % 100;
d2 = rand() % 100;
cout << d1 << "/" << d2 << "=" << endl;
break;
default: cout << "error\n";
}
}
}
break;
case 2:
{
for (i = 1; i<30; i++)
{
op = rand() % 4;
switch (op)
{
case 0:
d1 = rand() % 100;
d2 = rand() % 100;
d3 = rand() % 100;
d4 = rand() % 100;
cout << "(" << d1 << "/" << d2 << ")" << "+" << "(" << d3 << "/" << d4 << ")=" << endl;
break;
case 1:
d1 = rand() % 100;
d2 = rand() % 100;
d3 = rand() % 100;
d4 = rand() % 100;
if ((d1*d4)>(d2*d3))
cout << "(" << d1 << "/" << d2 << ")" << "-" << "(" << d3 << "/" << d4 << ")=" << endl;
else
cout << "(" << d1 << "/" << d4 << ")" << "-" << "(" << d3 << "/" << d2 << ")=" << endl;
break;
case 2:
d1 = rand() % 100;
d2 = rand() % 100;
d3 = rand() % 100;
d4 = rand() % 100;
cout << "(" << d1 << "/" << d2 << ")" << "*" << "(" << d3 << "/" << d4 << ")=" << endl;
break;
case 3:
d1 = rand() % 100;
d2 = rand() % 100;
d3 = rand() % 100;
d4 = rand() % 100;
cout << "(" << d1 << "/" << d2 << ")" << "/" << "(" << d3 << "/" << d4 << ")=" << endl;
break;
default: cout << "error\n";
}
}
}
break;
}
system("pause");
}
运行界面如下