Sofe1204

Untitled

Mar 22nd, 2022 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Box {
  6.     private:
  7.         double length;
  8.         double width;
  9.         double height;
  10.     public:
  11.         Box() {}
  12.         Box(double length, double width, double height) {
  13.             this -> length = length;
  14.             this -> width = width;
  15.             this -> height = height;
  16.         }
  17.         ~Box() {}
  18.         double volume() {
  19.             return this -> length * this -> width * this -> height;
  20.         }
  21.         double surface() {
  22.             return 2*(this -> height * this -> width) + 2*(this -> height * this -> length) + 2*(this -> width * this -> length);
  23.         }
  24. };
  25.  
  26. void printBox(Box box) {
  27.     cout << "volume: " << box.volume() << " surface: " << box.surface() << endl;
  28. }
  29.  
  30. double biggestVolume(Box boxes[], int n) {
  31.     double max = -99999;
  32.     int index = -1;
  33.    
  34.     for (int i=0; i<n; i++) {
  35.         max = max < boxes[i].volume() ? boxes[i].volume() : max;  
  36.         index = i;
  37.     }
  38.    
  39.     cout << "biggest volume: " << max << " " << &boxes[index] << endl;
  40. }
  41.  
  42. double biggestSurface(Box boxes[], int n) {
  43.     double max = -99999;
  44.     int index = -1;
  45.    
  46.     for (int i=0; i<n; i++) {
  47.         max = max < boxes[i].surface() ? boxes[i].surface() : max;
  48.         index = i;
  49.     }
  50.    
  51.     cout << "biggest surface: " << max << " " << &boxes[index] << endl;
  52. }
  53.  
  54. int main()
  55. {
  56.     int n;
  57.     cin >> n;
  58.    
  59.     Box boxes[n];
  60.    
  61.     for (int i=0; i<n; i++) {
  62.         int length, width, height;
  63.         cin >> length >> width >> height;
  64.         boxes[i] = Box(length, width, height);
  65.     }
  66.    
  67.     for (int i=0; i<n; i++) {
  68.        printBox(boxes[i]);
  69.     }
  70.    
  71.     biggestVolume(boxes, n);
  72.     biggestSurface(boxes, n);
  73.    
  74.  
  75.     return 0;
  76. }
Add Comment
Please, Sign In to add comment