Question
C++, Skat Game sortSuit and sortFace This is my code: //main.cpp #include #include #include #include SkatGame.h using namespace std; int main() { const int loops
C++, Skat Game sortSuit and sortFace
This is my code:
//main.cpp
#include
using namespace std;
int main() { const int loops = 1000000; double sum;
int count = 0; SkatGame Skat; Card* card;
for (int i = 0; i < 5; i++) { Skat.shuffle(); Skat.deal(); Skat.getSkat(); Skat.toString(); }
for (int i = 0; i < loops; i++) {
Skat.shuffle(); Skat.deal(); card = Skat.getSkat();
if (card[0].getFace() == "Bube" || card[1].getFace() == "Bube") {
count++; } }
cout << "Bei einer Million betrachteten Spielen ist bei " << count << " Spielen " << endl; cout << "mindestens ein Bube im Skat. " << endl;
sum = (static_cast
system("pause"); return 0; }
//skatGame.cpp #include
using namespace std;
enum face { sieben, acht, neun, zehn, Bube, Dame, Koenig }; enum Suit { Kreuz, Pik, Herz, Karo };
SkatGame::SkatGame() { int i,j,k = 0; face faces; Suit Suits;
for (int i = 0; i != 3; i++) { for (int j = 0; j != 7; j++) { faces = static_cast
void SkatGame::shuffle() { Card mem; int pos;
for (int i = 0; i < 32; i++) { pos = 1 + rand() % 32; mem = deck[i]; deck[i] = deck[pos]; deck[pos] = mem; } }
void SkatGame::deal() { int pos = 0; for (int i = 0; i < 10; i++) { player1[i] = deck[pos]; pos++; }
for (int i = 0; i < 10; i++) { player2[i] = deck[pos]; pos++; }
for (int i = 0; i < 10; i++) { player3[i] = deck[pos]; pos++; }
for (int i = 0; i < 2; i++) { skat[i] = deck[pos]; pos++; }
}
//void SkatGame::print() const string SkatGame::toString() { cout << "Karten fuer: " << endl << endl; cout << setw(15) << "Spieler 1 " << setw(15) << "Spieler 2 " << setw(15) << "Spieler 3 " << setw(15) << "Skat " << endl << setw(15) << "--------- " << setw(15) << "--------- " << setw(15) << "--------- " << setw(15) << "---- " << endl;
for (int i = 0; i < 10; i++) { cout << setw(15) << player1[i].toString() << setw(15) << player2[i].toString() << setw(15) << player3[i].toString(); if (i == 0 || i == 1) { cout << setw(15) << skat[i].toString(); } cout << endl; } cout << endl << endl; };
Card* SkatGame::getSkat() { return skat; }
//card.cpp #include
Card::Card() {};
Card::Card(Suit suit, Face face) {face = Face; suit =Suit;};
Suit Card::getSuit() const //Ausgabe Farbe { return suit; }
Face Card::getFace() const //Ausgabe Wert { return face; }
string Card::toString() const // Ausgabe Blatt des Spielers { string output; output = getFace() + " " + getSuit(); return output; }
//Card.h #include
using std::string;
class Card { public: Card (); Card (Suit, Face); Suit getSuit() const; Face getFace() const; string toString() const;
private: enum Suit suit; enum Face face; };
Can some one help me out to work this sort function and code???
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started