100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Card.cpp Project University of Michigan EECS 280 $9.49   Add to cart

Exam (elaborations)

Card.cpp Project University of Michigan EECS 280

 5 views  0 purchase
  • Course
  • Institution

// Project UID 1d9f47bfccfbfdefe1 #include <cassert> #include <iostream> #include <string> #include "Card.h" // add any necessary #include or using directives here // rank and suit names -- do not remove these constexpr const char* const Card::RANK_TWO; constexpr const cha...

[Show more]

Preview 2 out of 6  pages

  • February 11, 2023
  • 6
  • 2022/2023
  • Exam (elaborations)
  • Questions & answers
avatar-seller
// Project UID 1d9f47bfc76643019cfbf037641defe1

#include <cassert>
#include <iostream>
#include <string>
#include "Card.h"
// add any necessary #include or using directives here

// rank and suit names -- do not remove these
constexpr const char* const Card::RANK_TWO;
constexpr const char* const Card::RANK_THREE;
constexpr const char* const Card::RANK_FOUR;
constexpr const char* const Card::RANK_FIVE;
constexpr const char* const Card::RANK_SIX;
constexpr const char* const Card::RANK_SEVEN;
constexpr const char* const Card::RANK_EIGHT;
constexpr const char* const Card::RANK_NINE;
constexpr const char* const Card::RANK_TEN;
constexpr const char* const Card::RANK_JACK;
constexpr const char* const Card::RANK_QUEEN;
constexpr const char* const Card::RANK_KING;
constexpr const char* const Card::RANK_ACE;

constexpr const char* const Card::SUIT_SPADES;
constexpr const char* const Card::SUIT_HEARTS;
constexpr const char* const Card::SUIT_CLUBS;
constexpr const char* const Card::SUIT_DIAMONDS;

Card::Card() {
rank = RANK_TWO;
suit = SUIT_SPADES;
}

//REQUIRES rank is one of "Two", "Three", "Four", "Five", "Six", "Seven",
// "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"
// suit is one of "Spades", "Hearts", "Clubs", "Diamonds"
//EFFECTS Initializes Card to specified rank and suit
Card::Card(const std::string& rank_in, const std::string& suit_in) {
rank = rank_in;
suit = suit_in;
}

//EFFECTS Returns the rank
std::string Card::get_rank() const {
return rank;
}


//EFFECTS Returns the suit. Does not consider trump.
std::string Card::get_suit() const {
return suit;
}

//REQUIRES trump is a valid suit
//EFFECTS Returns the suit
//HINT: the left bower is the trump suit!
std::string Card::get_suit(const std::string& trump) const {
if (rank == RANK_JACK && suit == Suit_next(trump)) {
return trump;
}
else
return suit;
}


This study source was downloaded by 100000850872992 from CourseHero.com on 02-10-2023 23:27:02 GMT -06:00


https://www.coursehero.com/file/89322978/Cardcpp/

, //EFFECTS Returns true if card is a face card (Jack, Queen, King or Ace)
bool Card::is_face() const {
if (rank == RANK_JACK) {
return true;
}
if (rank == RANK_QUEEN) {
return true;
}
if (rank == RANK_KING) {
return true;
}
if (rank == RANK_ACE) {
return true;
}
else
return false;
}

//REQUIRES trump is a valid suit
//EFFECTS Returns true if card is the Jack of the trump suit
bool Card::is_right_bower(const std::string& trump) const {
if (rank == RANK_JACK && suit == trump) {
return true;
}
return false;
}

//REQUIRES trump is a valid suit
//EFFECTS Returns true if card is the Jack of the next suit
bool Card::is_left_bower(const std::string& trump) const {
if (rank == RANK_JACK && suit == Suit_next(trump)) {
return true;
}
return false;
}

//REQUIRES trump is a valid suit
//EFFECTS Returns true if the card is a trump card. All cards of the trump
// suit are trump cards. The left bower is also a trump card.
bool Card::is_trump(const std::string& trump) const {
if (suit == trump || is_left_bower(trump)) {
return true;
}
return false;
}


int get_suit_names_by_weight(const Card card) {
std::string suit = card.get_suit();
for (int i = 0; i < NUM_SUITS; ++i) {
if (suit == SUIT_NAMES_BY_WEIGHT[i]) {
return i;
}
}
return false;
}

int get_rank_names_by_weight(const Card card) {
std::string rank = card.get_rank();
for (int i = 0; i < NUM_RANKS; ++i) {
if (rank == RANK_NAMES_BY_WEIGHT[i]) {
return i;
}
}

This study source was downloaded by 100000850872992 from CourseHero.com on 02-10-2023 23:27:02 GMT -06:00


https://www.coursehero.com/file/89322978/Cardcpp/

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller ExamsConnoisseur. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $9.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

77333 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$9.49
  • (0)
  Add to cart