Area and Volume of Cuboid using Data Abstraction
In this, we are going to see a program on area and volume of cuboid using data abstraction in C++ Programming Language. 
 


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

#include<iostream.h>
#include<conio.h>

class Cuboid
{
    private:
    int length, breadth, height;

    public:
    setval(int l, int b, int h)
    {
        length = l;
        breadth = b;
        height = h;
    }
    int calculateArea()
    {
        return 2 * (length * breadth + breadth * height + length * height);
    }
    int calculateVolume()
    {
        return length * breadth * height;
    }
};

void main()
{
    clrscr();
    int l,b,h;
    cout << "Enter Length, Breadth and Height: ";
    cin >> l >> b >> h;
    Cuboid c;
    c.setval(l, b, h);
    cout << "Area of cuboid is " << c.calculateArea();
    cout << "\nVolume of cuboid is " << c.calculateVolume();
    getch();
}

//.......Coded by SAHIL SHAIKH


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

#include <iostream>
using namespace std;

class Cuboid
{
    private:
    int length, breadth, height;

    public:
    setval(int l, int b, int h)
    {
        length = l;
        breadth = b;
        height = h;
    }
    int calculateArea()
    {
        return 2 * (length * breadth + breadth * height + length * height);
    }
    int calculateVolume()
    {
        return length * breadth * height;
    }
};

int main()
{
    int l,b,h;
    cout << "Enter Length, Breadth and Height: ";
    cin >> l >> b >> h;
    Cuboid c;
    c.setval(l, b, h);
    cout << "Area of cuboid is " << c.calculateArea();
    cout << "\nVolume of cuboid is " << c.calculateVolume();
    return 0;
}

//.......Coded by SAHIL SHAIKH


#ENJOY CODING

Post a Comment

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

Previous Post Next Post