-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinheritance.cpp
111 lines (106 loc) · 1.93 KB
/
inheritance.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
#include <iostream>
using namespace std;
class publication
{
string title;
float price;
public:void getdata()
{
cout<<"Enter title and price"<<endl;
cin>>title>>price;
try
{
if (title=="C++")
{
throw title;
}
}
catch(string ti)
{
title="0";
cout<<"Exception For Title is caught"<<endl;
}
try
{
if (price>800)
{
throw price;
}
}
catch(float pr)
{
price=0;
cout<<"Exception For price is caught"<<endl;
}
}
public:void display()
{
cout<<endl<<"The Title of the book is:"<<title<<endl<<"The price of the book is:"<<price<<endl;
}
};
class book : public publication
{
int pcount;
public:
void getcount();
void show();
};
void book:: getcount()
{
cout<<"Enter the no of pages"<<endl;
cin>>pcount;
try
{
if (pcount>800)
{
throw pcount;
}
}
catch(int p)
{
pcount=0;
cout<<"Exception For no of pages is caught"<<endl;
}
}
void book::show()
{
cout<<"No of pages of the book:"<<pcount<<endl;
}
class tape:public publication
{
float min;
public:
void getmin()
{
cout<<"Enter the time in minutes"<<endl;
cin>>min;
try
{
if (min>60)
{
throw min;
}
}
catch(float m)
{
min=0;
cout<<"Exception For minutes is caught"<<endl;
}
}
void showmin()
{
cout<<"The time in minutes of tape is:"<<min<<endl;
}
};
int main()
{
book b;
tape t;
b.getdata();
b.getcount();
t.getmin();
b.display();
b.show();
t.showmin();
return 0;
}