implement stack using stack.h headerfile functions
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 ? | 4 Yes | 4 No |
Post New Answer View All Answers
What is the use of volatile variable?
How to get the current position of the file pointer?
What are structures and unions?
Out of fgets() and gets() which function is safe to use and why?
What is the output of the following program? Why?
What c++ is used for?
If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?
What causes a runtime error c++?
What is the auto keyword good for in c++?
How many different levels of pointers are there?
What is virtual base class?
Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).
Differentiate between the message and method in c++?
Do you know what is overriding?
What is function prototyping?