Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a short computer program with these classes and functions for C++. In Assignment 2, you must implement several C++ classes and use them to

Write a short computer program with these classes and functions for C++.

In Assignment 2, you must implement several C++ classes and use them to write a Go Fish game. In this lab, well implement and test a few of those classes. The first one youll implement is the Card class, which represents a single playing card:

class Card { private: int rank; // Should be in the range 0-12. int suit; // Should be in the range 0-3. public: // constructors, destructor, accessors, and mutators };

Youll need to implement the needed constructors, destructors, accessor functions, and mutator methods. To do this, think carefully about what operations (if any) youll need to perform on an individual card and what information youll need to be able to get from the card. Put the definition for this class in card.hpp and the implementation in card.cpp. Once these files are done add and commit them to your git repo, and push them to GitHub.

Step 3: Implement the Deck class from Assignment 2

Once you have a class to represent a single card, you can implement your class to represent a whole deck of 52 cards:

class Deck { private: Card cards[52]; int n_cards; // Number of cards remaining in the deck. public: // constructors, destructor, accessors, and mutators };

Again, in addition to the attributes outlined above, youll need to implement any needed constructors, destructors, accessor, and mutator methods. Again, think about what operations need to be performed on a deck of cards. For shuffling, youll want to use C++s rand() function. Put the definition for this class in deck.hpp and the implementation in deck.cpp. Once these files are done add and commit them to your git repo, and push them to GitHub.

Step 4: Implement the Hand class from Assignment 2

Now that you have classes to represent cards and a deck, you should be able to implement the class to represent a players hand of cards:

class Hand { private: Card* cards; int n_cards; // Number of cards in the hand. public: // constructors, destructor, accessors, and mutators };

When writing the methods for this class, make sure you write a method to print the hand out to std::cout. Put the definition for this class in hand.hpp and the implementation in hand.cpp. Once these files are done add and commit them to your git repo, and push them to GitHub.

Step 5: Write a small application to deal a hand of cards

In order to test your classes, write a small program that uses them to do the following things:

Initializes a new deck of 52 cards.

Shuffles that deck.

Deals a hand of 7 cards.

Prints the contents of that hand to the console.

Put this program in deal_hand.cpp. Also, add a Makefile to compile your program. Once these files are done add and commit them to your git repo, and push them to GitHub.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions