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


Please Help Members By Posting Answers For Below Questions

Where the memory to the static variables is allocated?

560


What are keywords in c++?

602


Why is main function important?

587


What is binary object model?

602


Name the operators that cannot be overloaded in C++?

585






Define private, protected and public access control.

609


What are static member functions?

617


What is srand c++?

581


What is object in c++ wikipedia?

570


How java is different from c and c++?

645


What are virtual functions in c++?

689


Who discovered c++?

560


Describe linked list using C++ with an example.

650


Can a program run without main?

630


Does c++ cost money?

582