Kat H.

asked • 05/24/21

Suits. The starter code below has code to keep track of the suits in a card game.

The starter code below has code to keep track of the suits in a card game. They are defined in an order such that clubs are the best suit (highest number), followed by diamonds, spades and then hearts. It will read in the names of two suits, decide which is the winning suit, then print it out.

Your job is to add two functions:

  1. Suit getSuit(const string& s) : turns a string like "Spade" or "Heart" into an enumerated value
  2. string getSuitName(Suit s) : given an enumerated value, return the corresponding string. Hint: the SUIT_NAMES array can help make this a one-line function.


Code:


#include <iostream>


using namespace std;


enum Suit { HEART, SPADE, DIAMOND, CLUB };

const string SUIT_NAMES[] = {"Heart", "Spade", "Diamond", "Club"};


//Do not modify anything on or above the line below this

//YOUR_CODE_BELOW


//YOUR_CODE


//YOUR_CODE_ABOVE

//Do not modify anything on or below the line above this



int main()

{

//get two suits to compare

string suit1Name, suit2Name;

cin >> suit1Name >> suit2Name;


Suit s1 = getSuit(suit1Name);

Suit s2 = getSuit(suit2Name);


//The one with larger numberic value is winner

Suit winner = max(s1, s2);


cout << getSuitName(winner) << endl;

}

1 Expert Answer

By:

Patrick B. answered • 05/24/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.