write a program in c++ to implement stack using functions
in header file stack.h
Answer Posted / sv
#include <iostream>
#include <stack>
using namespace std;
int main()
{
string title;
int howmany;
stack<string> discs;
//Asking the user how many discs he wants to enter in the
stack.
//The loop will rotate that many number of times and then
//prompt the user for input.
cout<<"How many discs :";
cin>>howmany;
for(int i=0;i>title;
//pushing the discs one upon the other
discs.push(title);
}
cout<<"Now at the top of the CD Stack we have :"<<discs.top
()<<endl;
cout<<"The first one entered is "<<endl;
while(!discs.empty())
{
title = discs.top();
discs.pop();
}
cout<<title<<endl;
return 0;
}
| Is This Answer Correct ? | 31 Yes | 29 No |
Post New Answer View All Answers
Tell me what are static member functions?
Explain the differences between list x; & list x();.
How java is different from c and c++?
What is the difference between strcpy() and strncpy()?
Define anonymous class.
How can you differentiate between inheritance and implementation in c++?
What are the rules for naming an identifier?
What is function overloading in C++?
How can I learn dev c++ programming?
What is ctime c++?
In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h
Explain the difference between new() and malloc() in c++?
What does count ++ do in c++?
Explain the difference between c++ and java.
Is std :: string immutable?