-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.this_ptr.cpp
139 lines (119 loc) · 2.35 KB
/
11.this_ptr.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
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
//REMEMBER ONLY ONE CLASS pg 3-31
class book
{
private:
char author_name[20];
char title[20];
int price;
bool status=true;
public:
book()
{
strcpy(this->author_name,"");
strcpy(this->title,"");
this->price=0;
}
void add_book()
{
cout<<"\nenter title : ";
cin>>this->title;
cout<<"enter author name : ";
cin>>this->author_name;
cout<<"enter price : ";
cin>>this->price;
cout<<"\n";
}
void display_database()
{
cout<<"Title : "<<this->title<<endl;
cout<<"Author : "<<this->author_name<<endl;
cout<<"Price : "<<this->price<<endl;
cout<<"\n******\n";
}
bool buy_book(char search_title[],int quantity) //IMP
{
bool found=false;
if(strcmp(this->title,search_title)==0)
{
int cnt=0;
cnt=quantity*this->price;
cout<<"total price : "<<cnt;
found=true;
return found;
}
return found;
}
int delete_database(char delete_title[])
{
if(strcmp(this->title,delete_title)==0)
{
return 0;
}
return 1;
}
};
main()
{
int N;
cout<<"\nEnter no. of book data to be enter : ";
cin>>N;
book b[N];
char search_title[20];
int quantity;
char delete_title[20];
int op=-1;
int i,del[N],j;
while(op!=0)
{
cout<<"\n1.ADD A BOOK";
cout<<"\n2.DISPLAY DATABASE";
cout<<"\n3.BUY A BOOK";
cout<<"\n4.DELETE A BOOK";
cout<<"\n5.EXIT";
cout<<"\n\nENTER CHOICE : ";
cin>>op;
switch(op)
{
case 1:
for( i=0;i<N;i++)
{
b[i].add_book();
}
break;
case 2:
for(i=0,j=0;i<N;i++,j++)
{
if(del[j]==0)
break;
b[i].display_database();
}
break;
case 3:
cout<<"enter the title of book to buy & quantity : ";
cin>>search_title>>quantity;
for(i=0;i<N;i++)
{
if(b[i].buy_book(search_title,quantity))
break;
}
if(i==N)
cout<<"Book not available";
break;
case 4:
cout<<"Enter title of book to delete : ";
cin>>delete_title;
for( i=0,j=0;i<N;i++,j++)
{
del[j]=b[i].delete_database(delete_title);
}
break;
case 5:
op=0;
break;
}
}
}