c++ please include comments 4. The following table shows the enrollment of fresh
ID: 3715182 • Letter: C
Question
c++
please include comments
Explanation / Answer
Let us consider the program as bellow
# include<iostream.h>
#include<conio.h>
const int SIZE = 5000;// maximum size considered on the basis of total value given in the table
srand(time(NULL));// initial value is set to null.
int randList [SIZE]; // creation of the list
void init(int randList[], const int SIZE) // function to perform suffling for each trail
{
for (int i=0; i<SIZE; i++)
randList[i] = i % 100;
}
void shuffle (int randList[], const int SIZE)
{
for (int i=0; i<SIZE; i++)
swap(randList,i,(rand() % SIZE));
}
void swap(int randList[], int a, int b) /* based on the given trail the possible out come is to be set and arrange in the order. here two integer variable are used to swap the value among themselves.*/
{
int t = randList[a];
randList[a] = randList[b];
randList[b] = t;
}
bool trial(int randList[], const int SIZE)
{
return(randList[trialCount % SIZE] < randList [SIZE]); // getting the trail outcome value
}
void test(bool * resultList, const int resultSize) // organizing the final value for the list
{
const int SIZE = 1000;
srand(time(NULL));
int randList [SIZE];
init(randList,SIZE);
for (int i=0; i<resultSize; i++)
{
if (i%SIZE == 0)
shuffle(randList,SIZE);
resultList[i] = trial(randList,SIZE,i);
}
}
void main () // creation of the main method
{
const int resultSize = 2000;
bool * resultList = new bool[resultSize];
test(resultList,resultSize);
// check sequence of outcomes
}
********************************
here in the given question, their are 4 bits. so we can apply the each bit value and we can get the final answer. it should be noted that, this program is used to generate the random value out of the given max cont size total value.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.