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

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

  Sorted list adt and the binary search tree adt

Explain the differences between our specifications of the Sorted List ADT and the Binary Search Tree ADT.

  Design a single class that expresses the commonality

Design a single class that expresses the commonality of these concepts.

  Technical community blog

Write a blog article for a coding/technical community blog

  Implementation activities of software development

Analysis, design, and implementation activities of software development

  Creating the gui for the game interface

A GUI-based application that allows a user to play a simple trivia game

  Represent one book in java

Represent one book in java

  Develop a gui based java program

Designing and developing a College Registration program

  Implement avl tree

Implement AVL trees that allows both iterative traversal and recursive traversal.

  Write a java program to register students for a college

Project is for designing and developing a College Registration program. Write a Java program to register students for a college

  Implement security so that all users can view the informatio

Implement security so that all users can view the information about the projects, but only authenticated users

  Create four classes

Create four classes: Account.java, Checking.java, Savings.java, and AccountArray.java.

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