| 1. |
Define a class to represent a book in a library. Include the following members: Data MembersBook Number, Book Name, Author, Publisher, Price, No. of copies issued, No. of copies Member Functions(i) To assign initial values(ii) To issue a book after checking for its availability(iii) To return a book(iv) To display book information. |
|
Answer» #include<iostream.h> #include<conio.h> #include<stidio.h> class Library { int BookNo; char BName[25]; char Author[25]; char Publisher[25]; float Price; int No_of_Copies; int No_of_Copies_Issued; public: void initial() { cout<<end1<<"Enter book number : "; cout <<BookNo; cout<<end1<<"Enter book name : "; gets (Bname); cout<<end1<<"Enter Author name : "; gets (Author); cout<<end1<<"Enter publisher name : "; gets (publisher); cout<<end1<<"Enter price : "; cin>>Price; cout<<endl<<"Enter Number of copies: "; cin>>No_of_Copies; } void issue_book () { cout<<"Enter book details......."<<end1; initial(); if(No_of_Copies>0) { cout<<"enter How many book you want to issue:"; cin>>No_of_Copies_Issued; if(No_of_Copies>=No_of_Copies_Issued) { No_of_Copies=No_of_Copies-No_of_Copies_Issued; cout<<endl<<" "<<No_of_Copies_Issued<<" book is issued.."; display(); } else { cout<<”Copies_Issued<<" books is not available in stock.."; } } else { cout<<"Book is not available"; } } void return_book() { cout<<"enter book detail you want to return..."; cout<<endl<<"Enter Book Number: "; cin>>BookNo; cout<<endl<<"Enter Book Name: "; gets(BName); No_of_Copies=No_of_Copies+No_of_Copies_Issued; cout<<endl<<BookNo<<":"<<BName<<"Book is returned......"; } void display() { cout<<"Book Number: "<<BookNo<<endl; cout<<"Book Name: "<<BName<<endl; cout<<"Author Name: "<<Author<<endl; cout<<"publisher Name: "<<Publisher<<endl; cout<<"Price: "<<Price<<endl; } }; void main () { clrscr(); Library 11; int ch; cout<<"1->Issue book...."<<end1; cout<<"2->Return Book....."<<end1; cout<<"Enter your choice .. "<<end1; cin>>ch; switch(ch) { case 1: 11.issue_book(); break; case 2: 11.return_book(); break; } getch(); |
|