Write a program with a class called Dice in a file called "Dice.h" that has as a member object a vector that simulates the rolling of a single die a hundred times. as well as a member variable called Size which contains the size of the vector.
In the file Dice.cpp, the Dice class should have the following public member functions defined:
a default constructor which sets all of the values of the vector member object to 0.
roll100() which rolls the die 100 times and records that roll in the vector member object.
calculateRolls() which calculates the number of 1 rolls, the number of 2 rolls, the number of 3 rolls, the number of 4 rolls, the number of 5 rolls, and the number of 6 rolls. The function then displays the number of the respective rolls to the user.
printDice() which displays the contents of the vector to the screen with 10 elements of the vector per line for 10 lines.
https://i.stack.imgur.com/QaYHG.png
https://i.stack.imgur.com/v6gxj.png
https://i.stack.imgur.com/CzijH.png
Main.cpp:
#include <iostream>
#include "Dice.h"
#include <vector>
using namespace std;
int main() {
Dice roll;
roll.roll100();
roll.calculateRolls();
roll.printDice();
}
Dice.cpp:
#include "Dice.h"
#include <iostream>
#include <vector>
using namespace std;
Dice::Dice() {
vector <int> rolls(SIZE, 0);
}
const int SIZE = 100;
vector <int> rolls(SIZE, 0);
int ones;
int twos;
int threes;
int fours;
int fives;
int sixes;
void roll100() {
unsigned seed = time(0);
srand(seed);
int result;
for (int i = 0; i < SIZE; i ) {
result = (rand() % 6 1);
rolls[i] = result;
}
}
void calculateRolls()
{
for (int i = 0; i < SIZE; i ) {
if (rolls[i] == 1)
ones ;
if (rolls[i] == 2)
twos ;
if (rolls[i] == 3)
threes ;
if (rolls[i] == 4)
fours ;
if (rolls[i] == 5)
fives ;
if (rolls[i] == 6)
sixes ;
}
cout<<"Number of 1 rolls "<<ones<<"\n";
cout<<"Number of 2 rolls "<<twos<<"\n";
cout<<"Number of 3 rolls "<<threes<<"\n";
cout<<"Number of 4 rolls "<<fours<<"\n";
cout<<"Number of 5 rolls "<<fives<<"\n";
cout<<"Number of 6 rolls "<<sixes<<"\n";
}
void printDice() {
for (int i = 0; i < SIZE; i ) {
if (i % 9 == 0)
cout << endl;
cout << rolls[i];
}
}
Dice.h:
#ifndef DICE_H
#define DICE_H
#include <vector>
using namespace std;
class Dice {
private:
public:
const int SIZE = 100;
int ones;
int twos;
int threes;
int fours;
int fives;
int sixes;
Dice();
void roll100();
void calculateRolls();
void printDice();
};
#endif
CodePudding user response:
Dice.cpp needs
Dice::calculateRolls(){....}
etc
PS. I did not look for any other errors, just your given compile errors.