Wednesday, October 1, 2014

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 request for the no 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.

Algorithm:
1.      Start of program
2.      Set global variable count=0
3.      Create a class with member functions input(),value() and display() which returns value.
4.      Input record of books (author, title, price, publisher).
5.      Enter the book to be sold.
6.      int f=b[i].t_value(a,t);
a.       if(f==1), dis=1,  b[i].display(q), calling the display() member function from class.
  if(dis!=1) print The book is not in store";
7.      end of program

Code:
#include
#include
#include
int count=0;
class books
{
   char author[40],title[40],publisher[40];
   float price;
   int sp;
   public:
   books()
   {
   count++;
   }//constructor
   void input(char a[40],char t[40],float p,char pub[40],int s)
   {
      strcpy(author,a);
       strcpy(title,t);
       price=p;
       strcpy(publisher,pub);
       sp=s;
   }
   int t_value(char a[40],char t[40])
   {
      if( strcmpi(author,a)==0 && strcmpi(title,t)==0)
                  return 1;
       else
                  return 0;
   }
   void display(int qty)
   {
       cout<
        cout<
        cout<
        cout<
        if(qty>sp)
                   cout<
        else
                   cout<
   }
};


main()
{
      books b[2];
      char a[40],t[40],pub[40];
       float p;
       int s,q,dis;
       cout<<"Input the records of two books!";
       for(int i=0;i<2 i="" o:p="">
       {
      cout<>a;
      cout<<"Title: "; cin>>t;
      cout<<"Price: "; cin>>p;
      cout<<"Publisher: ";cin>>pub;
      cout<<"Number of books in store: ";cin>>s;
      b[i].input(a,t,p,pub,s);
     }
   cout<
   cout<>a;
   cout<<"Title: "; cin>>t;
   cout<<"Number of copies: ";cin>>q;
   for(int i=0;i<2 i="" o:p="">
   {
      int f=b[i].t_value(a,t);
      if(f==1)
      {
     dis=1;
      b[i].display(q);
      }
   }
   if(dis!=1)
      cout<<"The book is not in store";
      getch();

}

No comments:

Post a Comment