Write the definition of a member function PUSH( ) in C++, to add a new book in a dynamic stack of BOOKS considering the following code is already included in the program
struct BOOKS
{
char ISBN[20], TITLE[80];
BOOKS *Link;
};
class STACK
{
BOOKS *Top;
public:
STACK-() {Top=NULL;}
void PUSH();
void POP();
~STACK();
};
Advertisement Remove all ads
Solution
void STACK::PUSH()
{
BOOKS *Temp;
Temp = new BOOKS;
gets(Temp ->ISBN);
gets(Temp ->TITLE);
Temp->Link=Top;
Top = Temp;
}
Concept: Member of a Class - Data Members and Member Functions (Methods)
Is there an error in this question or solution?
Advertisement Remove all ads
APPEARS IN
Advertisement Remove all ads
Advertisement Remove all ads