Question: Part A . [ 4 mark ] Initializing a Sequence of Cards Your first task is to write a program that can initialize a sequence
Part A mark Initializing a Sequence of Cards
Your first task is to write a program that can initialize a sequence of cards, which is used for playing the simple UNO game. The program takes one integer from the user and it is the seed for the card sequence generation. As shown in the following Table the value of seed is from to and each seed corresponds to one specific sequence. Then it prints the entire sequence of cards. We provide a skeleton of code in the file asgskeletonpartA.cpp and you need to complete the program.
Now to begin, a card has three attributes: color, value and number. There are colors with their corresponding values: Red with value Yellow with value Blue with value and Green with value There are numbers: the integers from to A card is combined with one color and one number randomly, such as Red Yellow Blue and Green
A class called Card is provided in the skeleton code, with the above attributes defined as private members. Color is a pointer to char, ie char or equivalently cstrings. Some access function prototypes are also defined. There is also a prototype of the default constructor. You need to implement these access functions and the default constructor in order to complete the class definition of Card.
To initialize a sequence of cards, you need to implement one function. A sequence is simply an array of Card objects as you can see in main The initSequenceCard cardSeq, char colorName int j int num is the function to initialize the sequence of cards. For one sequence, there are cards. When you create each card, you should first set its value and its color according to the value as shown in Table Then, combining the color with the number, you can get a card. Note that the sequence is passed to the function as a pointer Card and you should not change this.
We provide a help function called printSequence which simply takes the sequence again as a pointer and prints each Card object sequentially. This is called in main to check output of your code. Notes:
Based on skeleton code, complete the class definition of Card.
You are not allowed to delete any part of the skeleton code.
Do not add move attributes or member functions.
Finish all the default constructor or functions.
Table is shown below.
Sample Input and Output
Example
Enter the seed for random number generation:
Yellow Blue Yellow Blue Blue Yellow
Example
Maresen Vioul Shode Dutug Censole
Enter the seed for random number generation:
Green Red Yellow Blue Bluel Blue
Example
Enter the seed for random number generation:
Blue Green Blue Red Red Blue
#include
#include
using namespace std;
class Card
public:
Card;
void setColorchar n;
void setValueint v;
void setNumint num;
char getColor;
int getVal;
int getNum;
private:
char color;
int value;
int number;
;
Add your code here.
You need to implement these access functions and the default constructor in
order to complete the class definition of Card.
void initSequenceCard cardSeq, char colorName int j int num;
void printSequenceCard cardSeq;
int main
Add your code here.
initSequencecardSeq colorName, j num;
printSequencecardSeq;
return ;
Add your code here.
You need to implement initSequenceCard cardSeq, char colorName int j
int num function.
Add your code here.
You need to implement printSequenceCard cardSeq function.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
