Deal two cards at a time

Assignment Help C/C++ Programming
Reference no: EM13166213

Write a declaration for the class Card including its data members and function members based on the following UML and save it in a file called card.h.
Card
-suit:int
-rank:int
+Card()
+genRandom():void
+getRand():string
+getSuit():string
+printCard():void
+sameCard(Card):bool
+sameSuit(Card):bool
+sameRand(Card):bool

b)Implement the member functions based on the following descriptions, and save them in a file called card.cpp.
Card(): is the constructor.

genRandom(): this function will simulate the dealing of a card. It will randomly generate a rank (1 to 13) and a suit (1 to 4) and store these values in the appropriate member attributes. See end of this handout for explanation of how to generate random numbers.

getRank(): will return the text version of the rank
1 is Ace, 2 is Deuce, 3 to 10 is the number spelled out (Three, Four, ....., Ten), 11 is Jack, 12 is Queen and 13 is King
getSuit(): will return the name of the suit, Spades, Clubs, Diamonds, Hearts

printCard(): will show on the screen the rank and suit of the card. It will need to call the member functions getRank() and getSuit();

sameCard(Card): will return a Boolean value indicating if the two cards being compared have the same rank and the same suit in other words are identical.

sameSuit(Card) and sameRank(Card): will return a Boolean value indicating if the two cards being compared have the same rank or the same suit.

c) Write a program that uses the class Card . It should deal x pairs of cards, (where x is between 1 and 15 inclusive), print them out, and count the number of pairs that had identical cards, cards only of the same rank, cards only of the same suit, and pairs of different cards. You are to ask the user how many pairs to deal. Print out a summary at the end, indicating the number of identical cards, different cards and number of pairs with same rank or same suit. <<

Here is a general algorithm.
- Declare two objects of type Card called card1, card2.
- Print out a welcome message which includes your name(s)
- Ask the user the number of pairs to deal out. Set a maximum such that your output will fit in
one output screen. Be sure to check that the number of pairs the user has requested is valid. As long
as number of pairs requested is not valid, prompt the user for a valid number of pairs.
Card
- suit: int
- rank: int
+ Card()
+ genRandom(): void
+ getRank(): string
+ getSuit(): string
+ printCard(): void
+ sameCard(Card): bool
+ sameSuit(Card): bool
+ sameRank(Card): bool
  
COMP218/Winter 2014 - Assignment 4 Page 3 of 4

- Deal two cards at a time, print them out
- Check if they are identical, have just the same rank or just same suit or are completely
different. Print out a message indicating the result of your comparison.
- Count the number of pairs in each category (identical, same suit, same rank or different).
- Once finish dealing all cards, print out a summary of your findings.

NOTE 1: Be sure to save the class declaration in a header file, the class implementation if a .cpp file.
Don't forget to include these files in the project. Following is a sample output screens. Note these
are samples, meaning you can change the messages and the format but not the content

Reference no: EM13166213

Questions Cloud

Wind and solar power-energy needs : Many people are debating how to best meet energy needs in the United States. Some argue that the country must decrease its dependence on oil and invest in alternative sources of energy, such as wind and solar power.
Choice lists of the case statement : In Ada, the choice lists of the case statement must be exhaustive, so that there can be no unrepresented values in the control expression. In C++,
Create a program that draws a two-dimensional house : Create a program that draws a two-dimensional house seen from the front, the way a child would see it: with a door, two windows, and a roof with a chimney
What is the molarity of nabr in the solution : a 50 ml solution containing NaBr was treated with excess AgNo3 to precipitate 0.2146g of AgBr. what is the molarity of NaBr in the solution.
Deal two cards at a time : Deal two cards at a time, print them out.- Check if they are identical, have just the same rank or just same suit or are completely.different. Print out a message indicating the result of your comparison.
Change the inheritance to private inheritance : Take the following C++ code and make the following changes. Change the inheritance to private inheritance. Change the private data member balance to protected. Define get function members of IntAccount class to retrieve name and balance.
Which pair is written with first member having the higher : Which pair is written with the first member having the higher boiling point?
Draw a lewis structure for h2nnh2 : Draw a Lewis Structure for C3O2. Draw a Lewis Structure for C2H3NO5
State what concentration of ca remains in solution : If 2.55 g of NaOH were added to a 100.0 mL solution containing 0.10 M Ca(NO3)2, what concentration of Ca 2+ remains in solution?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Once the user enters a 0

Once the user enters a 0 you will exit the loop, close the file and execute the code as previously designed until you have displayed all of the scores and the average handicap.

  Native method with deadlock detection and recovery

The naïve method with deadlock avoidance and the naïve method with deadlock detection and recovery - what will you measure and compare in order to determine the winner or which is better

  Write recursive boolean method to accept array and value

Write down the recursive boolean method named isMember. The method must accept two arguments: an array and a value. Method must return true if value is found in array.

  Implement a standard sorted linked list class

Write C++ Program:Implement a standard SORTED linked list class. Be sure to include constructor/copy constructor, destructor, and assignment operator overload.

  Programming assignment is to tweak the existing mammal

programming assignment is to tweak the existing Mammal program and create your own Vehicle program.

  C++ class that has a dynamic array of a string

show  an example of a C++ Class that has a dynamic array of a string that takes in names by user input??

  A perfect solution is impossible or too expensive

Optimization is often encountered in engineering problems. More often than not, a perfect solution is impossible or too expensive to find and implement. Therefore, we resort to sub-optimal, yet useful, solutions. This assignment tackles a classical p..

  Add the correct code to fill the matrix array with the value

Use the file below code and add the correct code to fill the matr2 array with the values that make it the matrix transpose of matr1. There are many examples on the Internet that show how to do this in C++ and what it should look like when it is corre..

  A c++ program using the concept of function overloading

write a c++ program using the concept of function overloading for the following options : select the options from [1-3], 1- Area of rectangle 2- Area of square 3- Exit ,

  Make 2-dimensional array

make 2-dimensional array a bit of life and bringing them from the abstract to the concrete realms

  Write a menu-driven program that maintains an address book

Write a menu-driven program that maintains an address book using a linked list. The address book must supports the following operations

  Write main function to compute stress-strain in steel rod

Write a main function and the following functions to compute the stress and strain in a steel rod of diameter D (inches) and length L (inches) subject to the compression loads.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd