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 & Now you have to convert the stackstr 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 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:
Stackstrh a header file: the specification file to store the class definition
Stackstrcpp 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, and represent commands the rest of the integers represent data You may assume the input files contain valid data.
Each time we read display the number of elements in the stack.
Each time we read 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 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
If the input file contains the following numbers:
Process input:
Read Push
Read Push
Read Push
Read Display the element at the top of the stack and the largest value in the stack:
Read Push
Read Display the number of elements in the stack:
Read Push
Read Push
Read Pop and print the value removed from the stack and the largest value in the stack:
Read Display the number of elements in the stack:
Read Push
Read Push
Read Pop and print the value removed from the stack and the largest value in the stack:
Read Push
Read Push
END OF FILE
Display the stack from top to bottom: and
Format output as shown below
Input File: numberstxt
Top:
Max:
Count:
Pop:
Max:
Count:
Pop:
Max:
Stack:
Example
If the input file contains the following numbers:
Process input:
Read Display the number of elements in the stack:
Read Display "Top: Empty"
Read Display "Pop: Empty"
Read Push
Read Push
Read Push
Read Pop and print the value removed from the stack and the largest value in the stack:
Read Push
Read Push
Read Pop and print the value removed from the stack and the largest value in the stack:
Read Pop and print the value removed from the stack and the largest value in the stack:
Read Pop and print the value removed from the stack and the largest value in the stack:
Read Pop and print the value removed from the stack: there are no values left in the stack
END OF FILE
Display "Stack: Empty"
Format output as shown below
Input File: myFile.txt
Count:
Top: Empty
Pop: Empty
Pop:
Max:
Pop:
Max:
Pop:
Max:
Pop:
Max:
Pop:
Stack: Empty
Example
Display the following error message if the input file does not exist, and terminate the program.
There was an error opening intxt Exiting.
Requirements
Start with reading and understanding the starter code in main.cpp and StackADTh This is an incomplete program. Finish the program following the existing design add other standalone functions if you wish
Comments
Write a comment in the beginning of each source file, including your name and IDE Write a multiline comment for each function definition. Write short oneline 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: score score
No blanks for unary operators: count;
#include
#include
#include
#include
#include "StackADT.h
using namespace std;
void printInfo;
void processNumberstring Stack &;
void printStackStack &;
int main
printInfo;
cout "Enter input file name: endl;
string filename;
getlinecin filename; assume valid
declare stack here
call process Numbers
call printStack
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
