Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
371 views
in Computer by (50.9k points)
closed by

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(); 

};

1 Answer

+1 vote
by (45.3k points)
selected by
 
Best answer

void Library::push() 

book *nptr; 

nptr=new book; 

cout<<"Enter values for bookid and bookname";

cin>>nptr->bookid>>nptr->bookname;

nptr->next=NULL; 

if(top==NULL)

top=nptr; 

else 

nptr->next=top; 

top=nptr: 

}

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...