C++ Program To Calculate Area And Perimeter Of Rectangle

Area of rectangle and perimeter can be found with the concept of class and object in Object-Oriented Programming. At first, a class called “Rectangle” is declared with the following attributes: length and breadth of data type Integer.

Also member functions like void setSize(int length, int breadth);, int getArea( );, int getPerimeter( ); are included. And by using formula ‘area = length * breadth‘ and ‘perimeter = 2 * (length + breadth)‘ area and perimeter of rectangle is calculated simultaneously.

Also Read: C++ Program For Chi-Square Test For Uniformity

#include<iostream>
#include<cmath>
using namespace std;
class rectangle
{
public:
int length, breadth, area, perimeter;
void setsize(int length,int breadth); // this function set the value of length and breadth of the Rectangle.

int getarea(int length,int breadth)
{

int getarea();  // this function return the area of the rectangle.

area=length*breadth;
cout<<"area="<<area<<endl;
}
int getperimeter (int length, int breadth)
{
int getperimeter();// this function return the perimeter of the rectangle.
perimeter=2*(length*breadth);
cout<<"perimeter="<<perimeter<<endl;
}
};
using namespace std;
int main()
    {
int length,breadth;
rectangle o;
cout<<"Enter length of rectangle"<<endl;
cin>>length;
cout<<"Enter breadth of rectangle"<<endl;
cin>>breadth;
o.getarea(length,breadth);
o.getperimeter(length,breadth);
return 0;
}

Output:

C++ Program To Calculate Area And Perimeter Of Rectangle 1
C++ Program To Calculate Area And Perimeter Of Rectangle

Also Read: C++ Program for Kolmogorov-Smirnov(KS) Test for Uniformity

LEAVE A REPLY

Please enter your comment!
Please enter your name here