BM> I'm still a beginner tho and I'd appreciate it if you guys
BM> and gals would check my work. So here it is my very first
BM> C++ program. The Slot Machine.....
The overall inpression is good.
But if somebody shows me his/her (and sometimes even my :-)) C++ code,
I always have some remarks.
BM> #define WHEEL_MAX 13
BM> #define STARTING_CASH 300
Don't use #define for anything else than conditional compiling
(including avoiding including a header file more than once).
Better write
const unsigned int WHEEL_MAX = 13;
const unsigned int STARTING_CASH = 300;
The compiler will treat values defined like this exactly as if they
had been #defined, but without the bad implications #define can have.
BM> class Wheel {
BM> int top;
BM> int mid;
BM> int bot;
Two remarks here:
1) Instead of exposing member variables in the public interface,
better use accessor methods; this will prevent a client of the class
from overwriting the member variables with invalid values:
class Wheel
{
public:
unsigned int top() const // accessor methods
{
return myTop;
}
unsigned int mid() const
{
return myMid;
}
unsigned int bot() const
{
return myBot;
}
void Spin();
private:
unsigned int myTop; // member variables for representation
unsigned int myMid;
unsigned int myBot;
};
2) Try to avoid redundant member variables. Instances of class Wheel
each describe the state of a wheel. For this purpose, knowing the
(say) top symbol and the order of the symbols is more appropriate than
your three variables:
class Wheel
{
public:
Wheel(); // constructor for initializing const members
unsigned int top() const // accessor methods
{
return myCurrentTop;
}
unsigned int mid() const
{
return (myCurrentTop+1)%WHEEL_MAX;
}
unsigned int bot() const
{
return (myCurrentTop+2)%WHEEL_MAX;
}
void Spin();
// sets myCurrentTop to a new value in [0..WHEEL_MAX)
private:
ú [ Continued In Next Message... ]
--- PCBoard (R) v15.22/M 25
---------------
* Origin: McMeier & Son BBS (2:301/138)
|