Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

By using C++, Implement class Stack1 and Stack 2 as defined by the following skeleton: const int MAXITEM= 100; class Stack1 { private: int top;

By using C++, Implement class Stack1 and Stack 2 as defined by the following skeleton:

const int MAXITEM= 100;

class Stack1

{

private:

int top;

int info[MAXITEM];

public:

Stack( ); // default constructor: Stack is created and empty

Stack(const Stack1 &x); // copy constructor

void MakeEmpty(); // Stack is made empty;

bool IsEmpty( ); // test if the stack is empty

bool IsFull( ); // test if the stack is full

int length( ); // return the number of elements in the stack

void Print( ); // print the value of all elements in the stack in the sequence

// from the top to bottom

void Push(int x); // insert x onto the stack

void Pop(int &x); // delete the top element from the stack

// Precondition: the stack is not empty

~Stack(); // Destructor:

};

Create another class Stack2, in which the info array is of float data type.

In you main( ) routine, you need to test your class in the following cases:

Stack1 IntStack;

int x;

IntStack.Pop(x);

IntStack.Push(11);

IntStack.Push(22);

cout << "int length 1 = " << IntStack.length() << endl;

IntStack.Pop(x);

IntStack.Push(33);

cout << "int length 2 = " << IntStack.length() << endl;

cout << The int stack contains: << endl;

IntStack.Print();

2

IntStack.Push(44);

IntStack.Push(55);

IntStack.Push(66);

if(IntStack.IsFull() == false)

cout << The int stack is not full ! << endl;

else

cout << The int stack is full ! << endl;

Stack1 IntStack2(IntStack);

cout << The int stack2 contains: << endl;

IntStack2.Print();

IntStack2.MakeEmpty();

cout << The int stack3 contains: << endl;

IntStack2.Print();

Stack2 FloatStack;

float y;

FloatStack.Pop(y);

FloatStack.Push(7.1);

cout << "float length 1 = " << FloatStack.length() << endl;

FloatStack.Push(2.3);

FloatStack.Push(3.1);

cout << "float length 2 = " << FloatStack.length() << endl;

FloatStack.Pop(y);

cout << The float stack contains: << endl;

FloatStack.Print();

Stack2 FloatStack2 = FloatStack;

cout << The float stack 2 contains: << endl;

FloatStack2.Print();

FloatStack.MakeEmpty();

cout << The float stack 3 contains: << endl;

FloatStack2.Print();

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

Explain the principles of digital transformation.

Answered: 1 week ago