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
How do you clear a buffer in c++?
Is c++ a dying language?
What is const pointer and const reference?
Differentiate between an external iterator and an internal iterator? What is the advantage of an external iterator.
What is the difference between public, private, and protected access?
How a new element can be added or pushed in a stack?
What is #include c++?
What is c strings syntax?
Why is polymorphism useful?
What is time h in c++?
Which is better c++ or java?
What is purpose of abstract class?
What does catch(…) mean?
Can we define a constructor as virtual in c++?
What is private, public and protected inheritance?