Guest User

Digital Camera

a guest
Jan 10th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. using namespace std;
  5.  
  6.  
  7. // Your code here
  8. class Camera {
  9. protected:
  10. char manufacturer[20];
  11. char model[20];
  12. int year;
  13. float resolution;
  14. public:
  15. Camera(char *manufacturer, char *model, int year, float resolution) {
  16. strcpy(this->manufacturer, manufacturer);
  17. strcpy(this->model, model);
  18. this->year = year;
  19. this->resolution = resolution;
  20. }
  21.  
  22. virtual const float price() const = 0;
  23.  
  24. virtual const float rentalPrice(int days) const = 0;
  25.  
  26. bool operator<(const Camera &c) {
  27. return this->price() < c.price();
  28. }
  29.  
  30. char *getModel() {
  31. return model;
  32. }
  33.  
  34. virtual ~Camera() {
  35.  
  36. }
  37. };
  38.  
  39. class PhotoCamera : public Camera {
  40. private:
  41. bool raw;
  42. public:
  43. PhotoCamera(char *manufacturer, char *model, int year, float resolution, bool raw) :
  44. Camera(manufacturer, model, year, resolution) {
  45. this->raw = raw;
  46. }
  47.  
  48. const virtual float price() const {
  49. float total = 100 + (resolution * 20.0);
  50. if(raw == 1)
  51. return total + 50.0;
  52. else
  53. return total;
  54. }
  55.  
  56. const virtual float rentalPrice(int days) const {
  57. float total = ((1/(float)100)) * price();
  58. if(days > 7)
  59. return total - (20/float(100)) * total;
  60. else
  61. return total;
  62. }
  63. };
  64.  
  65. class VideoCamera : public Camera {
  66. private:
  67. int length;
  68. public:
  69. VideoCamera(char *manufacturer, char *model, int year, float resolution, int length) :
  70. Camera(manufacturer, model, year, resolution) {
  71. this->length = length;
  72. }
  73.  
  74. const virtual float price() const {
  75. float total = resolution * 80;
  76. if(length > 3600) {
  77. return total + (40 / float(100)) * total;
  78. } else
  79. return total;
  80. }
  81.  
  82. const virtual float rentalPrice(int days) const {
  83. float total = ((1/(float)100)) * price();
  84. if(days > 7)
  85. return total - (20/float(100)) * total;
  86. else
  87. return total;
  88. }
  89. };
  90.  
  91. class FilmCamera : public Camera {
  92. private:
  93. int fps;
  94. public:
  95. FilmCamera(char *manufacturer, char *model, int year, float resolution, int fps) :
  96. Camera(manufacturer, model, year, resolution) {
  97. this->fps=fps;
  98. }
  99.  
  100. const virtual float price() const {
  101. float total = 50000;
  102. if(fps>30)
  103. return total + ((fps - 30) * 5000);
  104. return total;
  105. }
  106.  
  107. const virtual float rentalPrice(int days) const {
  108. float total = 500 * days;
  109. /* if(fps>60)
  110. return 2 * total;
  111. else */
  112. return total;
  113.  
  114. }
  115. };
  116.  
  117. float production(Camera **c, int num, int days) {
  118. float total = 0;
  119. for(int i = 0; i < num; i++) {
  120. total += c[i]->rentalPrice(days);
  121. }
  122. return total;
  123. }
  124.  
  125. char *mostExpensiveCamera(Camera **c, int num) {
  126. Camera *max = c[0];
  127. for(int i = 1; i < num; i++) {
  128. if(*max < *c[i])
  129. max = c[i];
  130. }
  131. return max->getModel();
  132. }
  133.  
  134.  
  135. int main(int argc, char *argv[])
  136. {
  137. // Variables for reading input
  138. char model[20], producer[20];
  139. int year, length, fps, n;
  140. float resolution;
  141. bool raw;
  142.  
  143. int t;
  144.  
  145. // Array of cameras
  146. Camera *c [10];
  147.  
  148. // Read number of cameras
  149. cin>>n;
  150.  
  151. for(int i = 0; i < n; ++i){
  152.  
  153. // Camera type: 1 - Photo, 2 - Video, 3 - Film
  154. cin>>t;
  155.  
  156. if (t==1){
  157. cin >> producer >> model >> year >> resolution;
  158. cin >> raw;
  159. c[i] = new PhotoCamera(producer, model, year, resolution, raw);
  160. }
  161. else if (t==2){
  162. cin >> producer >> model >> year >> resolution;
  163. cin >> length;
  164. c[i] = new VideoCamera(producer, model, year, resolution, length);
  165. }
  166. else if (t==3){
  167. cin >> producer >> model >> year >> resolution;
  168. cin >> fps;
  169. c[i] = new FilmCamera(producer, model, year, resolution, fps);
  170. }
  171. }
  172.  
  173.  
  174. // Production days
  175. int days;
  176. cin >> days;
  177.  
  178.  
  179. cout<< "Price of production is: " << production(c, n, days);
  180. cout<<"\n" << "Most expensive camera used in production is: " << mostExpensiveCamera(c, n);
  181.  
  182.  
  183. return 0;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment