try_class.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4. class YoutubeChannel
  5. {
  6. private:
  7. std::string name;
  8. int subscribersCount;
  9. std::list<std::string> videoList;
  10. protected:
  11. std::string ownerName;
  12. int contentQuality=0;
  13. public:
  14. YoutubeChannel(std::string _name, std::string _owner)
  15. {
  16. name = _name;
  17. ownerName = _owner;
  18. subscribersCount = 0;
  19. }
  20. void subscribe()
  21. {
  22. subscribersCount++;
  23. }
  24. void unsubscribe()
  25. {
  26. if (subscribersCount > 0)
  27. subscribersCount--;
  28. else
  29. {
  30. std::cout << "Can't unsubscribe this channel" << std::endl;
  31. }
  32. }
  33. void pub_video(std::string v)
  34. {
  35. videoList.push_back(v);
  36. }
  37. void qualityCheck()
  38. {
  39. std::cout<<contentQuality<<std::endl;
  40. if(contentQuality<5)
  41. {
  42. std::cout<<"The quality of "<<name<<" channel is bad."<<std::endl;
  43. }
  44. else
  45. {
  46. std::cout<< name << " has great quality!"<<std::endl;
  47. }
  48. }
  49. void show_info()
  50. {
  51. std::cout << "**************************" << std::endl;
  52. std::cout << "Name: " << name << std::endl;
  53. std::cout << "Owner: " << ownerName << std::endl;
  54. std::cout << "Subscribers: " << subscribersCount << std::endl;
  55. std::cout << "Videos:" << std::endl;
  56. for (std::string _value : videoList)
  57. {
  58. std::cout << "\t" << _value << std::endl;
  59. }
  60. std::cout << "**************************" << std::endl;
  61. }
  62. };
  63. class CookingYoutubeChannel : public YoutubeChannel
  64. {
  65. public:
  66. CookingYoutubeChannel(std::string name, std::string ownerName) : YoutubeChannel(name, ownerName) {}
  67. void practice()
  68. {
  69. std::cout << ownerName << " is practicing cooking..." << std::endl;
  70. std::cout << ownerName << "'s channel has gained 1 content quality point." << std::endl;
  71. contentQuality++;
  72. }
  73. };
  74. class SingingYoutubeChannel : public YoutubeChannel
  75. {
  76. public:
  77. SingingYoutubeChannel(std::string name, std::string ownerName) : YoutubeChannel(name, ownerName) {}
  78. void practice()
  79. {
  80. std::cout << ownerName <<" is practicing cooking..." << std::endl;
  81. std::cout << ownerName << "'s channel has gained 1 content quality point." << std::endl;
  82. contentQuality++;
  83. }
  84. };