Write programs with class objects

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

Aim:

This assignment is to familiarise you with the use of classes in your programs.

On completion you should know how to:
- Write programs with class objects.
- Implement programs incrementally to minimise debugging.
- Design class objects for software applications.

Requirements:

This assignment involves the implementation of a simple class to hold sets of playing cards. This structure can be used in any card games requiring decks of cards or hands of cards. A standard deck of cards is represented by the numbers 0 to 51. Thus the contents of the class will be a (dynamic) array of integers with values in that range. These integers will represent the usual 52 cards, starting from the 2 of spades (denoted 2S) followed by 3,...,10 (denoted as XS), followed by J(ack), Q(ueen), K(ing) and A(ce). Then will follow the clubs, diamonds and hearts. To facilitate the output of a card, the file CardSet.cpp contains a function PrintCard(int) which will print one card. This file will also hold the implementation of the class CardSet whose interface file is provided as CardSet.h. The contents of this class:

class CardSet
{
public:
CardSet(); CardSet(int);
~CardSet();
int Size() const; bool IsEmpty() const; void Shuffle();
int Deal();
void Deal(int,CardSet&,CardSet&);
void Deal(int,CardSet&,CardSet&,CardSet&,CardSet&); void AddCard(int);
void MergeShuffle(CardSet&); void Print() const;
private:
int* Card; int nCards;
};

A driver program in main.cpp has also been provided for testing the class Cardset. Before commencing any work familiarise yourself with these files and the task performed by each class function described below. All work is to be done in CardSet.cpp and CardSet.h. Do not alter main.cpp.

Implementation:

The task for this assignment is to add the implementations of the member functions to the file CardSet.cpp. Here is a description of the required member functions:

(i) CardSet();
This is the (default) constructor. It should set up a set of 0 cards. 

(ii) CardSet(int);
This is the initialising constructor. It should set up a set of cards, where the number of cards is the argument passed. The array Card should be filled with cards starting from 0, up to the number of cards needed, but never exceeding the number 51. For example if a set of 104 cards is requested, the array would contain 0 to 51 twice. 

(iii) ~CardSet();
The destructor should clean up any dynamic memory used. 

(iv) int Size() const;
This accessor function should return the value of nCards. 

(v) bool IsEmpty() const;
This function should return true if there are no cards in this set. 

(vi) void Shuffle();
This function rearranges the cards in the set in a random manner. There are many ways of doing this. The simplest method follows this algorithm:

FOR each card i in the set
SET j to be a random number on range 0 to number of cards -1 IF i is not equal to j THEN
exchange card i and card j

You should use the cstdlib library function rand() to generate the random integers needed. 

(vii) int Deal();
This function should return the value of the first card in the set, located in the 0th element of the array. The function should then create fresh memory, transfer the rest of the set to this new memory, and then delete the old memory. That is, this class never has any vacant space in it. The array is always the same size as the number of actual cards it holds. If the set is empty, this function should print an error message and terminate the program.

(viii) void Deal(int,CardSet&,CardSet&);
This function deals two hands into the two CardSet arguments passed. The number of cards to be placed into each hand is the first argument. The cards should be removed from the current set one at a time, placing the cards into alternate hands. For example. if the current set held 2S, 3S, 4S, 5S, 6S, 7S (the integers 0 to 5) and we had to deal 3 cards, then the two hands would get 2S, 4S, 6S (integers 0, 2, 4) and 3S, 5S, 7S (1, 3, 5) respectively. The two hands may already have cards in them, and the additional cards will require new memory. Do not create new memory more often than is required. Remember that the current set has to be reduced in size as well. If there aren't enough cards in the current set to perform the deal, print an error message and terminate. 

(ix) void Deal(int,CardSet&,CardSet&,CardSet&,CardSet&);
Same as above but for four hands. 

(x) void AddCard(int);
Function to add a card to the current hand. 

(xi) void MergeShuffle(CardSet&);
This function takes the current set and the set provided as an argument and makes the current set contain all the cards from the two sets, with cards alternating from each set as far as possible. After this function the argument set will be empty. 

(xii) void Print() const;
This accessor function, uses PrintCard to print the contents of the set, five cards to a line. 

Commence this assignment by providing stubs for all the above functions so that the program will compile. Keep compiling the program regularly even if this requires parts of the code to commented out. The order in which the functions are implemented is left entirely up to you. However, this should be done to facilitate incremental development and testing of the program and not necessarily in the order given above.

