Wednesday, February 1, 2023

Calculate the volume of a cube

 Write a program in C++ to calculate the volume of a cube.

What is volume:

Volume is a measurement of how much space a three-dimensional object occupies. If you know how to multiply, you can find the volume of a cube or box.

If we have a box or a three-dimensional object, we find that there are three dimensions to consider: length, width, and height. The formula for volume is 

Length x Width x Height

L x W x H

It doesn't matter in what order you multiply these. You get the same answer regardless of the order. Also, the terms length, width, and height are words that helps to remember the formula. It doesn't matter which side. You can name the sides anything you want, as long as you take measurements in each of the three dimensions.

Cubes

A special case of boxes is the cube. This is the case when all sides have the same length. The volume of a cube can be found by knowing the length of one side.

If the side length of the cube is 'a' then

Volume = a x a x a
Volume = a3

This is where the term "cube" comes from. If there is a power of 3, we call it rolled.

Units of measurement

Units are diced when determining the volume of an object. So if your side measures in inches, your answer is cubic inches or inches3.

Sample Solution:

C++ Code :

#include <iostream>

using namespace std;

    int main()

    {

        int sid1;

        float volcu;

        cout << "\n\n Calculate the volume of a cube :\n";

        cout << "---------------------------------------\n";              

cout<<" Input the side of a cube : ";

        cin>>sid1;

        volcu=(sid1*sid1*sid1);

cout<<" The volume of a cube is : "<< volcu << endl;

cout << endl;

     return 0;

    }

Sample Output:

Calculate the volume of a cube :                                     

---------------------------------------                               

 Input the side of a cube : 5                                          

 The volume of a cube is : 125

 

No comments:

Post a Comment

Popular Posts