C++ project

profiledeef
CSC275_Program1Specification_F172.docx

Due Date:

C++ Source Code: Tuesday, 10/3/2017, 11:59 PM EST.

Late penalty: -10% to max points possible per day late, no submissions accepted later than Sunday, 10/8/2017, 11:59 PM EST.

Submission Format:

Submit through the appropriate assignment in Blackboard.

C++ Source Code: Typed as a .cpp file.

I will not accept hand-written assignments.

Scoring:

Maximum Points Possible: 100

Correctness: 60 points

Efficiency/Style: 20 points

Documentation: 20 points

Group Member Rules: This assignment does not allow partners.

General Homework Rules:

You may NOT use outside sources to obtain solutions to homework problems. You may NOT look for answers on the Internet. You may read outside sources to help you understand the general material we are covering in the course, but you may not use outside sources to solve the homework problems. "Outside sources" includes other students, friends, family members, etc. You may talk to other members of the class about the course content, but you may not use other students' solutions to the homework. Similarly, you may not provide solutions to other students. If you have any doubts about what is allowed, ask your professor.

I will not adjust your grade on an exam or assignment based upon good performance on other homeworks, good performance in other classes, or other factors such as “needing an A.”

Advice:

Do not try to avoid doing the homework. The minimum penalty for plagiarism is a

0 on the assignment. You should know at this point that not doing the assignments will result in you being unable to score well on your exams. If plagiarism occurs, and I do not catch it, you can be certain that it will show up in your score on the exams. Please do not risk it.

Please listen to me on this. I want you to do well in the course. Homework is designed to help you achieve the level of mastery needed. Please put the time in on the assignments and you will do better. Please come to office hours, email me, start early, and get help from me if you have trouble.

CSC 275 Project 1

Blackjack Card Class

New Chapters Covered:

· Chapter 6: Structures and Classes

· Chapter 7: Constructors and Other Tools

· Chapter 8: Operator Overloading and Friends

Specification:

You will design a Card class which will be used for blackjack-style playing cards. Because the expected game is Blackjack, we will want to design functionalities and store information which is relevant to that game in particular. For this assignment, you are not required to create a full blackjack game. Rather, you are only required to create the class for handling the card objects.

A Deck of Cards:

Each card has one of four suits: Spades, Clubs, Diamonds, and Hearts.

There are 13 face values: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King

The 52 cards in the deck represent all possible pairs of a suit and face value.

A Hand of Cards – Evaluating Points:

A hand is a subset of the cards in the deck. In blackjack a hand is worth a certain number of points. The goal is to have a hand which is worth as close to 21 points as possible without going over.

The points of a particular card are based upon the card’s face value and, in the case of the Ace, based upon the total value of the hand.

Face values 2 through 10 are worth points equal to their face value.

Face values of Jack, Queen, and King are each worth 10 points.

An Ace is worth 11 points if the hand is worth less than or equal to 21 points; otherwise the Ace is worth 1 point.

Card Class Public Members:

· 4 constructor functions:

Card();

creates card with default private data for an Ace of Spades.

Card(int myvalue);

creates of the given face value. Computes and stores the appropriate points for the given face value. Set the suit as Spades.

Card(int mysuit, int myvalue);

creates card of the given suit and face value. Computes and stores the appropriate points for the given face value.

Card(int mysuit, int myvalue, int mypoints);

Creates card of the given suit and face value worth the given number of points. (Will use to create composite cards as part of the + overloading)

· 2 accessor functions:

int GetPoints() const;

Returns the integer value of the calling card’s point value.

string GetCardName() const; Returns a string describing the card’s suit and face value (see the sample output for examples). Returned string should be of the form: “Face Value Name” of “Suit Name”

· 3 comparison operator overloads:

friend bool operator == (const Card& lhs, const Card& rhs); Returns true if the two cards have the same value and false otherwise. Output an error message and exit if comparison is made to a composite card.

friend bool operator < (const Card& lhs, const Card& rhs);

Returns true if the left card’s value is less than the right card’s and false otherwise. Properly treats Aces as being greater than the other cards. Output an error message and exit if comparison is made to a composite card.

friend bool operator > (const Card& lhs, const Card& rhs);

Returns true if the left card’s value is greater than the right card’s and false otherwise. Properly treats Aces as being greater than non-aces cards. Output an error message and exit if comparison is made to a composite card.

· 1 addition operator overload:

friend const Card operator +(const Card& lhs, const Card& rhs);

