-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFruits_inheritance.cpp
56 lines (47 loc) · 999 Bytes
/
Fruits_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
#include <iostream>
using namespace std;
int apples = 0, mangoes = 0;
int total_fruits = 0;
class fruit
{
public:
void input_fruits()
{
cout << "Enter the number of apples : ";
cin >> apples;
cout << "Enter the number of mangoes : ";
cin >> mangoes;
}
void calculate_total()
{
total_fruits = apples + mangoes;
cout << "The total fruits in the basket are : " << total_fruits << endl;
}
};
class apple : public fruit
{
public:
void show_apples()
{
cout << "The number of apples in the basket is : " << apples << endl;
}
};
class mango : public fruit
{
public:
void show_mangoes()
{
cout << "The number of mangoes in the basket is : " << mangoes << endl;
}
};
int main()
{
fruit f1;
apple a1;
mango m1;
f1.input_fruits();
a1.show_apples();
m1.show_mangoes();
f1.calculate_total();
return 0;
}