Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Card.cpp Project University of Michigan EECS 280

Rating
-
Sold
-
Pages
6
Grade
A+
Uploaded on
11-02-2023
Written in
2022/2023

// 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 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;

Show more Read less
Institution
Course

Content preview

// 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/

Written for

Course

Document information

Uploaded on
February 11, 2023
Number of pages
6
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$9.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ExamsConnoisseur Self
Follow You need to be logged in order to follow users or courses
Sold
587
Member since
3 year
Number of followers
344
Documents
1492
Last sold
1 week ago

4.2

68 reviews

5
40
4
11
3
13
2
1
1
3

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions