C++ program for Area and Volume using Class || OOP || Class || C++
In this, we are going to calculate area and volume of cube using class in C++ Programming Language.

The Code given below can be used in TURBO C++ Compilers: -


//Calculate area and volume of Cuboid
#include<iostream.h>
#include<conio.h>

class calc
{
private:
    int length;
    int width;
    int height;

public:
    void data(int l, int w, int h)
    {
        length = l;
        width = w;
        height = h;
    }
    int Area()
    {
        return 2 * (length + width + height);
    }
    int Volume()
    {
        return length * width * height;
    }
};

void main()
{
    int l, w, h;
    cout<<"Enter the Length, Width and Height: \n";
    cin>>l>>w>>h;
    // create object
    calc calc1;
    calc1.data(l,w,h);
    //Passing arguments
    cout<<"Area = "<<calc1.Area()<<" sq units"<<endl;
    cout<<"Volume = "<<calc1.Volume()<<" cubic units"<<endl;
    getch();
}
//.........Coded by ARADHANA MISHRA


    
  

The Code given below can be used in gcc/g++ Compilers: -


//Calculate area and volume of Cuboid
#include<iostream>
using namespace std;

class calc
{
private:
    int length;
    int width;
    int height;

public:
    void data(int l, int w, int h)
    {
        length = l;
        width = w;
        height = h;
    }
    int Area()
    {
        return 2 * (length + width + height);
    }
    int Volume()
    {
        return length * width * height;
    }
};

int main()
{
    int l, w, h;
    cout<<"Enter the Length, Width and Height: \n";
    cin>>l>>w>>h;
    // create object
    calc calc1;
    calc1.data(l,w,h);
    //Passing arguments
    cout<<"Area = "<<calc1.Area()<<" sq units"<<endl;
    cout<<"Volume = "<<calc1.Volume()<<" cubic units"<<endl;
    return 0;
}
//.........Coded by ARADHANA MISHRA
    
  
#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post