0
I need help here guy
Write a program to print the area of two rectangles having sides (4,5) and (5,8) respectively by creating a class named 'Rectangle' with a method named 'Area' which returns the area and length and breadth passed as parameters to its constructor.
5 Antworten
+ 3
NASHON ODERO just put a closing curly bracket } after return 0;
Your code is working fine.
0
Which language are you talking about and where's your code/attempt ?
0
C++
0
#include<iostream>
#include<cmath>
using namespace std;
class Rectangle
{
public:
Rectangle(double length,double breadth)
{
rectangleLength=length;
rectangleWidth=breadth;
}
double area()
{
return rectangleLength*rectangleWidth;
}
private:
double rectangleLength;
double rectangleWidth;
};
int main()
{
Rectangle rectangle1(12.3,14.98);
cout<<"Area = "<<rectangle1.area()<<endl;
return 0;
0
Write a program to print the area of two rectangles having sides (4,5) and (5,8)
respectively by creating a class named 'Rectangle' with a function named 'Area' which
returns the area. Length and breadth are passed as parameters to its constructor