-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolymorphism.cpp
98 lines (74 loc) · 2.01 KB
/
polymorphism.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
#include <iostream>
using namespace std;
#include <list>
class YouTubeChannel {
private:
string Name;
int SubscriberCount;
list<string> PublishedVideoTitles;
protected:
string OwnerName;
int ContentQuality;
public:
YouTubeChannel(string name , string ownername){
Name = name;
OwnerName = ownername;
SubscriberCount = 0;
ContentQuality = 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;
}
}
void CheckAnalytics(){
if(ContentQuality < 5)
cout<< Name << "has bad quality"<< endl;
else
cout << Name << "good quality" <<endl;
}
};
class CookingYTChannel:public YouTubeChannel{
public:
CookingYTChannel(string name, string Ownername):YouTubeChannel(name, Ownername){
}
void Practice(){
cout << OwnerName << "practicing cooking"<<endl;
ContentQuality++;
}
};
class SingersYTChannel:public YouTubeChannel{
public:
SingersYTChannel(string name, string Ownername):YouTubeChannel(name, Ownername){
}
void Practice(){
cout << OwnerName << "practicing singing"<<endl;
ContentQuality++;
}
};
int main(){
CookingYTChannel ytChannel("Perly's kitchen","perly");
SingersYTChannel ytChannel2("Perly sings","perly");
ytChannel.Practice();
ytChannel2.Practice();
ytChannel2.Practice();
YouTubeChannel * yt1=&ytChannel;
YouTubeChannel * yt2=&ytChannel2; //pointers to the YT channels
//a pointer from a base class can point to an object of a derived class
yt1->CheckAnalytics();
yt2->CheckAnalytics();
}