icse-promo

Question

Design a class to overload a function volume() as follows:


(i) double volume(double r) – with radius ‘r’ as an argument, returns the volume of sphere using the formula:
v = 4 / 3 × 22 / 7 × r3


(ii)double volume(double h, double r) – with height ‘h’ and radius ‘r’ as the arguments, returns the volume of a cylinder using the formula:
v = 22 / 7 × r2 × h


(iii) double volume(double l, double b, double h) – with length ‘l’, breadth ‘b’ and height ‘h’ as the arguments, returns the volume of a cuboid using the formula:
v = l × b × h

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					public class program7
{

    double volume(double r)
    {
        double vol = 4.0 / 3 * 22 / 7 * Math.pow(r, 3);
        return vol;
    }
    double volume(double h, double r)
    {
        double vol = 22.0 / 7 * Math.pow(r, 2) * h;
        return vol;
    }
    double volume(double l, double b, double h)
    {
        double vol = l * b * h;
        return vol;
    }
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *