Question: C++ Programming: Skat Skat You shall realize an object-oriented simulation of the card game 'Skat' and with this simulation some statistical Investigate issues. (Remark: You

C++ Programming: Skat

Skat

You shall realize an object-oriented simulation of the card game 'Skat' and with this simulation some statistical Investigate issues. (Remark: You do not need to know the game of Skat to do this. Everything you know is in this assignment). Realize the class SkatGame and a supporting class Card as described in the following class diagrams:

SkatGame - deck: array - player1: array - player2: array - player3: array - skat: array + SkatGame() + shuffle(): void + deal(): void + toString(): string + getSkat(): array

Card - suit: Suit - face: Face + Card() + Card(Suit, Face) + getSuit(): Suit + getFace(): Face + toString(): string

1) It is played with 32 cards, of which each of the three players receives 10 cards. The remaining two cards remain concealed on the table ('skat'). The global constants for the array sizes therefore have the values DECK_SIZE = 32, PLAYER_SIZE = 10 and SKAT_SIZE = 2. 2) A constructor of Card is to combine the two attributes suit and face with values taken from outside for card color and card value. According to the rules of the Skat game, the enumeration types o for the card suit (enum suit) the values { KARO = 0, HEART, PIK, CROSS }, o for the card value (enum face) the values { SEVEN = 0, EIGHT, NINE, TEN, BUBE, DAME, KING, ACE }

3) toString is to separate card color and card value of the card separated by a space as a single string (e.g. "Seven of diamonds" or "Queen of hearts").

4) The constructor of SkatGame should return all 32 different cards of a Skat game (i.e. all 4 card suits (Suit) with all 8 card values (Face ) and save it in the attribute deck. Note: You can use loops with matching int-values for this purpose and store the int-values in the Transfer to the card constructor in Suit or Face casts.

5) shuffle should shuffle the cards, i.e. shuffle the 32 card objects in the array deck in a random order ...to bring.

6) deal should completely map the 32 Card objects in the array deck to the four arrays player1, player2, split player3 and skat. In the first three arrays, after the call of deal 10 of the Card objects in deck and the remaining two Card objects in skat. After all cards are distributed, the arrays player1, player2 and player3 is still sorted in ascending order as follows: All KREUZ cards are higher than all PIK cards, these are higher than all HERZ cards and these higher than all KARO cards. Within the individual colors, the order is ASS, KING, LADY, BUBE, TEN, NINE, EIGHT and SEVEN ( ACE highest and SEVEN lowest).

7) toString is intended to return all the Card objects contained in the four arrays player1, player2, player3, and skat as a string in a suitable format. This must show how the 32 cards are distributed among the three players and skat (the two remaining cards).

8) getSkat should return the array skat containing two card objects so that it can be used in the calling program.

9) Pay attention to 'const-correctness': All methods for which this is possible should be declared as const. (This is not yet considered in the class diagrams!)

The application program (main) should perform the following activities:

10) Create a SkatGame object.

11) Execute the following sequence five times: Shuffle the cards, give and deal which cards the three players and the Skat have received.

12) Shuffle and deal 10,000 times and see how many times under the two cards of the Skat at least one BUBE is included. Enter the value obtained both as an absolute value (Ex: "With 10 000 games considered, 2379 games contain at least one BUBE in Skat.") as well as a relative Frequency in percent. (Example: "23.79 percent of Skat sheets contain at least one jack in Skat").

13) Shuffle and deal 10,000 times and determine how often both cards of the Skat are BUBE. Enter the value obtained both as an absolute numerical value and as a relative frequency in percent out.

How i can add this now in my code:

sortBySuit() { //Sorts the cards in the hand so that cards of the same suit are *grouped together, and within a suit the cards are sorted by value. * Note that aces are considered to have the lowest value, 1. } sortByFace() { //Sorts the cards in the hand so that cards of the same color are grouped together.Cards with the same color are sorted by suit. }

main.cpp

#include #include #include #include #include "Header.h"

using namespace std;

int main() { enum Suit { KARO = 0, HERZ, PIK, KREUZ }; //Defintion der Farben enum Face { SIEBEN = 0, ACHT, NEUN, ZEHN, BUBE, DAME, KOENIG, ACE }; //Definition der Werte

SkatGame one; // creating the object of SkatGame one.toString(); }

Quelle.cpp

#include "Header.h" // including the header file that we have created #include #include

using namespace std;

Card::Card() {}; Card::Card(Suit gesinnung, Face Zahl) : suit(gesinnung), face(Zahl) {}; Suit Card::getSuit() // Ausgabe der Fraben { return Card::suit; } Face Card::getFace() // Ausgabe der Werte { return Card::face; } std::string Card::toString() // Ausgabe Blatt des Spielers { std::string zurueck; zurueck = std::to_string(Card::suit) + " " + std::to_string(Card::face); return zurueck; }

SkatGame::SkatGame() { int a, b, e = 0;

for (a = 0; a <= 3; a++) { for (b = 0; b <= 7; b++) { SkatGame::deck[e] = Card(static_cast(a), static_cast(b)); e++; } } } void SkatGame::shuffle() { int a, card1, card2; Card hold; for (a = 0; a < 1000; a++) { card1 = rand() % 32; card2 = rand() % 32; hold = SkatGame::deck[card1]; SkatGame::deck[card1] = SkatGame::deck[card2]; SkatGame::deck[card2] = hold; } } std::string SkatGame::toString() { int i; for (i = 0; i <= 31; i++) { std::cout << (SkatGame::deck[i]).toString() << std::endl; }; return "justatest"; }

Header.h

#include #include #include // It is non-standard but designed to cause the current source file to be included only once in a single compilation.

enum Suit { KARO = 0, HERZ, PIK, KREUZ }; //Defintion der Farben enum Face { SIEBEN = 0, ACHT, NEUN, ZEHN, BUBE, DAME, KOENIG, ACE }; //Definition der Werte

//Enum keyword is used to define enumeration. It is a user defined data type where we specify set of values for a variable and the variable can only take one out of a small set of possible values. int const SKAT_SIZE = 2; int const DECK_SIZE = 32; int const PLAYER_SIZE = 10;

class Card { public: Card(); Card(Suit, Face); Suit getSuit(); Face getFace(); std::string toString(); private: Suit suit; //enum Face face; //enum };

class SkatGame { public: SkatGame(); void shuffle(); void deal(); std::string toString(); std::array getSkat(); private: std::array deck; std::array player1; std::array player2; std::array player3; std::array skat; };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!