Write a function called card namer that takes two single character strings, repr
ID: 3586654 • Letter: W
Question
Write a function called card namer that takes two single character strings, representing the value and suit of a card following the shorthand below, and returns the full name of the card. Some sneaky cheaters have been trying to slip in fake cards, like the 9 of triangles. So if the suit input isn't one of the recognized inputs the function should return CHEATER! You may assume that value will be always be a valid input. Input Value Input Suit I) Ace Diamonds Clubs Hcarts Spades 2..92 .. 9 10 Jack Queen KingExplanation / Answer
#include<iostream>
using namespace std;
string card_namer(string a, string b){
string res = "CHEATER!";
if (a.size() == 1 && b.size() == 1){
if (a[0] >= '2' && a[0] <= '9'){
if (b[0] == 'D'){
res = a + " " + "Diamonds";
}
if (b[0] == 'H'){
res = a + " " + "Hearts";
}
if (b[0] == 'S'){
res = a + " " + "Spades";
}
if (b[0] == 'C'){
res = a + " " + "Clubs";
}
}
if (a[0] == 'A'){
if (b[0] == 'D'){
res = "Ace Diamonds";
}
if (b[0] == 'H'){
res = "Ace Hearts";
}
if (b[0] == 'S'){
res = "Ace Spades";
}
if (b[0] == 'C'){
res = "Ace Clubs";
}
}
if (a[0] == 'T'){
if (b[0] == 'D'){
res = "10 Diamonds";
}
if (b[0] == 'H'){
res = "10 Hearts";
}
if (b[0] == 'S'){
res = "10 Spades";
}
if (b[0] == 'C'){
res = "10 Clubs";
}
}
if (a[0] == 'J'){
if (b[0] == 'D'){
res = "Jack Diamonds";
}
if (b[0] == 'H'){
res = "Jack Hearts";
}
if (b[0] == 'S'){
res = "Jack Spades";
}
if (b[0] == 'C'){
res = "Jack Clubs";
}
}
if (a[0] == 'Q'){
if (b[0] == 'D'){
res = "Queen Diamonds";
}
if (b[0] == 'H'){
res = "Queen Hearts";
}
if (b[0] == 'S'){
res = "Queen Spades";
}
if (b[0] == 'C'){
res = "Queen Clubs";
}
}
if (a[0] == 'K'){
if (b[0] == 'D'){
res = "King Diamonds";
}
if (b[0] == 'H'){
res = "King Hearts";
}
if (b[0] == 'S'){
res = "King Spades";
}
if (b[0] == 'C'){
res = "King Clubs";
}
}
}
return res;
}
int main(){
string value;
string suit;
cout << "Enter two characters specifying the value and suit:";
cin >> value >> suit;
cout << card_namer(value,suit) << endl;;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.