-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritance.cpp
64 lines (51 loc) · 1.54 KB
/
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
57
58
59
60
61
62
63
64
#include <iostream>
using namespace std;
#include <list>
class YouTubeChannel {
private:
string Name;
int SubscriberCount;
list<string> PublishedVideoTitles;
protected://protected acess mosdifyer allows us to acess the property to be acessed by derived classes
string OwnerName;
public:
YouTubeChannel(string name , string ownername){
Name = name;
OwnerName = ownername;
SubscriberCount = 0;
}
void Subscribe(){
SubscriberCount++;
}
void Unsubscribe(){
if (SubscriberCount > 0)
SubscriberCount--;
}
void PublishedVideo(string title){
PublishedVideoTitles.push_back(title);
}
void GetInfo(){
cout << "Name" << Name << endl;
cout << "Owner name" << OwnerName << endl;
cout << "Subscribers" << SubscriberCount << endl;
cout << "Videos" << endl;
for(string videoTitle: PublishedVideoTitles){
cout<< videoTitle << endl;
}
}
};
class CookingYTChannel:public YouTubeChannel{
//this allows the new class to inherit t=fomr the Youtibechannel class
//the publis means everything publis in the base class will be available in the dervived class
public:
CookingYTChannel(string name, string Ownername):YouTubeChannel(name, Ownername){
//we call the constrcutor from the base class
}
void Practice(){
cout << OwnerName << "practicing cooking"<<endl;
}//this method is available only for this new class
};
int main(){
CookingYTChannel ytChannel("Perly's kitchen","perly");
ytChannel.GetInfo();
}