Question

Specifications: C++ each class should have a header file all files must create a console application...

Specifications:

C++

each class should have a header file

all files must create a console application in Visual Studio

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

aCoin 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

aDeckOfCards deck;

// Get a random card from the deck

aCard c = deck;// Draw a hand of N cards

Vector 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

// File Name: aDie.h
#ifndef ADIE_H
#define ADIE_H
#include <cstdlib> // srand, rand
#include <ctime> // time
using namespace std;

// Defines class aDie

class aDie
{
// To store die value
int val;
public:
// Default constructor to generate random value between 1 and 6
aDie();

// Overloading + operator
// Returns the added result
friend int operator+(const aDie &c1, const aDie &c2);

// Overloading function to convert object type to integer
// Returns the value
operator int() const;
};// End of class

#endif // End of ADIE_H

-----------------------------------------------------------------------------

#include <iostream>
#include "aDie.h"
using namespace std;

// Default constructor to generate random value between 1 and 6
aDie::aDie()
{
val = rand() % 6 + 1;
}// Default constructor

// Overloading + operator
// Returns the added result
int operator+(const aDie& c1, const aDie& c2)
{
// Adds the value of both the objects
return c1.val + c2.val;
}// End of function

// Overloading function to convert object to integer
// Returns the value
aDie::operator int() const
{
return val;
}// End of function

// main function definition
int main()
{
aDie D; // To instantiate a Die object

int rolled = D; // To get the value rolled by D
cout<<"\n Rolled value: "<<rolled;
rolled = D + D; // To get the value of the sum of 2 rolls of the die
cout<<"\n Sum of rolled value: "<<rolled;
aDie d1, d2; // to instantiate 2 dice

rolled = d1 + d2; // To get the value of the sum of the roll of 2 dice
cout<<"\n Sum of rolled die 1 and die 2: "<<rolled;
}// End of main function

Sample Output:

Rolled value: 6
Sum of rolled value: 12
Sum of rolled die 1 and die 2: 11

2)

// File Name: aCoin.h
#ifndef ACOIN_H
#define ACOIN_H
#include <cstdlib> // srand, rand
#include <ctime> // time
using namespace std;

// Defines class aCoin

class aCoin
{
// To store coin head or tail
string val;
public:
// Default constructor to generate random value between 'H' and 'T'
aCoin();

// Overloading function to convert object type to string
// Returns the value
operator std::string() const;
};// End of class

#endif // End of ACOIN_H

----------------------------------------------------------------------------------

#include <iostream>
#include "aCoin.h"
using namespace std;

// Default constructor to generate random value between 1 and 6
aCoin::aCoin()
{
int res = rand() % 1 + 0;
if(res == 0)
val = "T";
else
val = "H";
}// Default constructor

// Overloading function to convert object to integer
// Returns the value
aCoin::operator std::string() const
{
return val;
}// End of function

// main function definition
int main()
{
// Instantiate a coin
aCoin coin;
// Get the result of a "toss" of the coin this way:
string z = coin;
cout<<"\n Coin tossed: "<<z;
}// End of main function

Sample Output:

Coin tossed: T

Add a comment
Know the answer?
Add Answer to:
Specifications: C++ each class should have a header file all files must create a console application...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • We want to design our die class (to be named aDie) such that we can have...

    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...

  • Create A Header file and A CPP File for this we want to simulate drawing cards...

    Create A Header file and A CPP File for this 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...

  • C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification...

    C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....

  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • For this project your card class must include an Image of the card. Here is a...

    For this project your card class must include an Image of the card. Here is a zip filecontaining 52 images you can use for your cards. Please note that the name for each card can be created by the concatenation of the first character of the suit, the value of the card, and the ".png" suffix. When you construct a card, you should have it load its image. Alternatives exist regarding how to draw() the card. One way to do...

  • 12. Coin Toss Simulator Write a class named Coin. The Coin class should have the following field ...

    12. Coin Toss Simulator Write a class named Coin. The Coin class should have the following field .A String named sideUp. The sideUp field will hold either "heads" or "tails" indicating the side of the coin that is facing up The Coin class should have the following methods .A no-arg constructor that randomly determines the side of the coin that is facing up (heads" or "tails") and initializes the aideUp field accordingly .A void method named toss that simulates the...

  • This needs to be done in c++11 and be compatible with g++ compiling Project description: Write...

    This needs to be done in c++11 and be compatible with g++ compiling Project description: Write a C++ program to simulate a simple card game between two players. The game proceeds as follows: The 52 cards in a deck of cards are shuffled and each player draws three cards from the top of the deck. Remaining cards are placed in a pile face-down between the two players. Players then select a card from the three in their hand. The player...

  • How do I start this c++ code homework? Write a code in C++ for a BlackJack...

    How do I start this c++ code homework? Write a code in C++ for a BlackJack card game using the following simplified rules: Each card has a numerical value. Numbered cards are counted at their face value (two counts as 2 points, three, 3 points, and so on) An Ace count as either 1 point or 11 points (whichever suits the player best) Jack, queen and king count 10 points each The player will compete against the computer which represents...

  • Java programing Write a program that deals a deck of card into 4 hands – Each...

    Java programing Write a program that deals a deck of card into 4 hands – Each hand having 13 cards. The program should be doing the followings use an array to randomly select 52 cards and deal it into 4 hands. Print each hand unsorted Identify the face value of each hand and display it. You should create a class called Card, and all the methods should be defined within the card class. Hints – Import below java utility to...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT