#include<iostream.h>
#include<conio.h>
#include<string.h>
int ans=0;
class books
{
char *ath,*tt,*pb;
int p,stock;
public:void accept();
void sale(char a[20],char b[20],char c[20],int d,int no);
void purch();
void display();
};
void books::accept()
{
ath=new char[20];
tt=new char[20];
pb=new char[20];
cout<<"\nenter author name:-";
cin>>ath;
cout<<"\nenter title:-";
cin>>tt;
cout<<"\nenter publisher name:-";
cin>>pb;
cout<<"\nenter price:-";
cin>>p;
cout<<"\nenter how much you have stock:-";
cin>>stock;
}
void books::sale(char a[20],char b[20],char c[20],int d,int no)
{
int x,y,z;
x=strcmp(a,ath);
y=strcmp(b,tt);
z=strcmp(c,pb);
if(x==0&&y==0&&z==0&&d==p&&no<=stock)
{
stock=stock-no;
ans=1;
}
}
void books::purch()
{
ath=new char[20];
tt=new char[20];
pb=new char[20];
cout<<"\nenter book details for purchasing\n\n";
cout<<"\nenter author name:-";
cin>>ath;
cout<<"\nenter title:-";
cin>>tt;
cout<<"\nenter publisher name:-";
cin>>pb;
cout<<"\nenter price:-";
cin>>p;
cout<<"\nenter number of copy is to be purchased:-";
cin>>stock;
}
void books::display()
{
cout<<"\n"<<ath<<"\t"<<tt<<"\t"<<pb<<"\t"<<p<<"\t"<<stock<<"\n";
}
int main()
{
books bk[10];
clrscr();
for(int i=0;i<2;i++)
bk[i].accept();
char a[20],b[20],c[20];
int d,no;
cout<<"\nenter book details for selling\n\n";
cout<<"\nenter author name:-";
cin>>a;
cout<<"\nenter title:-";
cin>>b;
cout<<"\nenter publisher name:-";
cin>>c;
cout<<"\nenter price:-";
cin>>d;
cout<<"\nenter number of copy is to be sold:-";
cin>>no;
for(i=0;i<2;i++)
bk[i].sale(a,b,c,d,no);
if(ans==1)
cout<<"book was sold successfully";
else
{
cout<<"sorry you dont have sufficient stock\nyou need to purchase the book\n";
bk[i++].purch();
}
cout<<"\ndetails of all books\n";
for(int j=0;j<i;j++)
bk[j].display();
getch();
return 0;
}
/*
enter price:-12
enter how much you have stock:-4
enter author name:-we
enter title:-rt
enter publisher name:-fgg
enter price:-12
enter how much you have stock:-567
enter book details for selling
enter author name:-e
enter title:-f
enter publisher name:-t
enter price:-4
enter number of copy is to be sold:-6
sorry you dont have sufficient stock
you need to purchase the book
enter book details for purchasing
enter author name:-a
enter title:-c
enter publisher name:-b
enter price:-32
enter number of copy is to be purchased:-55
details of all books
qw er df 12 4
we rt fgg 12 567
a c b 32 55
*/
#include<conio.h>
#include<string.h>
int ans=0;
class books
{
char *ath,*tt,*pb;
int p,stock;
public:void accept();
void sale(char a[20],char b[20],char c[20],int d,int no);
void purch();
void display();
};
void books::accept()
{
ath=new char[20];
tt=new char[20];
pb=new char[20];
cout<<"\nenter author name:-";
cin>>ath;
cout<<"\nenter title:-";
cin>>tt;
cout<<"\nenter publisher name:-";
cin>>pb;
cout<<"\nenter price:-";
cin>>p;
cout<<"\nenter how much you have stock:-";
cin>>stock;
}
void books::sale(char a[20],char b[20],char c[20],int d,int no)
{
int x,y,z;
x=strcmp(a,ath);
y=strcmp(b,tt);
z=strcmp(c,pb);
if(x==0&&y==0&&z==0&&d==p&&no<=stock)
{
stock=stock-no;
ans=1;
}
}
void books::purch()
{
ath=new char[20];
tt=new char[20];
pb=new char[20];
cout<<"\nenter book details for purchasing\n\n";
cout<<"\nenter author name:-";
cin>>ath;
cout<<"\nenter title:-";
cin>>tt;
cout<<"\nenter publisher name:-";
cin>>pb;
cout<<"\nenter price:-";
cin>>p;
cout<<"\nenter number of copy is to be purchased:-";
cin>>stock;
}
void books::display()
{
cout<<"\n"<<ath<<"\t"<<tt<<"\t"<<pb<<"\t"<<p<<"\t"<<stock<<"\n";
}
int main()
{
books bk[10];
clrscr();
for(int i=0;i<2;i++)
bk[i].accept();
char a[20],b[20],c[20];
int d,no;
cout<<"\nenter book details for selling\n\n";
cout<<"\nenter author name:-";
cin>>a;
cout<<"\nenter title:-";
cin>>b;
cout<<"\nenter publisher name:-";
cin>>c;
cout<<"\nenter price:-";
cin>>d;
cout<<"\nenter number of copy is to be sold:-";
cin>>no;
for(i=0;i<2;i++)
bk[i].sale(a,b,c,d,no);
if(ans==1)
cout<<"book was sold successfully";
else
{
cout<<"sorry you dont have sufficient stock\nyou need to purchase the book\n";
bk[i++].purch();
}
cout<<"\ndetails of all books\n";
for(int j=0;j<i;j++)
bk[j].display();
getch();
return 0;
}
/*
enter price:-12
enter how much you have stock:-4
enter author name:-we
enter title:-rt
enter publisher name:-fgg
enter price:-12
enter how much you have stock:-567
enter book details for selling
enter author name:-e
enter title:-f
enter publisher name:-t
enter price:-4
enter number of copy is to be sold:-6
sorry you dont have sufficient stock
you need to purchase the book
enter book details for purchasing
enter author name:-a
enter title:-c
enter publisher name:-b
enter price:-32
enter number of copy is to be purchased:-55
details of all books
qw er df 12 4
we rt fgg 12 567
a c b 32 55
*/
No comments:
Post a Comment