Software Engineering--arithmetic Ⅱ (also a big flaw, forget to teach)

Source: Internet
Author: User

Topic requirements: Randomly generated arithmetic topics

Random Arithmetic requirements: the topic avoids repeating the customizable quantity, the range of values, the addition and subtraction of negative numbers, division, etc.

#include <iostream>
#include <time.h>
using namespace Std;
void Basic (int num,int cc,int mhs,int kgs,int pyu,int max,int nnum)//Basic arithmetic function
{
Srand (Time (NULL));
int a[100]; The array that holds the first operand
int b[100]; An array that holds the second operand
int c[100]; Array of stored operators
int n,o,p,q,m;
int RePET; Control whether to repeat
for (int i=0;i<num;i++)
{
N=rand ()%max;
A[i]=n;
O=rand ()%max;
B[i]=o;
P=rand ()%cc;
C[i]=p;
Q=rand ()%2;
M=rand ()%2;
while (Nnum)
{
Switch (q)
{
Case (0):
A[i]=-a[i];
Break
Case (1):
Break
}
Break
}
while (Nnum)
{
Switch (m)
{
Case (0):
B[i]=-b[i];
Break
Case (1):
Break
}
Break
}
Repet=1;
for (int j=0;j<i;j++)
{
if (A[i]==a[j]&&b[i]==b[j]&&c[i]==c[j])//To determine if there are duplicates
{
I=i-1;
repet=0;
}
}
while (RePET)
{
if (i%mhs==0)
{
cout<<endl;
}
Switch (C[i])
{
Case (0):
cout<< "(" <<i+1<< ")" <<a[i]<< "+" <<b[i]<< "=";
Break
Case (1):
cout<< "(" <<i+1<< ")" <<a[i]<< "-" <<b[i]<< "=";
Break
Case (2):
cout<< "(" <<i+1<< ")" <<a[i]<< "*" <<b[i]<< "=";
Break
Case (3):
{
while (Pyu)
{
if (a[i]%b[i]!=0)
I=i-1;
repet=0;
}
if (b[i]==0)//Determine if the dividend is 0, is 0 does not output
{
I=i-1;
Break
}
Else
{
cout<< "(" <<i+1<< ")" <<a[i]<< "/" <<b[i]<< "=";
Break
}
}
}
for (int k=0;k<kgs;k++)
{
cout<< "\ t";
}
Break
}
}
cout<<endl;
}

void Main ()
{
int num1,cc1,m,n;
int mhs1,kgs1,pyu1,max1,nnum1;
while (n)
{
cout<< "Random Arithmetic" <<endl;
cout<< "--------------------------------------------------------" <<endl;
cout<< "1, please enter the number of arithmetic questions:";
cin>>num1;
cout<<endl;
while (1)
{
cout<< "2, there is multiplication method Please enter 0, no input 1:";
cin>>m;
cout<<endl;
if (m==0)
{
cc1=4;
Break
}
else if (m==1)
{
cc1=2;
Break
}
Else
cout<< "Input is wrong, please re-enter: 1 for the multiplication method, 2 for non-multiplication law:";
}
if (m==0)
{
cout<< "Please select whether the division is the surplus number, the remainder of the input 0, there is no residue input 1:";
cin>>pyu1;
cout<<endl;
}
cout<< "3, please enter whether there is a negative number (0 means no negative, 1 is negative):";
cin>>nnum1;
cout<<endl;
cout<< "4, please enter a range of values (maximum, the default starting from 0, if there is a negative number from the largest negative start):";
cin>>max1;
cout<<endl;
cout<< "5, please enter the printing method: The number of operational questions per line (recommendation 3 or 4):";
cin>>mhs1;
cout<<endl;
cout<< "Interval between the operands of each column (recommendation 1 or 2):";
cin>>kgs1;
cout<<endl;
cout<< "The result is:";
Basic (NUM1,CC1,MHS1,KGS1,PYU1,MAX1,NNUM1);
cout<<endl;
cout<< "Continue please enter 1, exit input 0:";
cin>>n;
cout<<endl;
}
}

Results:

Summarize:

See the topic, the initial thinking is to write a number of functional areas to achieve the topic requirements, but in the process of writing encountered a problem, some places are not open, then add a function to modify the code to implement the new requirements of the program in addition to the main function only write a function, all the requirements are completed in this program, The extension of the program is not very good, it is not easy to find the wrong writing. In the process of writing, there will be some statements to forget, such as while and break. The basic knowledge of writing code is not strong, previously practiced relatively little, resulting in some sentences to be determined by repeated experiments. There are imperfections in the title, such as the output of negative numbers that are not enclosed in parentheses.

Software Engineering--arithmetic Ⅱ (also a big flaw, forget to teach)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.