Finding Area of a wall using constructors in C++ || Constructor || C++
In this, we are going to find Area of a wall  using a Constructor in C++. 
 


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

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

class Area
{
public:
    float length, breadth, areaWall;
    Area(float l, float b)
    {
        length = l;
        breadth = b;
        areaWall = length * breadth;
    }
    void display()
    {
        cout << "Area of the Wall is:- " << areaWall;
    }
};

void main()
{
    clrscr();
    float l, b;
    cout << "Enter the dimensions of the wall.\nLength = ";
    cin >> l;
    cout << "Breadth = ";
    cin >> b;
    Area obj(l, b);
    obj.display();
    getch();
}

//..........Coded by YASH ALAPURIA
 

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

#include <iostream>
using namespace std;

class Area
{
public:
    float length, breadth, areaWall;
    Area(float l, float b)
    {
        length = l;
        breadth = b;
        areaWall = length * breadth;
    }
    void display()
    {
        cout << "Area of the Wall is:- " << areaWall;
    }
};

int main(void)
{
    float l, b;
    cout << "Enter the dimensions of the wall.\nLength = ";
    cin >> l;
    cout << "Breadth = ";
    cin >> b;
    Area obj(l, b);
    obj.display();
}

//..........Coded by YASH ALAPURIA

#ENJOY CODING

Post a Comment

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

Previous Post Next Post