Write a C++ class code to calculate the area of a rectangle as illustrated in the following figure.
Your code must be in a Project contains 3 separate files.
- Implementation file (.cpp)
- Header file (.h)
- Main file (.cpp)
Here is the image for the question:
Code:
main.cpp
:
#include "area.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Rectangle obj;
obj.setLength(8);
obj.setWidth(3);
cout<<"Area of Rectangle : "<<obj.getArea();
cout<<endl;
return 0;
}
area.h
:
#include <iostream>
using namespace std;
#ifndef area_h
#define area_h
class Rectangle
{
public:
double length, width,Area;
Rectangle();
double setLength(int a );
double setWidth(int b);
double getArea();
};
#endif
area.cpp
:
#include "area.h"
Rectangle::Rectangle()
double Rectangle::setLength(int a)
{length = a}
double Rectangle::setWidth(int b)
{width = b}
double Rectangle::getArea(){return Area= a * b;}
When i run the code, it shows this error: