Assignment 08
Assignment 08
Link:
https://docs.google.com/document/d/1eaBxYZtteNw_l4qeHGwwr7pJqOzU4uWblyTUDwLWE
MI/edit?usp=sharing
Card Wars
Background
You are the ruler of a very small country with
incredibly odd laws. For the past four years you have had
a very successful reign. However, one of the
unchangeable laws of your country of Fifteenseventystan
is that the position of ruler can be taken by anyone who
beats the current ruler at a game of war. Today, you have
been challenged by a young adventurer covered in slime,
for some reason. In order to keep your position, you must
beat him at war.
Specifications
For this assignment, you are going to create several classes.
The card class (used to store the value of a single playing card)
Private members:
A character to represent the cards value
(2, 3, 4, 5, 6, 7, 8, 9, J, Q, K, or A)
A character to represent the suit (H for
heart, C for club, S for spade, and D for
diamond)
A boolean to represent whether or not
the card has been destroyed.
Public members:
A default constructor should be made
available that does nothing. This is simply put in place to guarantee a
successful compilation of the program.
A parameterized constructor should be made available to take in both
the card's value and its suit.
Overloaded + operator: The + operator should be overloaded within
this class. When two cards are added together, it should return an
integer which is the sum of the values of the 2 cards. For purposes of
this function, count J,Q,K, and A as having a value of 10. For example, if
you added the 7 of clubs and the queen of diamonds together, it should
return a 17. If the sum of two cards is 11, both cards should be
destroyed.
Overloaded > and < operators: These operators should be overloaded
to compare the value of two cards. CardA>CardB should return true if
card A is greater than card B, and false if otherwise. Similarly,
CardA<CardB should return false if card A is greater than card B, and
true if otherwise. How cards are compared are as follows:
If the two cards have different suits, then the card with the higher
value is greater. The only exception to this is when the cards’
values are 2 and A, in which case the value 2 will be considered
the greater card.
If the two cards have the same suit, then the card with the lower
value is greater. The only exception to this is when the cards’
values are 2 and A, in which case the value A will be considered
the greater card.
Overloaded == and != operators: This operator should compare two
cards. The == operator overload should return true if the two cards have
the same value, and false if otherwise. Similarly, the != operator should
return false if the two cards have the same value, and true if otherwise.
Overloaded ~ operator: This operator should destroy the card forever.
Overloaded insertion operator (<<): This operator should return an
ostream object by reference. It must output the card's value, followed
by its suit. For example, the 7 of clubs would be output as 7C.
Notes
● Set the random seed for this assignment to be 469.
● It is recommended that each class definition goes in their own header file.
● You may define additional functions to be used to improve the program’s organization.
This includes global functions and member functions for the classes as well.
● You may use functions from existing libraries if 1) they are explicitly stated in the
assignment or 2) the usage of the library functions has been thoroughly introduced in
class. Otherwise, the usage of functions from existing libraries is prohibited without
the permission of your instructor.
● If the parameters and return type of a function is not specified, then it is your
responsibility to determine the most appropriate function signature.
Sample Outputs
Sample outputs regarding the format are provided below for your reference, i.e. the
data values used in the output might be completely made up. Your actual program output
does not have to match the sample exactly. Make sure that yours is nicely formatted and is
readable to anyone.
Sample Output
This is war!
Input defender name:
Julian
Normo
Battle commence!
–Game over–