-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOP_Prac03.cpp
141 lines (122 loc) · 2.66 KB
/
OOP_Prac03.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
#include <iostream>
using namespace std;
class publication
{
string title;
float price;
public:
void add()
{
cout << "\n\nEnter the Information of the Publication" << endl;
cout << "Enter the title of the publication: ";
cin.ignore();
getline(cin, title);
cout << "Enter the price of the publication: ";
cin >> price;
}
void display()
{
cout << "\n\nTitle of the publication: " << title << endl;
cout << "Price of the publication: " << price << endl;
cout<<endl;
}
};
class book : public publication
{
private:
int page_count;
public:
void add_book()
{
try
{
add();
cout << "Enter the page count: ";
cin >> page_count;
if (page_count <= 0)
{
throw page_count = 0;
}
}
catch (...)
{
cout << "Invalid page count" << endl;
page_count = 0;
}
}
void display_book()
{
display();
cout << "page count: " << page_count << endl;
}
};
class tape : public publication
{
private:
float play_time;
public:
void add_tape()
{
try
{
add();
cout << "Enter play time (mins): ";
cin >> play_time;
if (play_time <= 0)
{
throw play_time = 0;
}
}
catch (...)
{
cout << "Invalid play time Entered" << endl;
play_time = 0;
}
}
void display_tape()
{
display();
cout << "Play time is: " << play_time << endl;
}
};
int main()
{
book b1[10];
tape t1[10];
int ch = 0, b_count = 0, t_count = 0;
do
{
cout << "\n*** Publication Details ***" << endl;
cout << "1.Add Book details\n2.Add Tape details\n3.Diplay Book details\n4.Display Tape details\n5.Exit\nEnter Your Choice: ";
cin >> ch;
switch (ch)
{
case 1:
b1[b_count].add_book();
b_count++;
break;
case 2:
t1[t_count].add_tape();
t_count++;
break;
case 3:
for (int i = 0; i < b_count; i++)
{
b1[i].display_book();
}
break;
case 4:
for (int i = 0; i < t_count; i++)
{
t1[i].display_tape();
}
break;
case 5:
cout << "*** Terminated Successfully ***" << endl;
break;
default:
break;
}
} while (ch != 5);
return 0;
}