Add the point values of two cards together and compute their combined points as part of a blackjack hand. Properly reduces the value of an ace to 1 if the combined value would be greater than 21. Returns a composite card with the composite point value. Assigns a composite suit of 5 to the returned card. Assigns the composite card a face value of Ace if one of the two cards was an Ace and its value was not reduced to 1; otherwise assigns a composite face value of 14. Pseudocode for the algorithm is as follows:

New_Points = card1_points + card2_points

If either card1 or card2 is an ace:

If New_points > 21:

New_points = New_points - 10

New_FaceValue = Composite Face Value

Else:

New_FaceValue = Ace

Else:

New_FaceValue = Composite Face Value

Return NewCard with New_Points, New_FaceValue, and Composite Suit

Example uses of + operator:

Example 1:

+

returns a composite card which has:

points = 11 + 10 = 21

value = 1 (the Ace face value; because it contains an Ace which hasn’t been reduced to 1 yet)

suit = 5 (the composite suit)

Example 2:

+

returns a composite card which has:

points = 11 + 1 = 12

value = 1 (the Ace face value; because it contains an Ace which hasn’t been reduced to 1 yet)

suit = 5 (the composite suit)

Example 3:

+ + returns a composite card which has:

points = 1 + 9 + 10 = 20

value = 14 (the composite face value; because it does not contain an unreduced Ace)

suit = 5 (the composite suit)

Example 4:

+ return a composite card which has:

points = 10 + 9 = 19

value = 14 (the composite face value; because it does not contain an unreduced Ace)

suit = 5 (the composite suit)

Card Class Private Members:

· 3 integer variables:

int value :

stores the face value of the card as an integer, where:

1 : “Ace”

2 through 10 : “Two”, “Three”, “Four”, etc.

11 : “Jack”

12 : “Queen”

13 : “King”

14 : “Composite Face Value” (used for overloading +)

int suit :

stores the suit of the card as an integer, where:

1 : “Spades”

2 : “Clubs”

3 : “Diamonds”

4 : “Hearts”

5 : “Composite Suit” (used for overloading + )

int points :

stores the points the card contributes to a blackjack hand, where:

Ace : worth 11 points (unless the total hand is worth > 21 points; in that case its value becomes 1 point).

2 through 10 : worth their face value

Jack, Queen, and King : worth 10

Composite Card : points assigned by the + operator

TESTING:

A cpp file with a main function and the class definition has been provided. You will be adding the definitions of the methods / operator overloads for the class.

A sample run of the provided main function has been included. You should make certain that your class will work properly for the provided main function.

You should also test error cases mentioned in the specification. Include error messages explaining what the error was. Call exit(1); after each error message.

GRADING:

60 points for correctness, with:

· 15 points: Constructor Definitions

· 15 points: Accessor Definitions

· 15 points: Comparison Operator Overloads

· 15 points: Addition Operator Overload

· Must follow specification. Avoid changing the class definition. You should only be writing the definitions of the methods and the operator overloads.

20 points for efficiency / style

· includes error handling messages and exit calls where appropriate

· avoid excessively unnecessary steps in your algorithms

· avoid writing excessively more code than you need to

· avoid using excessive memory

· use whitespace appropriately for readability

· use appropriate variable names

20 points for documentation

· writing useful comments on blocks of code

· writing useful comments to describe variables

· writing a purpose / precondition / postcondition for each method you define (you can draw this from the specification)

Sample run (plain text):

Ace of Hearts == Ace of Diamonds? : 1 Ace of Hearts == King of Spades? : 0 King of Clubs == King of Spades? : 1 Ace of Diamonds > King of Spades? : 1 Ace of Diamonds > Ace of Hearts? : 0 Jack of Diamonds > King of Spades? : 0 King of Spades > Jack of Diamonds? : 1 King of Spades < Jack of Diamonds? : 0 Jack of Diamonds < King of Spades? : 1 Ace of Hearts + Ace of Diamonds? : 12 Ace of Hearts + Ace of Diamonds + Ace of Diamonds? : 13 Ace of Hearts + King of Clubs + King of Spades? : 21 King of Clubs + Ace of Hearts + King of Spades? : 21 King of Clubs + King of Spades + Ace of Hearts? : 21 Ace of Hearts + King of Clubs + King of Spades + Ace of Diamonds + King of Clubs + Ace of Diamonds? : 33 King of Clubs + Ace of Hearts + King of Clubs + King of Spades + Ace of Diamonds + King of Clubs + Ace of Diamonds? : 43 King of Clubs + 7 ? : 17 Ace of Hearts > 2 ? : 1 Ace of Hearts == 1 ? : 1 Ace of Hearts < 2 ? : 0

Sample run (as a screenshot):