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
Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?
Why cstdlib is used in c++?
If a function doesn’t return a value, how do you declare the function?
What do you understand by pure virtual function? Write about its use?
What is a singleton class c++?
Which function cannot be overloaded c++?
How should a contructor handle a failure?
Explain the use of virtual destructor?
What is encapsulation in c++ with example?
When to use “const” reference arguments in a function?
What is a forward referencing and when should it be used?
what does the following statement mean? int (*a)[4]
Is c++ a programming language?
What is stack unwinding?
Why c++ is so important?