1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
#include <iomanip>
using namespace std;
void fill_AR ( int [], int, int, int, int );
void printAR ( int [] );
void print ( int [], int, int, int );
int main()
{
int multiplier = 40;
int inc= 725;
int modulus = 729;
int seed = 1;
int newseed;
int seed_new [10];
fill_AR ( seed_new, seed, multiplier, inc, modulus );
printAR ( seed_new );
cout << "Run 1" << endl;
print ( seed_new, multiplier, inc, modulus );
cout << "Enter a new seed number: ";
cin >> newseed;
fill_AR ( seed_new, newseed,multiplier, inc, modulus );
cout << "Run 2" << endl;
print ( seed_new, multiplier, inc, modulus );
cout << "Enter a new seed number: ";
cin >> newseed;
fill_AR ( seed_new, newseed, multiplier, inc, modulus );
cout << "Run 3" << endl;
print ( seed_new, multiplier, inc, modulus );
}
void fill_AR ( int AR [], int s, int mul, int incr, int mod )
{
AR [0] = s;
for ( int i = 0; i < 11; i++ )
{
AR[i+1] = (mul * AR[i] + incr) % mod;
}
}
void printAR ( int AR [] )
{
for ( int cnt = 0; cnt < 10; cnt++ )
{
cout << AR[cnt] << " " << endl;
}
}
void print ( int AR [], int mul, int incr, int mod )
{
cout << endl << left << setw (12) << "Number" << setw (15) << "Multiplier" << setw (9)
<< "Seed" << setw (15) << "Increment" << setw (11) << "Modulus"
<< setw (10) << "Number Generated" << endl;
for (int cnt = 1; cnt < 11; cnt++ )
{
cout << left << setw (15) << cnt << setw (12) << mul << setw (10) << AR [cnt-1] << setw (15)
<< incr << setw (12) << mod << setw (10) << AR [cnt] << endl;
}
}
|