Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. #include <iostream>
  2. #include<cstring>
  3.  
  4. using namespace std;
  5. class PrintEdition
  6. {
  7. private:
  8. double pricePerPage;
  9. int pages;
  10. int issue;
  11. char* name;
  12. void copy(const PrintEdition& other)
  13. {
  14. this->pricePerPage=other.pricePerPage;
  15. this->pages=other.pages;
  16. this->issue=other.issue;
  17. this->name=new char[strlen(name)+1];
  18. strcpy(this->name,other.name);
  19.  
  20. }
  21. void del()
  22. {
  23. delete[]name;
  24. }
  25. public:
  26. PrintEdition()
  27. {
  28. this->pricePerPage=0.0;
  29. this->pages=0;
  30. this->issue=0;
  31. this->name=nullptr;
  32. }
  33. PrintEdition(double pricePerPage,int pages,int issue,char* name)
  34. {
  35. this->pricePerPage=pricePerPage;
  36. this->pages=pages;
  37. this->issue=issue;
  38. this->name=new char[strlen(name)+1];
  39. strcpy(this->name,name);
  40. }
  41. PrintEdition(const PrintEdition& other)
  42. {
  43. this->copy(other);
  44. }
  45. PrintEdition& operator=(const PrintEdition& other)
  46. {
  47. if(this!=&other)
  48. {
  49. this->del();
  50. this->copy(other);
  51. }
  52. return* this;
  53. }
  54. ~PrintEdition()
  55. {
  56. this->del();
  57. }
  58. void setPricePerPage(double pricePerPage)
  59. {
  60. this->pricePerPage=pricePerPage;
  61. }
  62. double getPricePerPage() const
  63. {
  64. return this->pricePerPage;
  65. }
  66. void setPages (int pages)
  67. {
  68. this->pages=pages;
  69. }
  70. int getPages() const
  71. {
  72. return this->pages;
  73. }
  74. void setIssue(int issue)
  75. {
  76. this->issue=issue;
  77. }
  78. int getIssue() const
  79. {
  80. return this->issue;
  81. }
  82. void setName(const char* name)
  83. {
  84. delete[]name;
  85. this->name=new char[strlen(name)+1];
  86. strcpy(this->name,name);
  87. }
  88. const char* getName()const
  89. {
  90. return this->name;
  91. }
  92. double getPrintPrice()const;
  93. virtual void showInfo()const =0;
  94. double getSellPrice();
  95. virtual double getAdditionalPrice()=0;
  96.  
  97. };
  98.  
  99. void PrintEdition::showInfo()const
  100. {
  101. cout<<"Price per page:"<<pricePerPage<<endl;
  102. cout<<"Pages:"<<pages<<endl;
  103. cout<<"Issue:"<<issue<<endl;
  104. cout<<"Name:"<<name<<endl;
  105. }
  106. double PrintEdition::getPrintPrice()const
  107. {
  108. return pricePerPage*pages;
  109. }
  110. double PrintEdition::getSellPrice()
  111. {
  112. return getPrintPrice()+getAdditionalPrice();
  113. }
  114.  
  115. class Newspaper:public PrintEdition
  116. {
  117. private:
  118. char printDate[128];
  119. int ads;
  120. public:
  121. double getSellPrice()
  122. {
  123. return getPrintPrice()+(ads*(-0.05));
  124. }
  125.  
  126. };
  127. class Magazine:public PrintEdition
  128. {
  129. private:
  130. bool hasPosters;
  131. int numberOfInterviews;
  132. public:
  133. double getSellPrice();
  134. };
  135. double Magazine::getSellPrice()
  136. {
  137. if(hasPosters==true)
  138. {
  139. return getPrintPrice()+1.50+numberOfInterviews * 1 ;
  140. }
  141. return getPrintPrice() + numberOfInterviews * 1 ;
  142. }
  143. class Book:public PrintEdition
  144. {
  145. private:
  146. char authorName[128];
  147. bool hasHardcovers;
  148. int year;
  149. public:
  150. double getSellPrice()
  151. {
  152. if(hasHardcovers==true)
  153. {
  154. return getPrintPrice()+5;
  155. }
  156. return getPrintPrice()+2.50;
  157. }
  158. };
  159.  
  160. int main()
  161. {
  162.  
  163. return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement