//Arithmetic program, supportting proper fraction arithmetic
//2016,03,04
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
void main()
{
srand((int)time(NULL)); //Produce seeds
int array_A[30];
int array_B[30];
for (int i = 0; i < 30; i++) //Produce 30 random number in the two arrays respectively
{
array_A[i] = 1+rand() % 99;
array_B[i] = 1+rand() % 99;
}
for (int i = 0; i < 30; i++)
{
if (array_A[i] > array_B[i])
{
int suanfu = rand() % 4;
switch (suanfu)
{
case 0:
cout << array_A[i] << " + " << array_B[i] << "=" << endl; break;
case 1:
cout << array_A[i] << " - " << array_B[i] << "=" << endl; break;
case 2:
cout << array_A[i] << " x " << array_B[i] << "=" << endl; break;
case 3:
cout << array_A[i] << " ÷ " << array_B[i] << "=" << endl; break;
}
}
else
{
int copyA = array_A[i]; //Retain the original value of A;
int copyB = array_B[i];
int beichushuA = 100; //The denominator is set to 100
int beichushuB = 100;
int firstA = beichushuA % copyA;
int firstB = beichushuB % copyB;
while (firstA != 0) //Get the greatest common divisor of A and 100 to get true score reduction
{
int temp = copyA;
copyA = beichushuA%copyA;
beichushuA = temp;
firstA = beichushuA%copyA; //copyA is becoming the Greatest common divisor in the end
}
while (firstB != 0)
{
int temp = copyB;
copyB = beichushuB%copyB;
beichushuB = temp;
firstB = beichushuB%copyB;
}
int suanfu = rand() % 4;
switch (suanfu)
{
// Output fractional in the form of the minimalist
case 0:
cout << array_A[i] / copyA << "/" << 100 / copyA << " + " << array_B[i] / copyB << "/" << 100 / copyB << "=" << endl; break;
case 1:
cout << array_B[i] / copyB << "/" << 100 / copyB << " - " << array_A[i] / copyA << "/" << 100 / copyA << "=" << endl; break;
case 2:
cout << array_A[i] / copyA << "/" << 100 / copyA << " x " << array_B[i] / copyB << "/" << 100 / copyB << "=" << endl; break;
case 3:
cout << array_A[i] / copyA << "/" << 100 / copyA << " ÷ " << array_B[i] / copyB << "/" << 100 / copyB << "=" << endl; break;
}
}
}
}