dice.h
来自「Data Structures with C++附代码」· C头文件 代码 · 共 51 行
H
51 行
#include "random.h"
class Dice
{
private:
// member data
int diceTotal; // sum of the two die
int diceList[2]; // listing of the two die faces
// random number generator class used for dice toss
RandomNumber rnd;
public:
// constructor
Dice(void);
// dice handling methods
void Toss(void);
int Total(void) const;
void DisplayToss(void) const;
};
// constructor. let random number generator use automatic seeding
Dice::Dice(void)
{}
// toss and determine dietotal
void Dice::Toss(void)
{
diceTotal = 0;
for (int i = 0; i < 2; i++)
{
diceList[i] = rnd.Random(6) + 1;
diceTotal = diceTotal + diceList[i];
}
}
// return the value of dietotal
int Dice::Total(void) const
{
return diceTotal;
}
// print the dice faces
void Dice::DisplayToss(void) const
{
for (int i = 0; i < 2; i++)
cout << diceList[i] << " ";
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?