Created
July 13, 2020 01:16
-
-
Save tinwritescode/2b00b510f3ffbd2e12b7728d3af588b7 to your computer and use it in GitHub Desktop.
from Project 2 OOP, HCMUS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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