Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program will consist of three files: 1. card.h : card class 2. stack.h : stack class 3. main.cpp : main program card class Create

This program will consist of three files:

1. card.h: card class

2. stack.h: stack class

3. main.cpp: main program

card class

Create the following class representing a playing card:

class card

{

private:

char suit; // h, d, c, s

int rank; // 1: ace, 11: jack, 12: queen, 13: king

public:

// sets suit and rank to the given values

void create (char s, int r);

// prints a card in the form: Ace of

void print ();

};

stack class

Make the following changes to the stack class written in class:

1. Include the card class in the stack.h file

2. Change the data type in the class to be an array of card type instead of char type. This requires changes in a number of places in the file.

3. Add a function called print that prints the elements in the stack, each card on a separate line, from the top element to the bottom element. You will use the print function in the card class to print the individual cards. print should not change the stack.

main program

The main program should make a standard deck of 52 cards (this will be a stack), print the deck, sort the deck, and print the deck again. You are required to write the following functions:

// puts the standard 52 cards into the stack of

// cards. The order of the cards is not important

// as long as all 52 are there.

void make_deck (stack& deck);

//

// mixes the cards in the deck using the following

// algorithm:

// declare two stacks temp1 and temp2

// repeat 100 times

// {

// for each card in the deck

// {

// remove a card from the deck

// randomly place that card on temp1 or temp2

// }

// move all the cards from temp1 back to deck

// move all the cards from temp2 back to deck

// }

//

void mix_deck (stack& deck);

stack.h: stack class

// implementation file for the stack class #include  using namespace std; const int stack_size = 100; class stack { private: char data [stack_size]; // array of stack elements int top; // top is the index of the top element of the stack public: stack (); // creates an empty stack void push (char item); // pushes item on top of stack char pop (); // removes and returns top of stack bool empty (); // returns true if stack is empty bool full (); // returns true if stack is full }; // constructor creates an empty stack stack::stack () { top = -1; } // push adds item to the top of the stack void stack::push (char item) { // if the stack is full, print an error message if (full ()) { cout << " Stack Class Error: Pushing on a full stack"; cout << " Trying to push " << item; } else // ok to push { top++; data [top] = item; } } // pop removes and returns the top element of the stack char stack::pop () { // if the stack is empty, print an error message if (empty ()) { cout << " Stack Class Error: popping an empty stack"; cout << " Returning a ?"; return '?'; } else // ok to pop { top--; return data [top + 1]; } } // empty returns true if the stack is empty, else // it returns false bool stack::empty () { return top == -1; } // full returns true if the stack is full, else it // returns false bool stack::full () { return top == stack_size - 1; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

What are DNA and RNA and what is the difference between them?

Answered: 1 week ago

Question

Why do living creatures die? Can it be proved that they are reborn?

Answered: 1 week ago

Question

13. You always should try to make a good first impression.

Answered: 1 week ago