Answers for "volume of shapes using class and operator overload"

C++
0

volume of shapes using class and operator overload

#include <iostream>
#include <iomanip>
using namespace std;

class cuboidvolume{
    
    float l,b,h;
    float r;
    float rc,rh;
    
    public:
    void v(float l, float b, float h){
        
        std::cout << std::fixed << std::setprecision(2);
        float vol=l*b*h;
        if (vol < 1){
            std::cout << "Less volume:Data not sufficient\n";
        }
        else{
            std::cout << vol << '\n';
        }
    }
    void v(float r){
        
        std::cout << std::fixed << std::setprecision(2);
        float fourbythree=4.0/3.0;
        float vol=fourbythree*(3.14)*r*r*r;
        if (vol < 1){
            std::cout << "Less volume:Data not sufficient\n";
        }
        else{
            std::cout << vol << '\n';
        }
    }
    void v(float rc, float hc){
        
        std::cout << std::fixed << std::setprecision(2);
        float vol=(3.14)*rc*rc*hc;
        if (vol < 1){
            std::cout << "Less volume:Data not sufficient\n";
        }
        else{
            std::cout << vol << '\n';
        }
    }

};

int main(){
    float l,b,h;
    float r;
    float rc,hc;
    
    cin>>l>>b>>h;
    cin>>r;
    cin>>rc>>hc;
    cuboidvolume x;
    x.v(l,b,h);
    x.v(r);
    x.v(rc,hc);
    return 0;
}
Posted by: Guest on May-20-2021

Code answers related to "volume of shapes using class and operator overload"

Browse Popular Code Answers by Language