Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Advanced Programming Assignment

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.

Submit: Submit your files using the submit facility on UNIX.

Attachment:- Assignment Files.rar

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92776565

Have any Question?


Related Questions in Programming Language

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As