-
Notifications
You must be signed in to change notification settings - Fork 12
/
GroupA_Practical3.cpp
146 lines (145 loc) · 3.05 KB
/
GroupA_Practical3.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
142
143
144
145
146
/*
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<stdio.h>
using namespace std;
class publication // declaring class Publication
{
private:
string title;
float price;
public:
void add()
{
cout << "\nEnter the Publication information : " << endl;
cout << "Enter Title of the Publication : ";
cin.ignore();
getline(cin, title);
cout << "Enter Price of Publication : ";
cin >> price;
}
void display()
{
cout << "\n--------------------------------------------------";
cout << "\nTitle of Publication : " << title;
cout << "\nPublication Price : " << price;
}
};
class book : public publication // declaring class book which inherits class publication in public mode.
{
private:
int page_count;
public:
void add_book()
{
try
{
add();
cout << "Enter Page Count of Book : ";
cin >> page_count;
if (page_count <= 0)
{
throw page_count;
}
}
catch(...)
{
cout << "\nInvalid Page Count!!!";
page_count = 0;
}
}
void display_book()
{
display();
cout << "\nPage Count : " <<
page_count;
cout << "\n--------------------------------------------------\n";
}
};
class tape : public publication // declaring class tape which inherits class publication in public mode
{
private:
float play_time;
public:
void add_tape()
{
try
{
add();
cout << "Enter Play Duration of the Tape : ";
cin >> play_time;
if (play_time <= 0)
throw play_time;
}
catch(...)
{
cout << "\nInvalid Play Time!!!";
play_time = 0;
}
}
void display_tape()
{
display();
cout << "\nPlay Time : " <<
play_time << " min";
cout << "\n--------------------------------------------------\n";
}
};
int main()
{
book b1[10]; // object of class book
tape t1[10]; // object of class tape
int ch, b_count = 0, t_count = 0;
do
{
cout << "\n* * * * * PUBLICATION DATABASE SYSTEM * * * * *";
cout << "\n--------------------MENU-----------------------";
cout << "\n1. Add Information to Books";
cout << "\n2. Add Information to Tapes";
cout << "\n3. Display Books Information";
cout << "\n4. Display Tapes Information";
cout << "\n5. Exit";
cout << "\n\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:
cout << "\n* * * * BOOK PUBLICATION DATABASE SYSTEM * * * *";
for (int j=0;j < b_count;j++)
{
b1[j].display_book();
}
break;
case 4:
cout << "\n* * * * TAPE PUBLICATION DATABASE SYSTEM * * * *";
for (int j=0;j < t_count;j++)
{
t1[j].display_tape();
}
break;
case 5:
exit(0);
}
}while (ch != 5);
return 0;
}