Arithmetic 2 program

Source: Internet
Author: User
Tags net time

I. Design ideas

Because forgetting does not pass the address of the array, all the programs are a bit confusing in the main function!
A, b array holds the numerator or integer, the XY array holds the denominator of the fraction, and when the denominator is 0 o'clock regenerated, the numerator is regenerated when the division is 0, the operation symbol exists as an integer in the C array, and the minus sign is multiplied by the randomly generated 1 and 0 control molecules by 1.

Two. SOURCE program code

#include <iostream>
using namespace Std;
#define N 100

void Main ()
{
int A[n],b[n],x[n],y[n],c[n],sel[3],num,page,lie,hang,max;
cout<< "..... Please select the following options ... "<<endl;
cout<< "1. Whether there is a multiplication method." <<endl;
cout<< "2. There are no negative numbers" <<endl;
cout<< "3 Whether the score is supported." <<endl;
cout<< "Please enter a range of values (maximum):" <<endl;
for (int i=0;i<3;i++)
cin>>sel[i];
cin>>max;
cout<< "Please enter the total number of pages and rows of the series:";
cin>>page>>hang>>lie;
Num=page*hang*lie;

Generate random numbers
if (sel[2]==1)
{
for (int i=0;i<num;i++)
{
A[i]=rand ()%max;
X[i]=rand ()%max;
while (x[i]==0)
X[i]=rand ()%max;
B[i]=rand ()%max;
Y[i]=rand ()%max;
while (y[i]==0)
Y[i]=rand ()%max;
}
if (sel[1]==1)
{
for (int i=0;i<num;i++)
{
if (rand ()%2==1)
a[i]= ( -1) *a[i];
if (rand ()%2==1)
b[i]= ( -1) *b[i];
}
}
if (sel[0]==1)
for (int i=0;i<num;i++)
{
C[i]=rand ()%4;
if (c[i]==3)
{
while (b[i]==0)
B[i]=rand ()%max;
}
}
Else
for (int i=0;i<num;i++)
C[i]=rand ()%2;
}


Else
{
for (int i=0;i<num;i++)
{
A[i]=rand ()%max;
B[i]=rand ()%max;
}
if (sel[1]==1)
{
for (int i=0;i<num;i++)
{
if (rand ()%2==1)
a[i]=a[i]* (-1);
if (rand ()%2==1)
b[i]= ( -1) *b[i];
}
}
if (sel[0]==1)
for (int i=0;i<num;i++)
C[i]=rand ()%4;
Else
for (int i=0;i<num;i++)
C[i]=rand ()%2;
}
Avoid duplication
if (sel[2]==1)
{
for (int i=0;i<num-1;i++)
{
for (int j=i+1;j<num;j++)
{
while (A[i]==a[j]&&b[i]==b[j]&&c[i]==c[j])
{A[i]=rand ()%max;}
}
}
}
Else
{
for (int i=0;i<num-1;i++)
{
for (int j=i+1;j<num;j++)
{
while (A[i]==a[j]&&c[i]==c[j])
{A[i]=rand ()%max;}
}
}
}

Output
for (int k=0;k<num;k++)
{
if (sel[2]==1)
{
cout<<a[k]<< "/" <<x[k];
Switch (C[k])
{
Case 0:
cout<< "+";
Case 1:
cout<< "-";
Case 2:
cout<< "*"; break;
Case 3:
cout<< "/"; break;
}
cout<<b[k]<< "/" <<y[k]<< "";

}
Else
{
cout<<a[k];
Switch (C[k])
{
Case 0:
cout<< "+";
Case 1:
cout<< "-";
Case 2:
cout<< "*"; break;
Case 3:
cout<< "/"; break;
}
cout<<b[k]<< "";
}
if ((k+1)%lie==0)
cout<<endl;
if ((k+1)% (Lie*hang) ==0)
cout<<endl<<endl;
}
}

Three. Running results

Four. Programming summary

Because forgetting does not pass the address of the array, all the programs are a bit confusing in the main function!
A, b array holds the numerator or integer, the XY array holds the denominator of the fraction, and when the denominator is 0 o'clock regenerated, the numerator is regenerated when the division is 0, the operation symbol exists as an integer in the C array, and the minus sign is multiplied by the randomly generated 1 and 0 control molecules by 1.

Five.

Date

Start time

End time

Interrupt Time

NET time

Activities

Note

3/13

11:30

12:00

0

30

Set the layout and ideas of the program

3/18

14:00

22:00

120

360

Writing Programs

3/19

16:00

19:00

30

70

Edit write report, upload blog

Arithmetic 2 program

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.