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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
# include <iostream>
# include <ctime>
# include <cstdlib>
# include <iomanip>
using namespace std ;
int check() ;
int main (void)
{
int dieone[6]={0} , y ,z , dietwo[6] = {0} ;
float counttwo = 0 , countthree = 0 , countforth = 0 , countfifth = 0 ,
countsixth = 0 , countseventh = 0 , counteighth = 0 , countnineth = 0 , counttenth = 0 , counteleventh = 0 , counttwelveth = 0 , Relativefrequency ;
srand(time(0)) ;
for (int x=0 ; x<= 8999 ; x++)
{
int sum = 0 ;
y = rand()%6 + 1 ;
dieone[y-1]=dieone[y-1] + 1 ;
z = rand()%6 + 1 ;
dietwo[z-1]=dietwo[z-1] + 1 ;
sum = y + z ;
if (sum == 2)
counttwo ++ ;
if (sum == 3)
countthree ++ ;
if (sum == 4)
countforth ++ ;
if (sum == 5)
countfifth ++ ;
if (sum == 6)
countsixth ++ ;
if (sum == 7)
countseventh ++ ;
if (sum == 8)
counteighth ++ ;
if (sum == 9)
countnineth ++ ;
if (sum == 10)
counttenth ++ ;
if (sum == 11)
counteleventh ++ ;
if (sum == 12)
counttwelveth ++ ;
}
cout << "---------------------------------------------------"
<< endl
<< "Sum "
<<"Frequency "
<<" Relative Frequency" ;
for (int i = 2 ; i <= 9 ; i++)
{
cout << endl
<< "---------------------------------------------------"
<< endl
<< i
<<" " ;
if (i == 2)
{
cout << counttwo
<<" " ;
Relativefrequency = (counttwo/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 3)
{
cout << countthree
<<" " ;
Relativefrequency = (countthree/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 4)
{
cout << countforth
<<" " ;
Relativefrequency = (countforth/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 5)
{
cout << countfifth
<<" " ;
Relativefrequency = (countfifth/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 6)
{
cout << countsixth
<<" " ;
Relativefrequency = (countsixth/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 7)
{
cout << countseventh
<<" " ;
Relativefrequency = (countseventh/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 8)
{
cout << counteighth
<<" " ;
Relativefrequency = (counteighth/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 9)
{
cout << countnineth
<<" " ;
Relativefrequency = (countnineth/9000) * 100 ;
cout << Relativefrequency ;
}
}
for (int i = 10 ; i <= 12 ; i++)
{
cout << endl
<< "---------------------------------------------------"
<< endl
<< i
<<" " ;
if (i == 10)
{
cout << counttenth
<<" " ;
Relativefrequency = (counttenth/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 11)
{
cout << counteleventh
<<" " ;
Relativefrequency = (counteleventh/9000) * 100 ;
cout << Relativefrequency ;
}
if (i == 12)
{
cout << counttwelveth
<<" " ;
Relativefrequency = (counttwelveth/9000) * 100 ;
cout << Relativefrequency ;
}
}
cout << endl ;
system("pause") ;
return 0 ;
}
|