-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance
More file actions
318 lines (275 loc) · 5.72 KB
/
Copy pathInheritance
File metadata and controls
318 lines (275 loc) · 5.72 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
Imagine a publishing company which does marketing for book and audiocassette versions.
Create a class publication that stores the title (a string) and price (type float) of a publication.
From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float).
Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members.
If an exception is caught, replace all the data member values with zero values.
*/
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
class Publisher
{
public:
char title[20];
float price;
};
class Book:public Publisher
{
public:
int m;
int page;
void accept();
void display();
};
void Book::accept()
{
cout<<"\n***************************";
cout<<"\nEnter name of book:";
cin>>title;
cout<<"\nEnter price of book:";
cin>>price;
cout<<"\nEnter number of pages of book:";
cin>>page;
}
void Book::display()
{
cout<<"\n"<<title<<"\t"<<price<<"\t"<<page;
}
class Cassette:public Publisher
{
public:
int m;
float min;
void accept1()
{
cout<<"\n***************************";
cout<<"\nEnter title of cassette:";
cin>>title;
cout<<"\nEnter price of cassette:";
cin>>price;
cout<<"\nEnter total time of record(minutes):";
cin>>min;
}
void display1()
{
cout<<"\n"<<title<<"\t"<<price<<"\t"<<min;
}
};
/*
int main()
{
int m,n;
cout<<"\nTotal no. of bookS:";
cin>>m;
Book b[m];
for(int i=0;i<m;i++)
{
b[i].accept();
}
cout<<"\n\t****BOOK DATA IS AS FOLLOWS****";
cout<<"\nTitle\tPrice\tPages";
for(int i=0;i<m;i++)
{
b[i].display();
}
cout<<"\nTotal no. of cassettes:";
cin>>n;
Cassette c[n];
for(int j=0;j<n;j++)
{
c[j].accept1();
}
cout<<"\n\t****CASSETTE DATA IS AS FOLLOWS****";
cout<<"\nTitle\tPrice\tMinutes";
for(int j=0;j<m;j++)
{
c[j].display1();
}
return 0;
}
*/
/*int main()
{
int m,n,x=0,y=0;
cout<<"\nTotal no. of bookS:";
cin>>m;
Book b[m];
for(int i=0;i<m;i++)
{
b[i].accept();
}
cout<<"\n\n\nTotal no. of cassettes:";
cin>>n;
Cassette c[n];
for(int j=0;j<n;j++)
{
c[j].accept1();
}
for(int i=0,j=0;i<m,j<n;i++,j++)
{
try
{
if((b[i].price>0||b[i].price<2000)&&(b[i].page>0||b[i].page<200))
{
throw(x);
}
if((c[j].price>0||c[j].price<2000)&&(c[j].min>0.0||c[j].min<45.6))
{
throw(y);
}
}
catch(int x)
{
cout<<"\nException Handled.";
b[i].price=0;
b[i].page=0;
}
catch(int y)
{
cout<<"\nException Handled.";
c[i].price=0;
c[i].min=0;
}
}
return 0;
}*/
int main()
{
int m,n,x=0,y=0,ch;
cout<<"\nTotal no. of bookS:";
cin>>m;
Book b[m];
for(int i=0;i<m;i++)
{
b[i].accept();
}
cout<<"\n\n\nTotal no. of cassettes:";
cin>>n;
Cassette c[n];
for(int j=0;j<n;j++)
{
c[j].accept1();
}
do{
cout<<"\n1.Display data of Books.";
cout<<"\n2.Display data of Cassette.";
cout<<"\n3.Exception handling of Books.";
cout<<"\n4.Exception handling of Cassettes.";
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n\t****BOOK DATA IS AS FOLLOWS****";
cout<<"\nTitle\tPrice\tPages";
for(int i=0;i<m;i++)
{
b[i].display();
}
break;
case 2:
cout<<"\n\t****CASSETTE DATA IS AS FOLLOWS****";
cout<<"\nTitle\tPrice\tMinutes";
for(int j=0;j<m;j++)
{
c[j].display1();
}
break;
case 3:
for(int i=0;i<m;i++)
{
try
{
if((b[i].price>0||b[i].price<2000)||(b[i].page>0||b[i].page<200))
{
throw(x);
}
}
catch(int x)
{
cout<<"\nException Handled for book "<<i+1<<".";
b[i].price=0;
b[i].page=0;
}
}
break;
case 4:
for(int j=0;j<n;j++)
{
try
{
if((c[j].price>0||c[j].price<200)||(c[j].min>0.0||c[j].min<45.6))
{
throw(y);
}
}
catch(int y)
{
cout<<"\nException Handled for cassette "<<j+1<<".";
c[j].price=0;
c[j].min=0;
}
}
break;
}
}while(ch!=5);
}
/*
OUTPUT:-
Total no. of bookS:2
***************************
Enter name of book:t
Enter price of book:32
Enter number of pages of book:65
***************************
Enter name of book:e
Enter price of book:65
Enter number of pages of book:654
Total no. of cassettes:2
***************************
Enter title of cassette:e
Enter price of cassette:6
Enter total time of record(minutes):65
***************************
Enter title of cassette:w
Enter price of cassette:6
Enter total time of record(minutes):61
1.Display data of Books.
2.Display data of Cassette.
3.Exception handling of Books.
4.Exception handling of Cassettes.
Enter your choice:1
****BOOK DATA IS AS FOLLOWS****
Title Price Pages
t 32 65
e 65 654
1.Display data of Books.
2.Display data of Cassette.
3.Exception handling of Books.
4.Exception handling of Cassettes.
Enter your choice:2
****CASSETTE DATA IS AS FOLLOWS****
Title Price Minutes
e 6 65
w 6 61
1.Display data of Books.
2.Display data of Cassette.
3.Exception handling of Books.
4.Exception handling of Cassettes.
Enter your choice:3
Exception Handled for book 1.
Exception Handled for book 2.
1.Display data of Books.
2.Display data of Cassette.
3.Exception handling of Books.
4.Exception handling of Cassettes.
Enter your choice:4
Exception Handled for cassette 1.
Exception Handled for cassette 2.
1.Display data of Books.
2.Display data of Cassette.
3.Exception handling of Books.
4.Exception handling of Cassettes.
Enter your choice:
*/