RFID46616c73 15 Newbie Poster

I think it would be more efficient to access the ResultsArray directly by using the produced value as the index.

const int MAX_VALUE = 18;
int results[MAX_VALUE + 1] = {0};  //add 1 to compensate for zero-based arrays

for (int i = 0; i < MAX_ITERATIONS; ++i) {
  dieSet.roll()
  results[dieSet.getResult()]++;
}

Thanks man. I worked on it over the weekend, and I've made progress. It compiles and runs. Now, how do I take the results and place them into a vertical and a horizontal histogram of the data?

Die.h

#ifndef DIE_H					// allows for additional
#define DIE_H

class Die

{
public:										// available outside of class
		Die();								// SMF to set value
		void Roll();							// member functions
		int GetFaces();

private:									// not available outside class
		int Face;
};

#endif

Die.cpp

#include "Die.h"				// for processing die face
#include <cstdlib>					// for the library rand() function

Die::Die()						//Initializes Face data member
{
 Face = 1;
}

void Die::Roll()
{
    Face = rand() % 6 + 1;
	
}
 
int Die::GetFaces()
{
    return Face;
}

DieRoll.h

#ifndef DIEROLL_H			// allows for additional
#define DIEROLL_H				

#include "Die.h"

class DiceRoll					// classs that specifies a collection of 3 contained Die objects

{
public:
		void RollDice();				// Calls Roll() function on each contained die
		int GetRollFaces();		// Returns the sum of the current Face value of Die1, Die2, & Die3

private:
		Die Die1;				// The three die contained in this -i.e
		Die Die2;				// objects of this class automatically contain
		Die Die3; …
RFID46616c73 15 Newbie Poster

How's this looking now? I've got Die and DieRoll compiling smoothly now.

Updated Code:
Die.h

#ifndef DIE_H					
#define DIE_H

//              Class Object
class Die

{
public:							// available outside of class
		Die();					// SMF to set value
		void Roll();				// member functions
		int GetFaces();

private:						// not available outside class
		int Face;
};
#endif

Die.cpp

#include "Die.h"				        // for processing die face
#include <cstdlib>					// for the library rand() function

Die::Die()						//Initializes Face data member
{
 Face = 0;
}

void Die::Roll()                                        // pulls the value of that roll
{
    Face = rand() % 6 + 1;
	
}
 
int Die::GetFaces()                                     // returns the die value
{
    return Face;
}

DieRoll.h

#ifndef DIEROLL_H			
#define DIEROLL_H				

#include "Die.h"

class DiceRoll					        // classs that specifies a collection of 3 contained Die objects

{
public:
		DiceRoll();				// Calls Roll() function on each contained die
		int GetRollFaces();		        // Returns the sum of the current Face value of Die1, Die2, & Die3

private:
		Die Die1;				// The three die contained in this -i.e
		Die Die2;				// objects of this class automatically contain
		Die Die3;				// three dice
};
#endif

DieRoll.cpp

#include <cstdlib>					// for the library rand() function
#include "DieRoll.h"				       // for processing die roll
#include "Die.h"

	DiceRoll::DiceRoll()		
	{
		Die1.Roll();
		Die2.Roll();
		Die3.Roll();
	}
	int DiceRoll::GetRollFaces()
	{
		int result;
		result = (rand() % 6) + 1;
		return result;
	}

Next step are the 3 global functions for the array that collects the results of the rolls.

I was thinking of …

RFID46616c73 15 Newbie Poster

I know I shouldn't be thinking about the histograms yet, but I was wondering, if I took the values in the arrays and used <string> functions to replace the numbers with an * mark would that print out a histogram? I'd have to use pointers I think to move things around, but it just might work.

RFID46616c73 15 Newbie Poster

Thanks guys. I knew in my confusion with the two classes doing almost the same thing that I was going to get confused. I've implemented the suggestions and have a working Die set.

As it was explained to me in another email, the Die class is an abstraction of a single physical die entity, while the DiceRoll class is an abstraction of three dice being rolled together with their total spots being reported to a using client via the member function Dice::GetFace().

In other words, each roll of the dice is one call to the RollDice() member function of a DiceRoll object that contains three objects of class Die.

The class DiceRoll contains no constructor member function since the contained data members are, themselves, objects of the class Die. These contained objects should be automatically initialized via their constructors when a DiceRoll object is declared (i.e., the constructor for class Die will automatically be invoked three times to construct each of the three contained Die object data members).

And yeah, I need to store the values so that later on I can use that data to build the two histograms. We never went over how to do that, but I'll look it up in the book.

RFID46616c73 15 Newbie Poster

Doing this project 1 step @ a time but the multiple files are starting to get confusing. Lemme start by telling you all what I need to do, then show you what I've done, and then maybe you can tell me if I'm on track with this or if I need to scrap it and start over. I don't necessarily want you to give me any code - I can do my own homework, but a point in the right direction.

Simulate Dice Rolling Game
1. Two classes used (Die, DiceRoll)
Note: Die is an abstraction of a single physical entity
DiceRoll is an abstraction of three dice rolled together
DiceRoll contains no constructor member function
class Die and class DieRoll must be in separate files
2. Three global functions required
void GatherStats(int RollsArray[], int RollsArraySize, int ResultsArray[]); // prototype
3. Loop for the size of the RollsArray include switch
Note: case clause increment ResultsArray cell, count all possible dice rolls
Frequency of each total is recorded in ResultsArray
4. Main driver global function declare two arrays and call the gloval functions
Note: Min size of 200
5. Pass RollsArray to GatherStats function and call DisplayResults
6. Display a horizontal histogram of asterisk characters.
7. Display a vertical histogram of asterisk characters.

Code(This is broken up into multiple files cuz it's easier to work on and compile.)

Dice.h

#ifndef DieRoll					// …
Nick Evan commented: Excellent first post. Bravo! +15