-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublicationSystem.cpp
More file actions
123 lines (98 loc) · 2.45 KB
/
Copy pathPublicationSystem.cpp
File metadata and controls
123 lines (98 loc) · 2.45 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
#include<iostream>
using namespace std;
class Publication
{
protected:
string title;
float price;
public:
void getPublication()
{
cout << "Enter the title: ";
cin >> title;
cout << "Enter the price: ";
cin >> price;
if(price < 0)
throw(price);
}
void displayPublication()
{
cout << "Title: " << title << endl;
cout << "Price: " << price << endl;
}
void resetPublication()
{
title = "";
price = 0.0;
}
};
class Book : public Publication
{
private:
int pageCount;
public:
void getData()
{
try
{
getPublication();
cout << "Enter page count: ";
cin >> pageCount;
if(pageCount < 0)
throw pageCount;
}
catch (...)
{
cout << "\nInvalid Input: Exception Caught.\n";
resetPublication();
pageCount = 0;
}
}
void displayData()
{
cout << "\n============== Book Details ==============" << endl;
displayPublication();
cout << "Page Count: " << pageCount << endl;
}
};
class Tape : public Publication
{
private:
float playTime;
public:
void getData()
{
try
{
getPublication();
cout << "Enter playing time (min): ";
cin >> playTime;
if (playTime == 0)
throw playTime;
}
catch (...)
{
cout << "\nInvalid Input: Exception Caught.\n";
resetPublication();
playTime = 0;
}
}
void displayData()
{
cout << "\n============== Tape Details ==============" << endl;
displayPublication();
cout << "Playing Time: " << playTime << " minutes" << endl;
}
};
int main(){
Book b;
Tape t;
cout << "Enter Book Details\n";
b.getData();
cout << "Enter Tape Details\n";
t.getData();
cout << "\n============== Publication Information ==============\n";
b.displayData();
t.displayData();
return 0;
}