InterviewSolution
Saved Bookmarks
| 1. |
Write the definition of a member function push() for a class Library in C++ to insert a book information in a dynamically allocated stack of books considering the following code is already written as a part of the program:struct book{int bookid;char bookname[20];book *next;};class Library{book *top;public:Library(){top=NULL;}void push();void pop();void disp();~Library();}; |
|
Answer» void Library::push() { book *nptr; nptr=new book; cout<<"Enter values for bookid and bookname"; cin>>nptr->bookid; gets(nptr->bookname); nptr->next=NULL; if(top==NULL) top=nptr; else { nptr->next=top; top=nptr; } } |
|