Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here is the stack class // implementation file for the stack class #include using namespace std; const int stack_size = 100; class stack { private:
Here is the 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
cout
}
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
CIS 251 Homework doc (Protected view) Last saved by user word sert Design Layout References Mail Review view 9 Te what you want to da Be catelul-files from the Internet can contain viruses. Unless you need to edit, it's sferto stay in Protected view. Enable Edting CIS 251 Homework 4-What a Card! Due: Monday, April 3,2017 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 This program will consist of three files: required to wrte the following functions puta the atandard 52 carda into the atack of 1. card.h, card class cards. The order of the card a ia not impor as long as all 52 are there. 2.stack.h stack class 3 main-epp: mam program void make deck (atack deck) mixea the carda in the deck using the following algorithm: create the following class representing a playing card declare two at acka temp and repeat 100 times private for each card in the deck int rank 11 ace, 11: Jack, 12 queen, 13: king remove a card from the deck ett twit and rank to the giren values randomly place thst card on tempi or temp2 void create tchar a Pratt a card in the form: Ace of move all the carda from templ back to deck void print all the cards from temp2 back to deck stack class Make the following changes to the stack class written in class road mix deck stacks deok). a Include the card class in the stack h file When done, submit your three source files (card,h, stack and main cpp) 2 Change the data type in the class to be an array of card type instead of char type. This requmes 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 A sample run ofmy piogram is on B the print function in the card class to print the individual cards print should not change the stack cout
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started