My assignment is to create a first in last out data structure but it must be able to take floats and strings. function overloading is supposed to be used for the push() method. I tried figure out how to make it take strings and floats but i failed miserably so i came here hoping to get steared on the right track (Im new to this forum and still new to programming). heres my code so far.......
Thanks any of your help will be greatly apreciated.Code:#include <iostream> #define SIZE 4 class stack { private: int top_of_stack; double data[SIZE]; public: int init(); stack(); int push(int put_on_stack); float push(float put_on_stack); char push( char put_on_stack); int pop(); }; int main() { using std::cout; using std::cin; using std::endl; stack s1; s1.push(58); s1.push(23); s1.push(12); s1.push(23); s1.push(54); s1.pop(); s1.pop(); s1.pop(); s1.pop(); s1.pop(); s1.pop(); cin.ignore(); } stack::stack() { top_of_stack = 0; } int stack::init() { top_of_stack = 0; } int stack::push(int put_on_stack) { if (top_of_stack >= SIZE) { std::cout<<"Stack is Full!!"<<std::endl; } data[top_of_stack] = put_on_stack; ++top_of_stack; } float stack::push(float put_on_stack) { if (top_of_stack >= SIZE) { std::cout<<"Stack is Full!!"<<std::endl; } data[top_of_stack] = put_on_stack; ++top_of_stack; } int stack::pop() { if (top_of_stack == 0) { std::cout<<"Nothing on Stack!!"; return 0; } top_of_stack--; std::cout<< data[top_of_stack]<<std::endl; }



LinkBack URL
About LinkBacks


