Classes and pointers experience using dynamic memory

Assignment Help JAVA Programming
Reference no: EM135326

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<Card*> 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.

Reference no: EM135326

Questions Cloud

Generate a flow chart in a word processing document : Using the info you studied on organizational structures, generate a flow chart in a word processing document for the company's organizational structure
The eu and turkey- scenarios to 2050 : Prepare your slides as soon as you have a good final draft. Preparing the slides will help you see any weaknesses in your paper.
Managerial economics assignment : Carry out an analysis from the standpoint of both EMV and expected utility to establish Jeremiah’s best course of action, including a consideration of his bidding strategy with regard to the auction.
Using marginal analysis and eva analysis : Finance questions based on  marginal analysis,  EVA analysis. Find  the current yield for Bond A.
Classes and pointers experience using dynamic memory : To practice defining classes using separate compilation using classes, vectors, and pointers experience using dynamic memory.
Leadership theorem : Choose two of the ILF presentations and debate their lessons for leadership. You should use theory in your answers discussing how the case exemplifies or differs from the theory.
Evaluate the success of the overall strategy : Assess the techniques used by QinetiQ for improving business processes and evaluate the success of the overall strategy.
Evaluate the effectiveness of stms strategy : Evaluate the effectiveness of STM's strategy of combining as many existing initiatives as possible in order to simplify their approach to TQM.
What kind of product or service does the business produce : What kind of product or service does the business produce? Is it identical to others in the industry or is it differentiated to some degree or perhaps unique

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program that reads a set of floating-point

Write a program that reads a set of floating-point data values from the input.

  Create a java program

UserApp and PrettyPrintUtility multiple times (supplying different TransData test file names), the AutoTesterUtility PROGRAM will be the driver program.

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Communication with an smtp server

Develop a graphical user interface based java program that can communicate with a real SMTP email server for sending emails

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Robot preparing for competition

Create an event so that the skateboard can be controlled by game player

  Mean and standard deviation using using eclipse

Java programming to calculate Mean and standard deviation using Using Eclipse.

  Methods

Assignment describe the basic working of methods. How to write a method in java and how to call a method.

  Implementation of memory management

Implementation of memory management

  Loops and files

Convert an algorithm using control structures into Java and write a while loop

  Implement a class quiz

Implement a class Quiz that implements the Measurable interface.

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

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