Quick actions

cmd+k|ctrl+k

Navigation

Languages

pgm1

Snippet info

Language

Cpp

Visibility

public

Author

shreejanshetty8

Created

2024-12-03T10:51:46.027596Z

Updated

2024-12-03T10:51:46.027596Z

#include <iostream>
using namespace std;

class Box {
    private:
        float length;
        float breadth;
        float height;

    public:
        // Member functions to set values of length, breadth, and height
        void setLength(float l) {
            length = l;
        }

        void setBreadth(float b) {
            breadth = b;
        }

        void setHeight(float h) {
            height = h;
        }

        // Function to compute the volume of the box
        float compVolume() {
            return length * breadth * height;
        }
};

int main() {
    // Declare pointers to Box class
    Box* box1 = new Box();  // Pointer for first Box object
    Box* box2 = new Box();  // Pointer for second Box object

    // Set dimensions for the first box
    box1->setLength(5.0);
    box1->setBreadth(3.0);
    box1->setHeight(2.0);

    // Set dimensions for the second box
    box2->setLength(7.0);
    box2->setBreadth(4.0);
    box2->setHeight(3.0);

    // Calculate and display the volume of the first box
    cout << "Volume of Box 1: " << box1->compVolume() << endl;

    // Calculate and display the volume of the second box
    cout << "Volume of Box 2: " << box2->compVolume() << endl;


    return 0;
}
INFO