Array based stack



What is a stack

Menu driven main copy over all the provided files you want to be sure to use the -R option when you copy so that you also copy over the testfiles directory for this lab you will produce a menu driven main and 3 test files to test some functions on the standard template library stack. the std::stack is a templated class and the Macro ELEMTYPE is going to be the data type that your menu driven program will accept This main will be the foundation for the main to test ALL of your upcoming homework. It is requred that you be able to redirect in input commands from a file. In order for you program to work you should not use std::cin. There are a couple functions in cmpslib.h that will clean up user input and make writing your main much simpler, furthermore you program will likely not work properly if you do not use these funcitons. They are designed to clean up the buffers, validate that the input is the correct datatype and simply ask the user to re-enter the value again if it is not.. inline void Prompt (string prompt, T & val) inline void Prompt( string prompt,T& val, T minval, T maxval) It is YOUR responstibilty to make sure that your (stack, queue, linked list ....) work properly. You will produce a menu driven main so to ease testing but then you must also test your code and make sure that it works. NOTE: The goal here is to TEST the stack!! you dont have a stack to test so we are going to use the standard template library statck. the STL stack does not have anything to prevent you from doing stupid stuff. IT is designed to try to be as efficent as possible so it doesnt have many built in safeguards. since we are using the std::stack for the stack in this lab yours should cause a segmentation fault when you call top on and empty container the size function returns an integer to show how many items are in the stack.. try using pop when the stack is emply and see what the size is , you will be surprised. Simply put for all your upcoming menu driven assignments your code must perform EXACTLY like the examples when you redirect in all the provided test files. If it does not match exactly you will not get full credit. ALSO: just because it works with all my provided test files DOES NOT mean your stack works properly.. I generally grade them with even more complex test files than the ones I provide for you... The only time it is my responsibilty to test your code for you is when i grade it, prior to that it is YOUR responsibilty to test it. in your stack homework you will create your own stack class , in this lab we will use the stack implementation of the standard template library, stl::stack you wil want to add some aditional logic to your STACK class to prevent the issues we are seing with the STL stack but you main that you are writing today can remain relativly the same , do not any logid to avoid the errors we see today to you main.. all of that is to be done in the stack class. it is crucial that your test main for the labs and homework should behave exactly like this one AND that it behaves the same when you redirect in the user input from a file. I WILL test and grade your stack by reidirecting in a file conatining the keystrokes to perform many different function calls This lab will provide a base for the menu driven mains to test many of the container classes we will produce moving forward Stack, Queue, Linked List and Binary Search Tree will all use this method of testing in order to make sure there will be several test files to try against your menu driven program instead of typing in a bunch of commands to the menu driven main we can redirect a file ./runme_int < testfiles/testinput1_int should have the exact same ouput as ./example_int < testfiles/testinput1_int ./runme_string < testfiles/testinput1_string should have the exact same ouput as ./example_string < testfiles/testinput1_string ./runme_fraction < testfiles/testinput3_fraction should have the exact same ouput as ./example_fraction < testfiles/testinput3_fraction you will make 3 files mytestfile_int, mytestfile_fraction and mytestfile_string add 5 values, call top then delete , 5 times ( on your homeworks you will want to delete more than you inserted to be sure ) add 5 different values call size call top then delete , 5 times call size you should also be able to chain commands together sei50ti40ti60tsddex