Skip to content

Instantly share code, notes, and snippets.

@tinwritescode
Created July 13, 2020 01:16
Show Gist options
  • Select an option

  • Save tinwritescode/2b00b510f3ffbd2e12b7728d3af588b7 to your computer and use it in GitHub Desktop.

Select an option

Save tinwritescode/2b00b510f3ffbd2e12b7728d3af588b7 to your computer and use it in GitHub Desktop.
from Project 2 OOP, HCMUS
#include "Dice.h"
Dice::Dice()
{
m_rollTime = 0;
m_totalRoll = 0;
m_rollValues[0] = -1;
memset(m_rollValues, 0, sizeof(m_rollValues));
}
int Dice::Roll()
{
int number = m_random.next(1, 6);
m_rollTime++;
m_totalRoll += number;
m_rollValues[number]++;
return number;
}
void Dice::ShowStatistic() const
{
std::cout << "Number\tRoll times" << std::endl;
for (int i = 1; i <= 6; i++)
{
std::cout << i << '\t' << m_rollValues[i] << std::endl;
}
}
int Dice::GetRollAverage() const
{
return (!m_rollTime) ? -1 : m_totalRoll / m_rollTime;
}
int Dice::GetRollTime() const
{
return m_rollTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment