Advertisement
Guest User

die.h

a guest
Sep 9th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #pragma once
  2. class die
  3. {
  4. public:
  5. die();
  6. //Default constructor
  7. //Sets the default number rolled by a die to 1
  8.  
  9. void roll();
  10. //Function to roll a die.
  11. //This function uses a random number generator to randomly
  12. //generate a number between 1 and 6, and stores the number
  13. //in the instance variable num.
  14.  
  15. int getNum() const;
  16. //Function to return the number on the top face of the die.
  17. //Returns the value of the instance variable num.
  18.  
  19. private:
  20. int num; //The value of this instance ( 1 through 6variable num.
  21. };
  22.  
  23. die::die()
  24. {
  25. num = 1;
  26. srand(time(0));
  27. }
  28.  
  29.  
  30.  
  31. void die::roll()
  32. {
  33. num = rand() % 6 + 1;
  34. }
  35.  
  36. int die::getNum() const
  37. {
  38. return num;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement