-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance2.cpp
More file actions
62 lines (48 loc) · 1.08 KB
/
inheritance2.cpp
File metadata and controls
62 lines (48 loc) · 1.08 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
/*Practice inheritance; create a public base class and a derived class. Create a class called Flower.
Then create a derived class called Rose. The derived class should have public access to Flower.
Flower has only one member, a string called bloomtime. Rose has only one member, a string called fragrance.*/
#include <iostream>
using namespace std;
//base case
class Flower{
private:
string bloomtime;
public:
Flower();
void setString(string flower);
string getString();
};
Flower::Flower(){
bloomtime="NA";
}
void Flower::setString(string flower){
bloomtime=flower;
}
string Flower::getString(){
return bloomtime;
}
//dervied class
class Rose:public Flower{
private:
string fragrance;
public:
Rose();
void setFragrance(string frag);
string getFragrance();
};
Rose::Rose(){
fragrance="NA";
}
void Rose::setFragrance(string frag){
fragrance=frag;
}
string Rose::getFragrance(){
return fragrance;
}
int main(){
//instance of derived class
Rose rose1;
//set it
rose1.setFragrance("sweet");
cout<<rose1.getFragrance();
}