Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Box {
- private:
- double length;
- double width;
- double height;
- public:
- Box() {}
- Box(double length, double width, double height) {
- this -> length = length;
- this -> width = width;
- this -> height = height;
- }
- ~Box() {}
- double volume() {
- return this -> length * this -> width * this -> height;
- }
- double surface() {
- return 2*(this -> height * this -> width) + 2*(this -> height * this -> length) + 2*(this -> width * this -> length);
- }
- };
- void printBox(Box box) {
- cout << "volume: " << box.volume() << " surface: " << box.surface() << endl;
- }
- double biggestVolume(Box boxes[], int n) {
- double max = -99999;
- int index = -1;
- for (int i=0; i<n; i++) {
- max = max < boxes[i].volume() ? boxes[i].volume() : max;
- index = i;
- }
- cout << "biggest volume: " << max << " " << &boxes[index] << endl;
- }
- double biggestSurface(Box boxes[], int n) {
- double max = -99999;
- int index = -1;
- for (int i=0; i<n; i++) {
- max = max < boxes[i].surface() ? boxes[i].surface() : max;
- index = i;
- }
- cout << "biggest surface: " << max << " " << &boxes[index] << endl;
- }
- int main()
- {
- int n;
- cin >> n;
- Box boxes[n];
- for (int i=0; i<n; i++) {
- int length, width, height;
- cin >> length >> width >> height;
- boxes[i] = Box(length, width, height);
- }
- for (int i=0; i<n; i++) {
- printBox(boxes[i]);
- }
- biggestVolume(boxes, n);
- biggestSurface(boxes, n);
- return 0;
- }
Add Comment
Please, Sign In to add comment