Demo:
During your week-6 lab class you should demo Test 1 in the main() function. This will require completion of the constructors, destructor, Size() and Print() functions in ass2.cpp. Do not alter the code in main.cpp.

Attachment:- files.rar

Verified Expert

This is card games written in C++. We implement only few functions that does the basic operations. This is the starting level of the game where we are more focused on the generating random cards, distributing 51 cards to each hand, then shuffling it to mix it proper and we use merge shuffling, which add two packs, and then mixes it well. Finally, we implement a function, which will distribute the cards to 2 hands or even 4 hands .

Reference no: EM131953985

Questions Cloud

Elusive cash balance-applications in financial management : Based on the prior years' financial statements, what conclusion do you think Patrick would be justified in reaching?
Price elasticity of demand for coke : What is the Coca-Cola executive assuming about the price elasticity of demand for Coke? Briefly explain.
Discuss the types of information and data : Consider the types of information and data a counselor might use to ensure that clients are effectively using the counseling sessions.
Find the price and draw up the bond schedule : The first coupon is $100, and each increases by 10%. The bond is prices to yield i= 9%. Find the price and draw up the bond schedule.
Write programs with class objects : Write programs with class objects and Implement programs incrementally to minimise debugging. - Design class objects for software applications
Analyze human behavior problems : Analyze human behavior problems within an organization for informing properly targeted solutions that improve human behavior.
Create a fictitious small business that has a business need : Write a one-page outline of your project proposal. Create a fictitious small business that has a business need to implement a new ERP system.
Maximize their profit making potential : How can an organization like Nike maximize their profit making potential? Please provide a reference with questions
Relationship between the family and the community : Do you consider the relationship between the family and the community when making a decision on the way forward to incorporate within your program?

Reviews

len1953985

4/23/2018 4:59:51 AM

This assignment gonna check on turnit in aswell, last semester turor send same copy of assignment to me and my friend and there was 100% plagiarism. So plz i need genuine solution. I am attaching a picture aswell which is how our tutor gonna mark the assignment.

len1953985

4/23/2018 4:59:10 AM

CSCl251 Asst Marking Criteria (8 marks) Not printing 5 cards per line No name etc at top of file - Incorrect indentation: Failure to delete memory - Deal function not checking if deck has enough cards — Function boold Shuf Is y (); () conat; voifle int Deal(); void Deal (int, CardSet& cardset &); void AddCard (int); void Deal (int, cardset s, CardSet&, cardsets, cardSet &) void MergeShuffle (CardSet&) ; void Print() coast; Marker: Date

Write a Review

C/C++ Programming Questions & Answers

  Write concept - array-based queue implementation

write 150 words in length about this concept "Array-Based Queue implementation", give example if needed

  Lists of integers and displays whether the two are identical

Write a test program that prompts the user to enter two lists of integers and displays whether the two are identical. Here are the sample runs.

  Implement a selection sort

Implement three functions whose prototypes are given - You are going to use a static array declared using { 12, 1, 6, 8, 5, 9, 22, 9, 13, 17 } to initialize an STL list, as shown in the slides.

  Write an lc-3 machine language program

Write an LC-3 machine language program starting at location x3000 which divides the number in memory location x4000 by the number in memory location x4001 and stores the quotient at x5000 and the remainder at x5001.

  How would we secure a microsoft sql server

Your deliverables will require the highest level of professionalism. All of your deliverables should be presented as if your customers are paying you $225 per hour plus expenses plus per diem.

  Create a text file named grades.txt

Write a program to calculate students' average test scores and their grades. Creat a text file named  grades.txt

  Discuss the different c++ loops and their characteristics

Discuss the different C++ loops, their characteristics

  Find the largest element and print out the index and value

Write a function maxv() that returns the largest element of a vector argument. Find the largest element and print out the index and value.

  Write a program that reads the scores from the file

Write a program that reads the scores from the file and displays their total and average. Scores are separated by blanks.

  Write a program that determines the miles per gallon

Write a C program that determines the miles per gallon for 3 tanks of gasoline that a user fills in his/her car

  Use a loop in main to efficiently handle all three persons

Plan and finish writing the main program, and all the functions, including a constructor. Use a loop in main to efficiently handle all three persons' data.

  Draw the extensive-form version of game

Consider a game between Joe and Snake. This game takes place in the morning after Joe has had breakfast. Snake can do two things: fight Joe or not. He likes fighting with people who are feeling cowardly and gets a payoff of 1 if he does. Snake, howev..

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