>I just started learning about stacks so I am uncertain if I solved it the best way.
It depends what your definition of best way is. If this is an assignment it will probably suffice.
Personally, I would have used classes instead of structs. Does it really matter? Probably not, just preference here.
Also, you could have designed your stack using templates instead. The advantage for doing this means that you can declare a stack of a generic type. Say a stack of strings, or integers. However, in your case, this criteria probably isn't important.
Just one other thing, void main, change that to int main.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
The throw/catch stuff is nice, and eventually you should learn how to use it, but for now I'd concentrate on the use of stacks and use of classes/structs (the only difference between classes and structs in C++ is that struct members have public access by default whereas class members have private access by default). Your functions to manipulate and interrogate stacks seem logical from what I can tell, but I would suggest you learn about member functions instead of stand alone function to do the manipulation. In particular I would suggest you replace your current functions with functions that are members of the stack struct (don't erase your current functions, the function bodies will be the same, it's just how you declare them and the syntax for defining them outside the interface that's different). I would also suggest you learn about data access by making the member variables private rather than public and how to use public accessor and mutator functions to access and manipulate the data. Learning how to write operators that allow you to write/read from screen/file, copy one object to another, use dynamic memory to declare size of stack on the fly, compare one struct object to another, assign one struct object to another, etc. would all be cool and very educational. I'd also suggest you learn how to put the interface into a header file and the implementation into a cpp file. You could even consider implementing a template version of the stack class. After all that then I'd toss throw/catch stuff to assist validating data entry and allowing user to expeditiously correct data entry mistakes without turning off or crashing program for a truly modern milly version of your current program.
In other words you've got a good start and seem to understand what to do with stacks in general, now learn how to leverage that knowledge in the spirit of C++ having fun along the way!
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396