

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


// CS 145 - Section 002 // Programming Assignment #4 - Functions //// // // // YOUR DESCRIPTIVE COMMENT (AT LEAST ONE PARAGRAPH) GOES HERE! ////////////////////////////////////////////////////////////////////// // #include #include <iostream.h><stdlib.h> #include <time.h> int dealCard(); int bool generateRandomNumber( checkForDuplicate(intint newCard, lowerBound, int oldCard);int upperBound); bool checkForDuplicate(int newCard, int oldCard1, int oldCard2); bool bool checkForDuplicate(checkForDuplicate(intint newCard,newCard, intint oldCard1,oldCard1, intint oldCard2,oldCard2, intint oldCard3);oldCard3, int oldCard4); void void displayHand(displayOneCard(int (^) intcard1, card); int card2, int card3, int card4, int card5); char rank(int card); char bool suit(containsFullHouse(int card); int card1, int card2, int card3, int card4, int card5); // The main function deals poker hands repeatedly, // // until a hand containing a full house is dealt. At // // that point, the number of dealt hands is output. void main() // { int int card1;card2; int card3; int int card4;card5; int count = 0; bool foundFullHouse = false; while { (!foundFullHouse) count++; card1 = dealCard(); card2 = dealCard(); while (checkForDuplicate(card2, card1)) card2 = dealCard(); card3 = dealCard(); while (checkForDuplicate(card3, card1, card2)) card3 = dealCard(); card4 = dealCard(); while card4 = dealCard(); (checkForDuplicate(card4, card1, card2, card3)) card5 = dealCard(); while (checkForDuplicate(card5, card1, card2, card3, card4)) card5 = dealCard(); displayHand(card1, card2, card3, card4, card5); foundFullHouse = containsFullHouse(card1, card2, card3, card4, card5); } cout << "A full house was dealt" << endl << "after " << count << " attempts!" << endl << endl; return; }
int { dealCard() //YOUR CODE GOES HERE! // } // This function generates a pseudorandom integer // // between the values of the two parameters. // int generateRandomNumber(int lowerBound, int upperBound) { static bool firstTime = true; long int randomNumberSeed; if (firstTime) { time(&randomNumberSeed); srand(randomNumberSeed); }^ firstTime =^ false; }^ return^ (lowerBound +^ int((upperBound - lowerBound) * (float(rand()) / RAND_MAX))); // YOUR DESCRIPTIVE COMMENT GOES HERE! // bool checkForDuplicate(int newCard, int oldCard) { }^ // YOUR CODE GOES HERE! // // YOUR DESCRIPTIVE COMMENT GOES HERE! // bool checkForDuplicate(int newCard, int oldCard1, int oldCard2) { }^ // YOUR CODE GOES HERE! // // YOUR DESCRIPTIVE COMMENT GOES HERE! // bool checkForDuplicate(int newCard, int oldCard1, int oldCard2, int oldCard3) { // YOUR CODE GOES HERE! // } // YOUR DESCRIPTIVE COMMENT GOES HERE! // bool checkForDuplicate(int newCard, int oldCard1, int oldCard2, int oldCard3, int oldCard4) { // YOUR CODE GOES HERE! // } // YOUR DESCRIPTIVE COMMENT GOES HERE! // void displayHand(int card1, int card2, int card3, int card4, int card5) { }^ // YOUR CODE GOES HERE! // // YOUR DESCRIPTIVE COMMENT GOES HERE! void displayOneCard(int card) // { }^ // YOUR CODE GOES HERE! // // This function determines the rank of a card by converting // // the number representing the card into a number from 1 to // // 13, and using 13 to represent a "King", 12 to represent a // // "Queen", and so on down to 1 to represent an "Ace". // char rank(int card) { int value; value = 1 + (card - 1) % 13; if (value == 1) return 'A'; else if (value == 10) else^ return if (value == 11)^ 'T'; return 'J'; else return if (value == 12) 'Q'; else if (value == 13) else^ return^ 'K'; return char(value - 2 + int('2')); } // This function determines the suit of a card by converting // the number representing the card into a character that //// // corresponds to "Hearts", "Diamonds", "Spades", or "Clubs". // char { suit(int card) int value; value = 3 + (card - 1) / 13; return char(value); } // YOUR DESCRIPTIVE COMMENT GOES HERE! // bool containsFullHouse(int card1, int card2, int card3, int card4, int card5) { // YOUR CODE GOES HERE! // }