-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencapsulation.cpp
61 lines (45 loc) · 1.52 KB
/
encapsulation.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
#include <iostream>
using namespace std;
#include <list>
class YouTubeChannel {
//encapsulation means that we make for example the subscribercount member private,
//and then create subscribe and unsubscribe methods which then can increse/decrese the
//subscribercount member. otherwise a user can just vhange the count, and thats not how you get subscribers, and
//should not be allowed
private:
string Name;
string OwnerName;
int SubscriberCount;
list<string> PublishedVideoTitles;
public:
YouTubeChannel(string name , string ownername){
Name = name;
OwnerName = ownername;
SubscriberCount = 0;
}
void Subscribe(){
SubscriberCount++; //now we can acess the subscribercount in the private class
}
void Unsubscribe(){
if (SubscriberCount > 0)
SubscriberCount--; //so that we dont get -1 subscribers
}
void PublishedVideo(string title){ //takes a strong paramter 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;
}
}
};
int main(){
YouTubeChannel ytChannel("Perly's art", "Perly");
ytChannel.PublishedVideo("art1"); //invoke the publishvideo method we added which taakes the paprameter title
ytChannel.Subscribe();
ytChannel.GetInfo();
}