Create a class for inventory of books containing
author, title, price, and publisher and stock as data members. Book can be sold, if stock is available, otherwise purchase will be made. Write necessary member functions for the following:
1. To accept details from user
2. To sale a book. (Sale contains book details & number of copies to be sold.)
3. To Purchase a book. (Purchase contains book details & number of copies to be purchased)
(Use new operator to allocate memory).
#include<iostream.h>
#include<conio.h>
class inventory
{
char author[10];
char title[10];
float price;
char publisher[10];
int stock;
public:
void getdata( )
{
cout<<"\n Enter Author Name:-";
cin>>author;
cout<<"\n Enter Title:-";
cin>> title;
cout<<"\n Enter the price:-";
cin>>price;
cout<<"\n Enter the publisher:-";
cin>> publisher;
cout<<"\n Enter the Stock:-";
cin>> stock;
}
void show()
{
cout<<"\n Author:- "<<author;
cout<<"\n Title:- "<<title;
cout<<"\n Price:- "<<price;
cout<<"\n Publisher:- "<<publisher;
cout<<"\n Stock:- "<<stock;
}
};
const int size=2;
void main()
{
inventory * p=new inventory[size];
inventory * d=p;
int x,i,z;
char a[5],b[5],c[5];
float y;
clrscr();
for(i=0;i<size;i++)
{
cout<<"\n Input Author,Title,Price,Publisher,stock:-"<<i+1;
p->getdata();
p->show();
p++;
}
for(i=0;i<size;i++)
{
cout<<"\n Inventory:"<<i+1;
d->show();
d++;
}
getch();
}
author, title, price, and publisher and stock as data members. Book can be sold, if stock is available, otherwise purchase will be made. Write necessary member functions for the following:
1. To accept details from user
2. To sale a book. (Sale contains book details & number of copies to be sold.)
3. To Purchase a book. (Purchase contains book details & number of copies to be purchased)
(Use new operator to allocate memory).
#include<iostream.h>
#include<conio.h>
class inventory
{
char author[10];
char title[10];
float price;
char publisher[10];
int stock;
public:
void getdata( )
{
cout<<"\n Enter Author Name:-";
cin>>author;
cout<<"\n Enter Title:-";
cin>> title;
cout<<"\n Enter the price:-";
cin>>price;
cout<<"\n Enter the publisher:-";
cin>> publisher;
cout<<"\n Enter the Stock:-";
cin>> stock;
}
void show()
{
cout<<"\n Author:- "<<author;
cout<<"\n Title:- "<<title;
cout<<"\n Price:- "<<price;
cout<<"\n Publisher:- "<<publisher;
cout<<"\n Stock:- "<<stock;
}
};
const int size=2;
void main()
{
inventory * p=new inventory[size];
inventory * d=p;
int x,i,z;
char a[5],b[5],c[5];
float y;
clrscr();
for(i=0;i<size;i++)
{
cout<<"\n Input Author,Title,Price,Publisher,stock:-"<<i+1;
p->getdata();
p->show();
p++;
}
for(i=0;i<size;i++)
{
cout<<"\n Inventory:"<<i+1;
d->show();
d++;
}
getch();
}