dice.cpp
来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 37 行
CPP
37 行
#include "dice.h"#include "randgen.h"// implementation of dice class// written Jan 31, 1994, modified 5/10/94 to use RandGen class// modified 3/31/99 to move RandGen class here from .h fileDice::Dice(int sides)// postcondition: all private fields initialized { myRollCount = 0; mySides = sides;}int Dice::Roll()// postcondition: number of rolls updated// random 'die' roll returned { RandGen gen; // random number generator myRollCount= myRollCount + 1; // update # of times die rolled return gen.RandInt(1,mySides); // in range [1..mySides]}int Dice::NumSides() const// postcondition: return # of sides of die { return mySides;}int Dice::NumRolls() const// postcondition: return # of times die has been rolled { return myRollCount;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?