Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Just need help in restructuring the program by using and applying functions according to the problem description above and the given C++ code below. #include
Just need help in restructuring the program by using and applying functions according to the problem description above and the given C++ code below.
#include#include #include #include #include #include using namespace std; int main(){ srand (time(NULL)); int action = -1; //action allows us to navigate the menu, we choose 0 to exit, 1 to create a deck of cards while(action!=0){ system("CLS"); //this clears the screen cout> action; cout>size; if(size13) { cout>filename; ofstream myfile(string(filename).c_str()); if(myfile.is_open()) { for(int i=0; i You have been given a working program that outputs a shuffled deck of cards. A deck of cards has 4 suits where each suit has 13 cards ranging from Ace, King, Queen, Jack, 10..., 2. There are games using fewer than 13 cards for each suit, such as Belote. Thus, the program prompts the user to select the number of individual cards in a suit, where the minimum is five, and the maximum is 13. The program will create a shuffled deck, test to see whether the deck has four of each card and then print the deck to the screen and a file (user will insert the filename) if the test is successful. All functionality has been included in main, causing code segments to be repeated as well as diminishing the readability. Rewrite the program by grouping calculations and related operations into functions. In particular, your program should include the following functions. PrintList: This is a void function, that accepts an array, the size of the array, and a string to print the list, such as "Sorted Deck" or "Sorted Integers, as parameters. Create two functions, one that accepts an array of integers, and another that accepts an array of strings. FilePrintList: This void function, taking an array as parameter and the size of the array, and prints the array to a file, after prompting the user for a file name. Similar to the "PrintList" function, make two variations of the function, one that accepts an integer array, and another that accepts a string array. RandomInt: This is an int function (returns a random integer), that takes as a parameter an integer called ceiling. This function generates a random number between 0 and ceiling -1. It is used in the Deck Creation process and the random integer represents an index. GetSize: This is an int function, taking no parameters. It prompts the user to determine the number of individual cards in a suit. It should only accept integers in the range [5,13]. If the user enters a value outside of this range, the program should prompt the user to re-enter until a value in the appropriate range is inserted. Menu: A void function taking no parameters. It allows the user to select whether he wants to create another deck of cards or exit. It checks whether the user has inserted an invalid action. Allowed actions are (1: create deck, 0: exit). Map: This is a void function, taking an integer array as parameter, a string array, and an integer representing the size of the card deck. This function converts the contents of the integer array to strings and stores them in the string array. For example, convert 0 to "1", or 1 to "2", 10 to jack. TestDeck: This bool function goes through the generated deck before its conversion to a string array, and checks if all numbers appear exactly four times. It takes an integer array, and size of the array, as parameters. It returns true if test is passed, false otherwise. Create Deck: This is a void function that encompasses the entire deck creation process, except prompting the user for the number of individual cards. It takes a string array as parameter and user's select size of the suit (GetSizel output). This function is called when the user selects "action 1" from the menu
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