Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

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

Answer Attachments

Exams With Marking Schemes

Related Questions