Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help C++ Need Help C(Card Game) We'll continue the Crazy 8's implementation here Requirements: This time, we will implement a few utility template functions

Need help C++

image text in transcribed

Need Help C(Card Game) We'll continue the Crazy 8's implementation here Requirements: This time, we will implement a few utility template functions that will help with the implementation of the deck, plus a driver to test them. You may modify the Card class. You will need only card h from the existing files. Note: perhaps unsurprisingly, if we weren't trying to practice writing generic Ccode, we'd probably use some of the C++ library code that handles much of this. You are not allowed to use the shuffle) from the C+ libraries, but you can use other code to help you.] 1. This code is to be placed in "util h" (and, optionally. "util.cpp") 2. You will have several choices in this assignment. The first choice you have is that you can write the functions as global functions or as static functions within a class 3. pairUp0 a. this function is going to return a vector of Card, constructed by pairing up ranks and suits b. the required parameters will represent two lists with generic element types. You can represent the lists using arrays and their lengths (4 parameters) or using two vectors c. The simplest version can use just the one generic type (this would be the T") for the type used for rank and suit. You could use 2 generic types, one for the rank and one for the suit. This would let you modify those types more easily. It constructs Card's, so it's not really useful beyond this program, but it is completely acceptable for your submission. d. For a more generic and useful function, you can avoid using "Card in the code. You can do this by adding another generic type parameter, which I'11 call R" below. Instead of creating a Card to the result for each pair, create an R to add. The catch is that the compiler does not have enough information from the existing parameters to determine what you mean by R. You can solve this by passing in an extra parameter of type R. The function will not actually use this parameter's value, so it's only purpose is to let the compiler figure out the desired return type 4. shuffle0 a. this function should take a reference to a vector of a generic type and mix up the order of the elements b. you can come up with your own algorithm to mix up the elements, but here is a simple one you can use: randomly generate two index values and swap the elements at those positions. Repeat this as many times as desired. c. You will probably find it convenient to modify the Card class to support the = operator or a copy constructor. 5. printList0 a. this function will display the contents of a vector b. you do not have to make it generic you can declare that it wll take a vector of Card and just print them out c. if you make it generic, you may find a toString0 function in Card is convenient 6. The driver should, as usual, test the above code. a. Create a list of ranks and a list of suits. You may find it convenient for now to use only a few ranks and a few suits since you just want to make sure the functions work. b. Use pairUpO to create a vector Card of these ranks and suits. c. Use printListO to display the contents d. Use shuffle0 to shuffle the list e. Use printListO to display the shuffled list Grading pairUp 20% shuffle 20% printList 20% driver 20% Comm ents count for l0%; something for each file class, som ething or each method function other comments to explain parts of the code when it's not clear Choosing appropriate names for variables, functions, constants, classes counts for 10%

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

58. Is it true that ? Explain.

Answered: 1 week ago