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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <cstdlib>
using namespace std;
void loadRandom666Array (int freq[], int numRolls);
void loadRandom468Array (int freq[], int numRolls);
bool printHistogram (int freqDist[], int numRolls);
int main()
{
int freq[16],numberrolls;
cout << "Enter number of rolls: ";
cin >> numberrolls;
loadRandom666Array( freq, numberrolls);
printHistogram(freq,numberrolls);
system("pause");
loadRandom468Array(freq,numberrolls);
printHistogram(freq,numberrolls);
}
void loadRandom666Array (int freq[], int numRolls)
{
int count=0,randomvalue1,randomvalue2,randomvalue3,sum;
for(int j=0; j<16; j++)
freq[j]=0;
for (int i=0; i< numRolls; i++)
{
randomvalue1=(rand()%6)+1;
randomvalue2=(rand()%6)+1;
randomvalue3=(rand()%6)+1;
sum=randomvalue1+randomvalue2+randomvalue3;
freq[i]=sum;
}
}
void loadRandom468Array (int freq[],int numRolls)
{
int randomvalue4,randomvalue6,randomvalue8,sum;
for (int j=0; j<16; j++)
freq[j]=0;
for (int i=0; i< numRolls; i++)
{
randomvalue4=(rand()%4)+1;
randomvalue6=(rand()%6)+1;
randomvalue8=(rand()%8)+1;
sum=randomvalue4+randomvalue6+randomvalue8;
freq[i]=sum;
}
}
bool printHistogram (int freqDist[], int numRolls)
{
for (int j=3; j<18; j++)
cout << j << " | "<< endl;
for(int g=0; g<16; g++)
if (freqDist[g]=numRolls)
{
for(int f=0; f<16; f++)
freqDist[f]=0;
for(int i=0; i <16; i++)
(freqDist[i] * 100/ numRolls);
cout << '*' << endl;
return true;
}
else
return false
}
|