I need an explanation for this Programming question to help me study.
In project 1 you wrote an application to see how distributed are the numbers created by instances of the Random class. Many of you have used a functional approach while others used some object-oriented concepts.
In this project we will solve our problem using a purely object-oriented approach. You will see how designing objects (their properties and methods) intelligently can make code really powerful.
We want to design our die class (to be named aDie) such that we can have statements such as:
aDie D; // To instantiate a Die object
int rolled = D; // To get the value rolled by D
rolled = D + D; // To get the value of the sum of 2 rolls of the die
aDie d1, d2; // to instantiate 2 dice
rolled = d1 + d2; // To get the value of the sum of the roll of 2 dice
In essence, we are creating a new class that behaves like a random number whenever it is used in an expression whose result is an int.
As in project 1, we will want to visualize the histograms for different experiments.
We want to see the histograms for the faces of 1 die.
We want to see the histograms for the faces of the sum of 2 dice.
We want to see the histograms for the faces of the product of 2 dice
Design a coin class (to be called aCoin) that simulates a coin. You want to design it so that you can do this:
// Instantiate a coin
// Get the result of a “toss” of the coin this way:
String z = coin;
The variable z should only be “H” or “T” for Heads and Tail.
Then show the number of H’s and of T’s obtained by displaying their counts
Then display the histogram of the toss results. As before, the maximum count should be represented with 60 X’s
Finally we want to simulate drawing cards from a deck,with or without replacement. With replacement means that the card is placed back in the deck after having been drawn.
You will want to design a class that represents a deck of card (52 cards. 13 cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King)
The class is to be called “aDeckOfCards”. And it should generate a random card drawn out of the deck.
The card should be printable with a string of the form: “Brand-Suit” where the brands are A,2,3,4,5,6,7,8,9,T,J,Q,K and the suits are “S,H,D,C for Spades, Heart, Diamond and Clubs)
You should be able to have statements such as:
// Declare a deck of cards
// Get a random card from the deck
aCard c = deck;// Draw a hand of N cards
Vector<aCard> hand = deck.draw(N);
Using your aDeckOfCards class, simulate the result of drawing 4 hands of 5 cards each (as in playing poker) and show each hand by printing the 5 cards of each hand. You should have a print method for a card so that you can print each card of the hand as in 4-S, K-H, K-D, 3-C, T-H for 4 of SPADE, King of HEART, KING of Diamond,3 of Club and TEN of Heart
This may seem a little abstract but given our lecture you should be able to get the job done.
Each of your classes should have its own “.h” file and “.cpp” files.
The aDie file for example should be implemented with “aDie.h” and “aDie.cpp”.
As in real life, this project may be amended.
project 1 code is attached