50 points Create a standard deck of 52 playing cards and list those cards on the
ID: 3569438 • Letter: 5
Question
50 points
Create a standard deck of 52 playing cards and list those cards on the screen, columns makes my life easier :-) Pause or "press Enter" after the unshuffled deck is displayed.
"Shuffle" the deck and list the shuffled deck on the screen. random_shuffle from <algorithm> will work on a vector of Cards
Sort (by rank) and evaluate evaluate the first 5 cards of the deck as a 'hand'. Print the unsorted, then the sorted hand.
a pair (say the card rank, like Pair of Queens)
two pair (say something like Pair of Queens and Pair of Twos)
three of a kind (say something like Three Kings)
full house (say something like Full house, Jacks over fours)
straight (say Ace-high straight) A straight is all 5 cards in rank order, ace can be high or low
four of a kind
flush (say something like spades flush)
Ideas:
create a Card class with an internal 'Rank' (A, 2, 3, 4, ..) and 'Suit' (spades, diamonds ...)
Here's one possible idea for a card class (Card.h)
#ifndef CARD_H
#define CARD_H
#include <string>
using namespace std;
class Card
{
public:
Card();
// set and get the rank, 2=2, 3=3, ... 10=10, 11=J, 12=Q, 13=K, 14=A
void setRank(int r);
int getRank();
// set and get the suit, 1=Spades, 2=Hearts, ...
void setSuit(int r);
int getSuit();
// for debugging, print the suit and rand as integers
void print();
// return the rank and suit as a 'nice' looking string
string toString();
// if you want to use sort() in the STL
bool operator<(const Card &c) const {return myRank < c.myRank;}
private:
int myRank;
int mySuit;
};
#endif // CARD_H
If you want to use the builtin sort alogrithm with the above class, use:
vector<Card> hand;
/// make sure to put cards in the hand here!
sort(hand.begin(), hand.end());
Explanation / Answer
A=0;
x=0;
n=input('How many variables=');
disp('Enter the coefficients along with constants For instance if x+y+3z=-5 then enter 1 1 3 -5 each number followed by an enter not space');
for i=1:n
for j=1:n+1
A(i,j)=input('');
end
end
%pivoting
for i=1:n-1
for j=i+1:n
if abs(A(j,i))>abs(A(i,i))
T=A(j,:);
A(j,:)=A(i,:);
A(i,:)=T;
end
end
end
disp('After pivoting');
disp(A);
for k=1:n-1
for i=k+1:n
m=A(i,k)/A(k,k);
for j=k:n+1
A(i,j)=A(i,j)-m*A(k,j);
end
end
end
disp('Triangularize Form ');
disp(A);
if A(n,n)==0
disp('No unique solution');
end
x(n)=A(n,n+1)/A(n,n);
for j=n-1:-1:1
sum=0;
for i=1:n
sprintf('x%.0f=%.10f',i,x(i))
end
for i=1:n-j
sum=sum+A(j,n+1-i)*x(n+1-i);
end
x(j)=(A(j,n+1)-sum)/A(j,j);
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.