forked from shashankTiwari9693/hacktober20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class and object
115 lines (108 loc) · 2.96 KB
/
class and object
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
#include<iostream>
using namespace std;
#define MAX 10
class Book
{
public:
int price;
char author[30];
char title[30];
int pages;
public:
void get()
{
cout<<"\n Enter Title of Book : ";
cin>>title;
cout<<"\n Enter name of author : ";
cin>>author;
}
};
class Print_book:public Book
{
public:
int weight;
public:
void get_pb()
{
cout<<"\n Enter the no. of pages: ";
cin>>pages;
cout<<"\n Enter the weight of book: ";
cin>>weight;
}
void show_pb()
{
cout<<"\n ------------Printed Book--------------\n";
cout<<"\n Book Title : "<<title;
cout<<"\n Author Name : "<<author;
cout<<"\n Weight of book : "<<weight;
cout<<"\n Price of book : "<<price;
cout<<"\n no. of pages : "<<pages;
cout<<"\n ----------------------------------\n";
}
};
class E_book:public Book
{
public:
int size;
public:
void get_eb()
{
cout<<"\n Enter the no. of pages: ";
cin>>pages;
cout<<"\n Enter the size of book in KB: ";
cin>>size;
}
void show_eb()
{
cout<<"\n ------------E-Book--------------\n";
cout<<"\n Book Title : "<<title;
cout<<"\n Author Name : "<<author;
cout<<"\n Size of book in KB : "<<size;
cout<<"\n Price of book : "<<price;
cout<<"\n no. of pages : "<<pages;
cout<<"\n ----------------------------------\n";
}
};
int main()
{
int x,m,n;
Print_book p[MAX];
E_book e[MAX];
cout<<"Enter type of book: \nFor Printed Book, press 1 \nFor E-Book, press 2 \n";
cin>>x;
if(x==1)
{
cout<<"Enter total no. of Printed book: ";
cin>>m;
for (int i=0;i<m;i++)
{
cout<<"Enter details for Book "<<i+1<<" : \n";
p[i].get();
p[i].get_pb();
}
cout<<endl;
for (int i=0;i<m;i++)
{
cout<<"Details for Book "<<i+1<<" : \n";
p[i].show_pb();
}
}
else if (x==2)
{
cout<<"Enter total no. of E-book: ";
cin>>n;
for (int i=0;i<n;i++)
{
cout<<"Enter details for E-Book" <<i+1<<" : \n";
e[i].get();
e[i].get_eb();
}
cout<<endl;
{
for(int i=0;i<n;i++)
cout<<"\n";
cout<<"Details for E-Book "<<i+1<<" : \n";
e[i].show_eb();
}
}
}