Question: Please I need this program in C++. I already did the drawing. Im just stuck on writing the code in the 2 first pictures are
Please I need this program in C++.
I already did the drawing.
Im just stuck on writing the code
in the 2 first pictures are what the project is asking and the 4 lasts pictures are the p1.cpp file that needs to completed for the project
Here's the p1.cpp file
// Project 1 Assignment File // CREATE A COMPLETE ID BLOCK
#include
using namespace std;
enum Rank {Ace,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King}; enum Suit {Clubs,Diamonds,Spades,Hearts};
struct Card { Rank rank; Suit suit; };
void readIn(ifstream &inf, Card theHand[], int &totalCards); void processCardRanks(Card theHand[], int totalCards, int rank[]); void processCardSuits(Card theHand[], int totalCards, int suit[]); Rank getRank(int cardValue); Suit getSuit(int cardValue); void printHand(Card theHand[], int totalCards); void printCard(Card theCard); Card int2Card(int value); void rankReport(int rank[]); void suitReport(int suit[]); ostream &operator
int main() { Card theHand[52]; int totalCards=0; int rank[13]={0}; int suit[4]={0}; ifstream file;
// COMPLETE main() }
//Function: openFile() // Description: // Parameters: // Return Value:
// WRITE openFile() HERE
// Function: readIn() // // Description: The function "readIn()" gets passed the file that was opened // and an array of Card struct named "theHand". // Using a while loop, the file is read into the variable theHand, one card at // a time, while keeping count of the total cards input. // // Parameters: ifstream inf - IMPORT - file // Card theHand[] - EXPORT - array of Card object // int totalCards - IMPORT/EXPORT - # number of cards // // Return Value: NONE void readIn(ifstream &inf, Card theHand[], int &totalCards) { int value; while( inf >> value) theHand[totalCards++]=int2Card(value); }
// Function: processCardRanks() // Description: processCardRank() finds out how many cards belong to each rank. // Parameters: Card theHand[] - IMPORT - card int value // int totalCards - IMPORT - # number of cards // int rankCounts - EXPORT - # of ranks // Return Value: NONE void processCardRanks(Card theHand[], int totalCards, int rankCounts[]) { int i; for(i=0; i
// Function: processCardSuits(), complete with documentation, is to be written here
// Function: getRank() is to be written here
// Function: getSuit() // Description: // Parameters: // Return Value: Suit getSuit(int cardValue) { return((Suit)(cardValue / 13)); }
// Function: printCard() // Decription: The function "printCard()" gets passed "theCard" struct and outputs the card. // Parameters: Card theCard - IMPORT - card rank, card suit // Return Value: NONE void printCard(Card theCard) { cout
// Function: printHand() is to be written here
// Function: int2Card() // Description: int2Card finds the cards rank and suit by utilizing getRank() // and getSuit() and then returns a Card struct. // Parameters: int value - IMPORT - card # // Return Value: struct Card int2Card(int value) { Card theCard; theCard.rank = getRank(value); theCard.suit= getSuit(value); return theCard; }
// Function: rankReport() // Description: rankReport() outputs the ranks that had one or more entries // within the hand and the rank or ranks with the greatest number of cards. // Parameters: int rank[] - IMPORT - # of cards in each rank // Return Value: NONE void rankReport(int rank[]) { const string rankString[13]={"Ace","Two","Three","Four","Five","Six", "Seven","Eight","Nine","Ten","Jack","Queen","King"}; int max = 0; // Tracks the largest number of cards in any rank bool multi; // Used to record if two or more ranks have max cards cout
// ADD CODE HERE }
// Function: suitReport() // ADD DOCUMENTATION HERE void suitReport(int suit[]) { const string suitString[]={ /* FILL IN SUIT NAMES AS STRINGS */ }; string suitName; int suitsRepresented=0;// Used to count how many different suits in Card array
// ADD CODE HERE }
// Function: operator
// Function: operator





Purpose: Review of material from CS 135; intro to data structures (structures) Points: Program: 20 Drawings: 5 Due: See Deliverables. No late submissions accepted. Description: Read and process a hand of cards of indeterminate length held in a file. For your first project, you will complete a program provided to you (file name: pl.cpp) by finishing some functions and writing some others. You will be provided some documentation and will write some. Several functions will be provided in complete form Your program will initially prompt the user for a file name. If the file is not found, an error message will be output and the program will terminate. Otherwise, the program will read the file, which contains values representing playing cards in a standard deck of cards. It then produces a report, detailed below. A playing card can be most basically represented using an integer in range 0-51, inclusive, which encompasses 52 values. Using the modulus (%) and division operations, ranks (A.2.3.4..10J.Q.K) and suits (clubs, diamonds. spades, and hearts) can be established, respectively. Note that any ordering of the four suits works as long as consistency is maintained. For example, the card numbered 27 is the two of spades, assuming the suit ordering given above: the rank is computed 27%13-1 and the suit is 27/13-2, where the suits are numbered 0. 1.2 and 3. A file of cards input to this program contains anywhere from 0 to 52 cards, cach represented using an integer as described. There is no set format to a file, except that it only contains integers (0 or more to a line). As the file is read, its information will be placed in an array of struct Card (name: theHand). representing the cards in the hand. As with any partially-filled array, the total items, i.e. the number of cards, an int (name: totalCards), is held as well. You will then report The Cards held in the array The number of cards in cach rank that has one or more entries (c.g. 2 Twos, 3 Fours, ..., 1 Jack....) The rank or ranks that had the greatest number of cards The suits that were represented, and the number of cards in each of those Whether all cards belonged to a single suit (only one suit with non-zero count), known as a flush To output the hand, traverse the cards using a for loop, calling a function for each one that outputs a struct of type Card. A Card has two members, both enumerated types, that represent the rank and the suit. For the remaining output requirements, two arrays of integers will be declared, one with thirteen elements and one with four elements that hold the number of cards in each rank and suit, respectively. You will then solve the problem of outputting those ranks that had one or more cards and how many, while at the same time keeping track of which rank had the largest count, and also outputting how many cards are in cach suit. As soon as two suits are non-zero, you know there wasn't a flush. Otherwise, if there weren't two suits with a non-zero count, note that the hand was a flush. Before starting work on the program, you must complete and submit several drawings to demonstrate an understanding of the design of and data held by the program. For each of the following hands provide the Card array (you need not show all 52 elements), and the arrays that hold the counts of ranks and suits: Royal flush that includes the Card with raw numeric value 37 8s over jacks full house. Suits of cards are your choice. 5 to 9 straight (at least 3 suits represented). Give the order of suits at the top of your drawing(s) and rank and suit count arrays along with the array of Card for cach hand in its drawing The program must have a function for each task. Here are the functions (name may not match name in file) Open the file: Write this function and fill in the documentation Takes an ifstream (must be a reference argument. The function prompts the user and if the file is found it returns true and the ifstream will be a handle for that text file. Otherwise the function returns false, and the other argument is assumed to be undefined The file name MUST be local to this function. . Read the file: This function is provided Takes the ifstream (still must be by reference: why?), the array of struct Card, and the card count. The function reads values in a loop, one per iteration, converting that value into a Card, placing it in the next available stor in the array and updating the card count, terminating when the file is exhausted Process Card Ranks: This function is provided, complete with documentation Takes the array of Card, the number of cards, and the array for holding counts of Tanks (name of array: runk). For each card, the counter corresponding to the card's numeric rank is incremented. Process Card Suits. You are to write this function and document is completely Takes the array of Card, the number of cards, and the amay for holding counts of suits (name of array:swil). For each card, increment the counter corresponding to the card's suit Get a card's rank: You are to write this function and document it completely Takes one value representing a playing card. Returns the card's rank as a value of type Rank . Get a card's suit: This function is provided, but requires documentation Takes one value representing a playing card. Returns the card's suit, as a value of type Sarit . Print Card: This function is provided, complete Takes a Card struct and prints the card, c.g. 7D. IC (Jack of clubs), ete; Uses the provided #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
