The bookstore keeps an inventory of the books it sells. The listing includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the seller enters the title and author, and the system searches the list to see if it's available or not. If this is not the case, a corresponding message will be displayed. If so, the system will display the book details and the requested number of copies. If copies are requested, details of the book and requirements for the number of copies requested. If the requested copies are available, the total price of the requested copies will be displayed; otherwise the message ?The requested copies are not in stock? is displayed. Design the system using a class called book with appropriate member functions and constructors. Use the new operator in constructors to allocate the required memory space. Implement a C++ program into the system

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message?Required copies not in stock? is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system.

OUTPUT FOR THE PROGRAM
#include<iostream>
#include<string.h>
using namespace std;

class book
{
char author[50],title[50],publisher[50];
int price,stock;
public:
book();
void get_data();
void display_data();
int search(char [],char []);
void copies(int);
};
book::book()
{
char *author=new char[50];
    char * title=new char[50];
    char *publisher=new char[50];
    price=0;
    stock=0;
}

void book::get_data()
{
cout<<"\nEnter name of the author: ";
cin>>author;
cout<<"\nEnter title of the book: ";
cin>>title;
cout<<"\nEnter publisher of the book: ";
cin>>publisher;
cout<<"\nEnter price of the book: ";
cin>>price;
cout<<"\nEnter stock of book: ";
cin>>stock;
}

void book::display_data()
{
cout<<"\n";
cout<<author<<"\t"<<title<<"\t"<<publisher<<"\t"<<price<<"\t"<<stock;
}

int book::search(char a[50],char b[50])
{

if(strcmp(author,a) && strcmp(title,b))
{
return 1;
}
else
return 0;
}

void book::copies(int cop)
{
if(stock>=cop)
{
cout<<"\nPrice for "<<cop<<" copies is: "<<(price*cop);
}
else
cout<<"\n*Not available*";
}

int main()
{
cout<<"\t\t***Book Inventory***";
int i,choice,flag,n,key,c;
char con;
char s_author[50],s_title[50];
book b[50];
do
{
cout<<"\n1)Upgrade the inventory\n2)Display\n3)Search the book\n";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"\nHow many books do you want to involve: ";
cin>>n;
for(i=0;i<n;i++)
{
b[i].get_data();
}
break;
}
case 2:
{
cout<<"\nAuthor\tTitle\tPublisher\tPrice\tStock";
for(i=0;i<n;i++)
{
b[i].display_data();
}
break;
}
case 3:
{
cout<<"\nEnter the name of the author: ";
cin>>s_author;
cout<<"\nEnter the title of the book: ";
cin>>s_title;
for(i=0;i<n;i++)
{
if(b[i].search(s_author,s_title))
{
key=i;
flag=1;
if(flag==1)
{
cout<<"\nBook is available";
}
else
{
cout<<"\nNo such book in the inventory";
break;
}
}
}
if(flag==1)
{
cout<<"\nEnter no. of copies you want: ";
cin>>c;
b[key].copies(c);
}
break;
}
}
cout<<"\nDo you want to continue(y/n): ";
cin>>con;
}
while(con!='n');
return 0;
}


For more such posts click the link:-http://svencrai.com/G8W

4 Comments

  1. Hello, could you explain what does it mean "void book::showdata()" ?

    ReplyDelete
  2. There is little mistake while creating the bill... As in for loop i will be incremented by 1 so as the key so the bill for the adjacent book will be displayed.

    ReplyDelete
Previous Post Next Post