Get premium membership and access questions with answers, video lessons as well as revision papers.

Create a class called dice that contains one private integer variable.Create a function called roll() that uses the standard randomn number generator, rand(), to generate...

      

Create a class called dice that contains one private integer variable.Create a function called roll() that uses the standard randomn number generator, rand(), to generate a number between 1 and 6. Then have roll() display that value.

  

Answers


Davis
#include
#include
using namespace std;
class dice {
int val;
public:
void roll();
};
void dice ::roll()
{
val = (rand() % 6) + 1; //generate 1 through 6
cout << val << "\n";
}
int main()
{
dice one, two;
one.roll();
two.roll();
one.roll();
two.roll();
one.roll();
two.roll();
return 0;
Githiari answered the question on May 12, 2018 at 16:40


Next: Create a class called prompt in C++ language.Pass its constructor function a prompting string of your choice.Have the constructor display the string and then input...
Previous: Given the following class, what are the names of its constructor and destructor functions? class widgit { int x, y; public : //.....fill in constructor and destructor functions };

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions