Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to find the number of 5 card hands from a standard deck of 52 ca

ID: 646752 • Letter: W

Question

Write a program to find the number of 5 card hands from a standard deck of 52 cards that satisfy the following conditions:

Containing all spades

All of the same suit

Containing cards of exactly two suits

Containing cards of all suits

Containing an Ace, 2, 3, 4 and 5 all of the same suit.

Consecutive and of the same suit. (assuming ace is the lowest card)

Consecutive (assuming ace is the lowest)

Containing three of one kind and two of another kind. (full house)

Containing two of one kind, two of a second kind and one of a third kind.

Output shall include each arrangement, as well as the sequential number and Total.

Explanation / Answer

#include<iostream>
#include<math.h>

using namespace std;

long long int factorial(int num){
if(num ==0 || num == 1){
return 1;
}

long long int fact = 1;

while(num > 1){
fact *= num;
num--;
}
return fact;
}

long long int c(int n, int k){
long long int factn = factorial(n);
long long int factk = factorial(k);
long long int factnk = factorial(n-k);

long long int res = factn/(factk * factnk);

return res;
}

int main(){
cout << "The number of 5 cards hands from a standard deck of 52 cards with following conditions are as follow : ";
cout << "Containing all spades : " << c(13 , 5) << endl;
cout << "All of the same suit : " << 4*c(13,5)<< endl;
cout << "Containing cards of exactly two suits" << << endl;
cout << "Containing cards of all suits : " << int(c(13,5) * pow(4,5))<< endl;
cout << "Containing an Ace, 2, 3, 4 and 5 all of the same suit : 4" << endl;
cout << "Consecutive and of the same suit. (assuming ace is the lowest card) : " << 4*c(13,5) - 40 << endl;
cout << "Consecutive (assuming ace is the lowest) : " << 10*pow(4,5) - 40<< endl;
cout << "Containing three of one kind and two of another kind. (full house) : " << c(13,1)*c(4,3)*c(12,1)*c(4,2) << endl;
cout << "Containing two of one kind, two of a second kind and one of a third kind : " <<c(13,1)*c(4,2)*c(12,1)*c(4,2)*c(11,1)*c(4,1) << endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote