Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Objectives:

1. To practice defining classes using separate compilation.

2. To practice using classes, vectors, and pointers.

3. To gain experience using dynamic memory.

Scenario:  The owners of the most popular Las Vegas casinos were so impressed with your UCLA promotional interactive animated cartoon that they want to hire you to design a bunch of new electronic card games using C++.  Your first task in this project is to help their coding team finish modeling a playing card and a deck of playing cards as C++ objects.

   Directions:

 Create a Win 32 Console Application project called "Hw8" in your solution called "Homework" using Microsoft Visual Studio.  

 1. You are to implement the following Card class.

enum Suit {HEARTS, CLUBS, SPADES, DIAMONDS};

enum Rank {ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING};

 class Card{

   public:

          Card(Rank r, Suit s);

          Rank getRank()const;

          Suit getSuit()const;

          string toString()const;

   private:

    Suit suit;

    Rank rank;

};

 First place the code above in a header file Card.h and make sure it has include guards.  Then define the Card member functions in the implementation file Card.cpp. I provided the definition of Card's toString() member function below to help get you started:

 string Card::toString()const{

     string description = "";

     switch(rank) {

  case ACE:

    description += "Ace";

    break;

  case TWO:

    description += "Two";

    break;

        case THREE:

    description += "Three";

    break;

  case FOUR:

    description += "Four";

    break;

        case FIVE:

    description += "Five";

    break;

  case SIX:

    description += "Six";

    break;

        case SEVEN:

    description += "Seven";

    break;

  case EIGHT:

    description += "Eight";

    break;

  case NINE:

    description += "Nine";

    break;

        case TEN:

    description += "Ten";

    break;

  case JACK:

    description += "Jack";

    break;

  case QUEEN:

    description += "Queen";

    break;

  case KING:

    description += "King";

    break;

  }

   description += " of ";

   switch(suit) { 

  case HEARTS:

    description += "Hearts";

    break;

  case CLUBS:

                description += "Clubs";

    break;

  case SPADES:

    description += "Spades";

    break;

  case DIAMONDS:

                description += "Diamonds";

    break;

  }

  return description;

}

 Be sure to define the other Card member functions in the implementation file also.

 2. You are to implement the following class CardDeck which models a standard deck of 52 playing cards:

 class CardDeck  {

  public:

     CardDeck();   // default constructor

    ~CardDeck();  // destructor

      /* Returns the Card pointer at the back of the vector or NULL if the deck is empty. */

     Card* getTopCard();

      /* Prints each card, one per line, using the Card's toString() member function. 

     */

     void print()const;

      /* Shuffles the deck of cards by swapping two random elements of the deck.  */

  void shuffle();

     private:

      vector deck;

       /* Swaps the contents of the elements of deck at the given   

         indices. */

      void swapCards(int index1, int index2);

};

 Be sure to put the code above in a header file called CardDeck.h with include guards and the appropriate include statements. The definitions of the CardDeck class member functions should go in the implementation file CardDeck.cpp Make sure the implementation file includes the CardDeck header file.

Java, Programming

  • Category:- Java
  • Reference No.:- M9155715
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in Java

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

  • 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