-
Notifications
You must be signed in to change notification settings - Fork 48
/
bookstall.cpp
158 lines (129 loc) · 2.4 KB
/
bookstall.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include<iostream>
#include<string.h>
using namespace std;
class book
{
private:
char title[100];
char author[100];
char publisher[100];
float price;
int stock;
public:
static int avai_stock;
void read();
void print();
void add();
int search(char t[10]);
int purchase(char t[10]);
//static void sucessful();
};
int book::avai_stock;
void book::read()
{
cin>>title>>author>>publisher>>price>>stock;
book::avai_stock=avai_stock+stock;
}
void book::print()
{
cout<<title<<" "<<author<<" "<<publisher<<" "<<price<<" "<<stock<<endl;
}
void book::add()
{
cin>>title>>author>>publisher>>price>>stock;
book::avai_stock++;
}
int book::search(char t[10])
{
int flag=1;
flag=strcmp(author,t);
if(flag==0)
{
cout<<title<<" "<<author<<" "<<publisher<<" "<<price<<" "<<stock<<endl;
return flag;
}
flag=1;
return flag;
}
int book::purchase(char t[10])
{
int st;
int flag=1;
flag=strcmp(author,t);
if(flag==0)
{
cout<<"\n enter no. of copies to purchase:";
cin>>st;
stock=stock+st;
cout<<title<<" "<<author<<" "<<publisher<<" "<<price<<" "<<stock<<endl;
return flag;
}
flag=1;
return flag;
}
int main()
{
int i,n=0,ch,j=0;
char x[40];
book* b1= new book[100];
do
{
cout<<"1)read"<<endl<<"2)display"<<endl<<"3)add"<<endl<<"4)search"<<endl<<"5)purchase"<<endl;
cout<<"6)quit"<<endl;
cout<<"enter ur choice:";
cin>>ch;
switch(ch)
{
case 1: cout<<"enter the no. of books in library:"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"enter the title,author,publisher price and stock:"<<endl;
b1[i].read();
}
break;
case 2: cout<<"----------------------list of books in stall------------------------------------"<<endl;
cout<<"********************************************************************************"<<endl;
cout<<"title is: "<<"author is: "<<"publisher is: "<<"price is: "<<"stock is: "<<endl;
for(i=0;i<n;i++)
{
b1[i].print();
}
break;
case 3: cout<<"enter the title,author,publisher and price & stock :"<<endl;
b1[n].add();
n++;
break;
case 4: cout<<"enter the author name to search";
cin>>x;
for(i=0;i<n;i++)
{
j=b1[i].search(x);
}
if(j==1)
{
cout<<"book nt found"<<endl;
}
else
{
cout<<"book found"<<endl;
}
break;
case 5: cout<<"enter the author name to purchase:";
cin>>x;
for(i=0;i<n;i++)
{
j=b1[i].purchase(x);
}
if(j==1)
{
cout<<"enter the title,author,publisher and price:"<<endl;
b1[n].add();
n++;
}
break;
case 6: break;
}
}while(ch!=6);
return 0;
}