#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
class Lottery
{
private:
void Sort(int *tab, int size);
int **bet_Table;
int **temp_Table;
int how_m_games;
int how_m_result;
int max_value;
int min_value;
float pay;
public:
Lottery(int min, int max, int how_many_result, int how_many_games,float how_much_bet);
void bet_Games();
void print_Report();
~Lottery();
};
void Lottery::Sort(int *tab, int size)
{
int i,j,k;
for(i=1;i<size;i++)
for(j=size-1;j>=i;j--)
if(tab[j]<tab[j-1])
{
k=tab[j-1];
tab[j-1]=tab[j];
tab[j]=k;
}
}
Lottery::Lottery(int min,int max, int how_many_result, int how_many_games, float how_much_bet)
{
int i;
srand(time(NULL));
pay=(1.0*how_many_games)*how_much_bet;
how_m_games=how_many_games;
how_m_result=how_many_result;
min_value=min;
max_value=max;
bet_Table=new int*[how_m_games];
temp_Table=new int*[how_m_games];
for(i=0;i<how_m_games;i++)
{
bet_Table[i]=new int[how_m_result];
temp_Table[i]=new int[max_value];
}
}
void Lottery::bet_Games()
{
int i,j,k;
for(i=0;i<how_m_games;i++)
for(j=0;j<max_value;j++)
temp_Table[i][j]=0;
i=0;
do
{
j=0;
do
{
do
{
k=rand()%max_value;
}while(temp_Table[i][k]!=0);
temp_Table[i][k]=1;
bet_Table[i][j]=k+1;
++j;
}while(j<how_m_result);
++i;
}while(i<how_m_games);
for(i=0;i<how_m_games;i++)
{
Sort(bet_Table[i],how_m_result);
}
}
void Lottery::print_Report()
{
int i,j;
for(i=0;i<how_m_games;i++)
{
for(j=0;j<how_m_result;j++)
{
cout<<bet_Table[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<"------------------------------------------------\n";
cout<<"To pay: "<<pay<<endl;
}
Lottery::~Lottery()
{
int i;
for(i=0;i<how_m_games;i++)
{
delete temp_Table[i];
delete bet_Table[i];
}
delete [] bet_Table;
delete [] temp_Table;
}
int main(int argc, char **argv)
{
Lottery my_Game(1,49,6,10,4.0); //polish "Duzy Lotek Plus"
my_Game.bet_Games();
my_Game.print_Report();
Lottery next_Game(1,42,5,3,1.25); //polis "Mini Lotto"
next_Game.bet_Games();
next_Game.print_Report();
return 0;
}
Brak komentarzy:
Prześlij komentarz