Explanation
If a rectangle has length l and width b
• it has area A = lb
• perimeter P = 2l + 2b = 2(l + b)
program :
#include<iostream.h>
#include<conio.h>
Class rect
{
Int l,b;
Int area;
Int peri;
Public:
Void get_rect()
{
Cout<<”\n Enter length and breath of the rectangle :”;
Cin>>l>>b;
}
Void calc()
{
area=l*b;
peri=2*l+2*b; // 2(l*b);
}
Void display()
{
Cout<<”\n The area of the rectangle is :”<<area;
Cout<<”\n The perimeter of the rectangle is :”<<peri;
}
};
Void main()
{
Clrscr();
rect a;
cout<<”\n Area and perimeter of the rectangle:”;
a.get_rect();
a.calc();
a.display();
getch();
}
If a rectangle has length l and width b
• it has area A = lb
• perimeter P = 2l + 2b = 2(l + b)
program :
#include<iostream.h>
#include<conio.h>
Class rect
{
Int l,b;
Int area;
Int peri;
Public:
Void get_rect()
{
Cout<<”\n Enter length and breath of the rectangle :”;
Cin>>l>>b;
}
Void calc()
{
area=l*b;
peri=2*l+2*b; // 2(l*b);
}
Void display()
{
Cout<<”\n The area of the rectangle is :”<<area;
Cout<<”\n The perimeter of the rectangle is :”<<peri;
}
};
Void main()
{
Clrscr();
rect a;
cout<<”\n Area and perimeter of the rectangle:”;
a.get_rect();
a.calc();
a.display();
getch();
}
No comments:
Post a Comment