Question: Stack ADT Class templates are used to create generic classes and abstract types. They enable you to create one general version of a class without

Stack ADT
Class templates are used to create generic classes and abstract types. They enable you to create one general version of a class without replicating code to handle multiple data types. Where to start when defining a template? It is easier to convert code that works into templates rather than to write templates from scratch. You have already created and tested a stack class for strings (zyLabs Stacks 1,2 & 3). Now you have to convert the stack_str class into a template class, so it would work with any data type.
If you are not familiar with multiple source and header files projects, please refer to 15.13 Separate files for classes zyBook. For each class we usually create two files (unless the class is really simple and all member functions are inline functions):
Stack_str.h - a header file: the specification file, to store the class definition
Stack_str.cpp a source file: the implementation file, to store longer member function definitions.
When a class gets converted into a template class, these two files are placed into one file:
StackADT.h
Project
One of the stack applications is to backtrack. As example take a list of integers. Negative numbers, 0, and 1 represent commands, the rest of the integers represent data. You may assume the input files contain valid data.
Each time we read 0, display the number of elements in the stack.
Each time we read 1, display the element at the top of the stack and the largest value in the stack in constant time. If there are no elements in the stack display "Top: Empty".
Each time we read a number greater than 1, we push it onto the stack.
Each time we read a negative number, we pop and print the number removed from the stack and the largest value in the stack in constant time. If there are no numbers in the stack, display "Pop: Empty". If there's only one number in the stack, after removing it, print it.
When the end of the file is detected, print "Stack: " and pop and print the items left in the stack, if any, or "Stack: Empty" otherwise.
Example 1
If the input file contains the following numbers:
10302017004050-208595-36075
Process input:
Read 10, Push 10
Read 30, Push 30
Read 20, Push 20
Read 1, Display the element at the top of the stack and the largest value in the stack: 2030
Read 70, Push 70
Read 0, Display the number of elements in the stack: 4
Read 40, Push 40
Read 50, Push 50
Read -2, Pop and print the value removed from the stack and the largest value in the stack: 5070
Read 0, Display the number of elements in the stack: 5
Read 85, Push 85
Read 95, Push 95
Read -3, Pop and print the value removed from the stack and the largest value in the stack: 9585
Read 60, Push 60
Read 75, Push 75
END OF FILE
Display the stack from top to bottom: 75,60,85,40,70,20,30, and 10
Format output as shown below
Input File: numbers1.txt
Top: 20
Max: 30
Count: 4
Pop: 50
Max: 70
Count: 5
Pop: 95
Max: 85
Stack: 75,60,85,40,70,20,30,10.
Example 2
If the input file contains the following numbers:
01-6105030-17020-5-4-3-2
Process input:
Read 0, Display the number of elements in the stack: 0
Read 1, Display "Top: Empty"
Read -6, Display "Pop: Empty"
Read 10, Push 10
Read 50, Push 50
Read 30, Push 30
Read -1, Pop and print the value removed from the stack and the largest value in the stack: 3050
Read 70, Push 70
Read 20, Push 20
Read -5, Pop and print the value removed from the stack and the largest value in the stack: 2070
Read -4, Pop and print the value removed from the stack and the largest value in the stack: 7050
Read -3, Pop and print the value removed from the stack and the largest value in the stack: 5010
Read -2, Pop and print the value removed from the stack: 10(there are no values left in the stack)
END OF FILE
Display "Stack: Empty"
Format output as shown below
Input File: myFile.txt
Count: 0
Top: Empty
Pop: Empty
Pop: 30
Max: 50
Pop: 20
Max: 70
Pop: 70
Max: 50
Pop: 50
Max: 10
Pop: 10
Stack: Empty
Example 3
Display the following error message if the input file does not exist, and terminate the program.
There was an error opening "in.txt". Exiting.
Requirements
Start with reading and understanding the starter code in main.cpp and ``StackADT.h```. This is an incomplete program. Finish the program following the existing design (add other stand-alone functions if you wish).
Comments
Write a comment in the beginning of each source file, including your name and IDE Write a multi-line comment for each function definition. Write short one-line comments where appropriate.
Indentation and Spacing
Proper indentation and spacing enhances the readability of your code.
Indent everything in main() and other functions.
Always indent within curly braces.
Use one space after comma and no space in front of it
Leave one blank line between the two sections of any function.
Use blanks around binary operators: score1+ score2
No blanks for unary operators: ++count;
#include
#include
#include
#include
#include "StackADT.h"
using namespace std;
void printInfo();
void processNumber(string, Stack &);
void printStack(Stack &);
int main()
{
printInfo();
cout << "Enter input file name: "<< endl;
string filename;
getline(cin, filename); // assume valid
// declare stack here
// call process Numbers()
// call printStack()
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!