Question: I'm, asking to implement a C++ class template that simulates a deck of cards that can be used in a card game. The Deck class
I'm, asking to implement a C++ class template that simulates a deck of cards that can be used in a card game. The Deck class should use a template argument for the Card class as the base type of the template. The Deck class should support initiation, draw from the top, and shuffle. The Deck class should be implemented as a singly-linked list.
The Card class should have methods for getting and setting the card value. The Deck class should be implemented as a C++ class template, which means that it should be able to handle any type of card as a template argument. The Deck class should support initiation, draw from top, shuffle, and other fundamental operations. The Deck class should be implemented as a singly-linked list, which means that each card in the deck should be represented as a node in the list. The class template should be in its own header file. Do not use cpp file to keep it simple. You are provided with a test suite in the folder test/. Your implementation must pass all tests provided in this test suite. Read these files to get a better understanding of the requirement. 

Here is the provided card.hpp file: 
Here is a test that will be run against the code for an example called test-1-deck.cpp:

Card Class Template Provided in the card.hpp file as a class template. Its base type can be int, string, etc. Deck Class Template The Deck class template should have the features. 1. It is a singly-linked list with the Card class as its node. 2. It should have the following methods: - The default constructor to initialize an empty deck - The destructor to release the memory - The rest of big three are not required. Do not waste time on them. - The void addCard(T value) method to add a card with a value to the beginning of the deck. - The T drawCard() method to remove and return the value of the first card in the deck. Your program should exit if the deck is empty. Print error message to cout in that case. - The method to return the current size of the deck. - The method to shuffle the deck. Algorithm will be explained after. 3. You can decide all other private instance variables. Think about: - Do you need a tail pointer? - Do you need a size variable? - You will need a random number generation algorithm in the shuffling process. The std: :srand function is part of the C standard library, and it's used to seed the random number generator that's used by functions like std: : rand. The basic idea is that you call std: :srand with an integer value, which sets the initial seed value for the random number generator. Then, when you call std: : rand, it generates a pseudo-random number based on the current seed value. You can then use the modulo operator on N to convert the random number to the range of 1 to N. - The shuffling algorithm used in the solution is called the Fisher-Yates shuffle (also known as the Knuth shuffle or the Durstenfeld shuffle). This algorithm shuffles an array (or in our case, a linked list) in-place by iterating over the elements of the array and swapping each element with a randomly chosen element that comes after it. Below is the example on an array. - For linked list, you cannot use [] syntax anymore but you can make a private function to find the pointer to the i-th card object. Then, use getValue and setValue of the Card class to do the value swapping. This method may look like Card T getcardAt (int index) Card Class Template Provided in the card.hpp file as a class template. Its base type can be int, string, etc. Deck Class Template The Deck class template should have the features. 1. It is a singly-linked list with the Card class as its node. 2. It should have the following methods: - The default constructor to initialize an empty deck - The destructor to release the memory - The rest of big three are not required. Do not waste time on them. - The void addCard(T value) method to add a card with a value to the beginning of the deck. - The T drawCard() method to remove and return the value of the first card in the deck. Your program should exit if the deck is empty. Print error message to cout in that case. - The method to return the current size of the deck. - The method to shuffle the deck. Algorithm will be explained after. 3. You can decide all other private instance variables. Think about: - Do you need a tail pointer? - Do you need a size variable? - You will need a random number generation algorithm in the shuffling process. The std: :srand function is part of the C standard library, and it's used to seed the random number generator that's used by functions like std: : rand. The basic idea is that you call std: :srand with an integer value, which sets the initial seed value for the random number generator. Then, when you call std: : rand, it generates a pseudo-random number based on the current seed value. You can then use the modulo operator on N to convert the random number to the range of 1 to N. - The shuffling algorithm used in the solution is called the Fisher-Yates shuffle (also known as the Knuth shuffle or the Durstenfeld shuffle). This algorithm shuffles an array (or in our case, a linked list) in-place by iterating over the elements of the array and swapping each element with a randomly chosen element that comes after it. Below is the example on an array. - For linked list, you cannot use [] syntax anymore but you can make a private function to find the pointer to the i-th card object. Then, use getValue and setValue of the Card class to do the value swapping. This method may look like Card T getcardAt (int index)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
