This week you will continue your Five Crowns program. 1. Print the hands. 2. Cre
ID: 3594974 • Letter: T
Question
This week you will continue your Five Crowns program.
1. Print the hands.
2. Create a sort algorithm in your object Hand that does the following:
a. Step through each card of the hand. Compare each pair of adjacent items and swap them if they are in the wrong order. You are comparing face values. Once face values are the same, sort by suit in alphabetical order. An example hand, sorted, is: 3c 3h 3stars 6c 9c 9spades 10d Jd Qd
b. Pass through the list until no swaps are needed, which means that your hand is sorted.
c. Google bubble sort for more info on this algorithm.
3. Print the sorted hands.
//Please help by providing the code so I can further understand (in C++)
//the beginning of the program was built by this:
Part 1
This week you will create the beginnings of a Five Crowns program (this is a card game). This program will be built on in future projects.
1. You will create a deck of 116 cards (suggested implementation: a vector. This allows you to use push_back to add each card to the vector).
a. You should create a class Card that contains the following:
i. Data members face and suit, of type int.
ii. A constructor that receives two ints representing face and suit and uses them to initialize the data members.
b. A toString function that returns a string in the form “face of suit” (eg. “three of spades.”) c. Two const arrays of strings representing faces and suits.
2. After you create the deck, print it out.
3. Then you will shuffle the deck. Here is a suggested algorithm for shuffling: Iterate through the array of Cards. For each Card, randomly select another card in the deck and swap the two Cards.
4. Once you have shuffled, print the deck again.
5. This assignment should have THREE separate files: header, implementation, and main. Here are the details on the 116-card deck:
1. There are five suits: a. Clubs b. Diamonds c. Hearts d. Spades e. Stars
2. Numbers of cards:
a. There are 10 (2 of each suit) of 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King. (i.e. no twos and no aces). (This adds up to 110 cards).
b. There are six Jokers.
3. Point values:
a. Threes have 3 points, fours have 4 points, and so on up to 10 (5 – 5, 6 – 6, 7 – 7, 8 – 8, 9 – 9, 10 – 10)
b. Jacks have 11 points.
c. Queens have 12 points.
d. Kings have 13 points.
e. Jokers have 20 points.
Part 2
This week you will continue your work on the Five Crowns program.
1. You will create an object Deck that consists of the following:
a. The vector of 116 cards from last week’s program.
b. bool operator == that overloads the == operator to check if two cards are equal.
c. bool operator <that overload the < operator and checks to see if the face value of one
card is less than the face value of another.
2. An object Hand that consists of the following:
a. An array (or vector – your choice) of nine cards from last week’s program.
3. Program main that will do the following:
a. Create the deck.
b. Print the deck.
c. Shuffle the deck.
d. Prompt the user for the number of players, and accept a value from 2 to 7.
e. Deal hands of nine cards to each player.
f. Print the hands.
g. Evaluate each hand. Determine if any cards are equal to each other and print the result.
Explanation / Answer
% Language : Matlab 2007a
% Authors : Autar Kaw
% Last Revised : November 8, 2009
% Abstract: This program shows you how to put a vector
% of numbers in an ascending order using the bubble sort method
clc
clear all
disp(‘This program shows the bubble sort method’)
disp(‘to put a vector of numbers in an ‘)
disp(‘ascending order’)
disp(‘Matlab 2007a’)
disp(‘Authors : Autar Kaw’)
disp(‘Last Revised : November 8, 2009’)
disp(‘http://numericalmethods.eng.usf.edu’)
disp(‘ ‘)
%% INPUTS
% The vector of numbers
disp (‘INPUTS’)
disp(‘Input the vector of numbers’)
A=[18 7 6 15 4 13];
disp(A)
%% SOLUTION
% Number of entries, n
n=length(A);
% making (n-1) passes
for j=1:1:n-1
% comparing each number with the next and swapping
for i=1:1:n-1
if A(i)>A(i+1);
% temp is a variable where the numbers are kept
% temporarily for the switch
temp=A(i);
A(i)=A(i+1);
A(i+1)=temp;
end
end
end
%% OUTPUT
disp(‘ ‘)
disp (‘OUTPUT’)
disp (‘The ascending matrix is’)
disp(A)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.