Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DO NOT USE any of the STL (including the vector type) in your Stack. For this lab, you should write a C++ program that creates

DO NOT USE any of the STL (including the vector type) in your Stack.

For this lab, you should write a C++ program that creates an integer stack named doubleStack using the dynamic array implementation. Use typedef to indicate the data type of the elements in the stack. Set the default type as int, but the code should remain to work if the typedef is changed to float.

Set the initial size of the stack to 5. The program should support operations push(), pop(), and print(). You should NOT create a new struct or class for this lab.

First, ask the user for a positive value to push to the stack. Once the stack has one or more elements, every push operation adds a value that is the current top value times two (top x 2). Ask if the user wants to push, pop, or quit with the following line.

cout << "Do you want to push (p), pop (o), or quit (q)?" << endl;

Allow the user to push or pop as many elements as they wish. When the stack is full OR when the user wants to stop, print all the elements in doubleStack and end the program. Please note that youll be using a dynamic array in this lab. Make sure that your code meets all the requirements associated with dynamic memory allocation.

Execution example

Welcome! Please enter a positive value: 2

Do you want to push (p), pop (o), or quit (q)? p inserted 4

Current stack: 2, 4

Do you want to push (p), pop (o), or quit (q)? o

The popped value is 4

Do you want to push (p), pop (o), or quit (q)? o

The popped value is 2

Do you want to push (p), pop (o), or quit (q)? o

Nothing to pop

Do you want to push (p), pop (o), or quit (q)? p

Please enter a positive value: 3

inserted 3

Current stack: 3

Do you want to push (p), pop (o), or quit (q)? p

inserted 6

Current stack: 3, 6

Do you want to push (p), pop (o), or quit (q)? p

inserted 12

Current stack: 3, 6, 12

Do you want to push (p), pop (o), or quit (q)? p

inserted 24

Current stack: 3, 6, 12, 24

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

Students also viewed these Databases questions