What I have to do is
Fill an empty array of 10000 with only 1 and 2, which will be placed randomly
'1,2' will be placed together in an empty array in only 8 spaces.
something like this:
000000121200000012012000000
and every experiment it will be random with 8 spaces filled by '1,2'
First write a function with the header “double experiment(int n)” . The parameter n represents the length/size of the board and the function returns the “occupancy” of a randomly filled board, which is the percentage of filled spaces (number of filled spaces divided by the length of the board).
The function “experiment” will
1. Clear the board; i.e. set all values of the board to “empty” (0).
2. Randomly place, or attempt to place, n dominoes onto the board.
3. Compute the “occupancy” of the current board.
4. Return the value of the “occupancy”, a double value.
..................................................
I need help in understanding what goes on in this program.
The first thing is the function. Here the parameter is n and return occupancy, what value goes there? I know the length is 10000 but what about the size. How is n related to occupancy?
Thus, how do I write the function?
2ndly how do i randomly put '1,2' in the array?
I can't even seem to start the code.
........................................
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
double experiment (int n) {
int Board[10000] = {0}, i;
srand (time (NULL));
for (i=1; i<=27, n++)
Board[i] = rand() % 2 + 1;
occupancy = 8/27;
occupancy = occupancy * 1.0;
return occupancy;
}
|