Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. class publication
  7. {
  8. protected:
  9. string name;
  10. float price;
  11.  
  12. public:
  13. publication(): price(0), name("N/A") {}
  14.  
  15. void putdata()
  16. {
  17. cout << "Name: "; cin >> name;
  18. cout << "Price: "; cin >> price;
  19. }
  20. void getdata() const
  21. {
  22. cout << "Name: " << name << "\n";
  23. cout << "Price: " << price << "\n";
  24. }
  25. };
  26.  
  27. class sales
  28. {
  29. protected:
  30. float sal[3];
  31. public:
  32. sales() {sal[0] = 0, sal[1] = 0; sal[2] = 0;}
  33. sales(float a, float b, float c) {sal[0] = a; sal[1] = b; sal[2] = c;}
  34.  
  35. void putdata()
  36. {
  37. cout << "Sales month ago: "; cin >> sal[0];
  38. cout << "Sales 2 months ago: "; cin >> sal[1];
  39. cout << "Sales 3 months ago: "; cin >> sal[2];
  40. }
  41. void getdata() const
  42. {
  43. cout << "Sales month ago: " << sal[0] << "\n";
  44. cout << "Sales 2 months ago: " << sal[1] << "\n";
  45. cout << "Sales 3 months ago: " << sal[2] << "\n";
  46. }
  47. };
  48.  
  49.  
  50. class book: public publication, public sales
  51. {
  52. protected:
  53. int num;
  54. public:
  55. book(): num(0), publication() {}
  56.  
  57. void putdata()
  58. {
  59. publication::putdata();
  60. cout << "Number of pages: "; cin >> num;
  61. sales::putdata();
  62. }
  63. void getdata() const
  64. {
  65. publication::getdata();
  66. cout << "Number of pages: " << num << "\n";
  67. sales::getdata();
  68. }
  69.  
  70. };
  71.  
  72. class type: public publication, public sales
  73. {
  74. protected:
  75. float time;
  76. public:
  77. type(): time(0), publication() {}
  78.  
  79. void putdata()
  80. {
  81. publication::putdata();
  82. cout << "Length of record: "; cin >> time;
  83. sales::putdata();
  84. }
  85. void getdata()
  86. {
  87. publication::getdata();
  88. cout << "Length of record: " << time << "\n";
  89. sales::getdata();
  90. }
  91.  
  92. };
  93.  
  94. class disk: public publication, public sales
  95. {
  96. protected:
  97. enum type_disk{dvd, cd};
  98. type_disk Disk;
  99. public:
  100. disk(): publication(), sales() {}
  101. void putdata()
  102. {
  103. publication::putdata();
  104. sales::putdata();
  105.  
  106. cout << "Disk type(cd, dvd): ";
  107. string temp; cin >> temp;
  108. while (!(temp == "cd" or temp == "dvd"))
  109. {
  110. cout << "Error, try again \nDisk type(cd, dvd): ";
  111. cin >> temp;
  112. }
  113. if (temp == "dvd") Disk = dvd;
  114. else
  115. {
  116. if (temp == "cd") Disk = cd;
  117. else {cout << "Unexpecter error!"; exit(11);}
  118. }
  119. }
  120. void getdata() const
  121. {
  122. publication::getdata();
  123. sales::getdata();
  124. cout << "Disk type(CD, DVD): ";
  125. if (Disk == cd) cout << "cd" << "\n";
  126. else cout << "dvd" << "\n";
  127. }
  128. };
  129.  
  130. int main()
  131. {
  132. book book1;
  133. type type1;
  134. disk disk1;
  135.  
  136. cout << "Book 1:\n";
  137. book1.putdata();
  138. cout << "\nRecord 1:\n";
  139. type1.putdata();
  140. cout << "\nDisk 1:\n";
  141. disk1.putdata();
  142. cout << "\n";
  143. book1.getdata();
  144. cout << "\n";
  145. type1.getdata();
  146.  
  147. cout << "\n";
  148. disk1.getdata();
  149. return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement