Write a program to print area of 2 rectangles having sides(4,5) and (5,8) respectively by creating a class named Rectangle.
Write a program to print area of 2 rectangles having sides(4,5) and (5,8) respectively by creating a class named 'Rectangle' with a function which returns the area. Length and breadth are passed as parameters to its constructor.
#include <iostream>
using namespace std;
class Rectangle
{
public:
int a;
Rectangle(int l, int b)
{
a=l*b;
cout<<a<<endl;
}
};
int main()
{
cout<<"area of R1 is ";
Rectangle R1(4,5);
cout<<"area of R2 is ";
Rectangle R2(5,8);
return 0;
}
Comments
Post a Comment