- 1
C++ program that computes the area and perimeter of a rectangle using OOP.Your program should have a class Rectangle
please help
2 Antworten
0
#include<iostream.h>
using namespacestd;
class rectangle
{
int l,b;
}d;
int main()
{
float p,a;
cout<<"enter the length and bredth of rectangle";
cin>>d.l>>d.b;
p=2*(d.l+d.b);
a=d.l*d.b;
cout<<"perimeter=";
cout<<p;
cout<<"area=";
cout<<a;
return(0);
}
0
#include <iostream>
using namespace std;
struct Rectangle
{
float x, y;
float area() const
{
return x*y;
}
float perimeter() const
{
return 2*(x+y);
}
};
int main()
{
float x, y;
cout << "Enter the rectangle broadth and width: ";
cin >> x >> y;
Rectangle r{x, y};
cout << "Area: " << r.area() << endl;
cout << "Perimeter: " << r.perimeter();
}