This is a simple Rectangle calculator that uses classes.
Ok, so I keep getting errors like.
Error 1 error C2660: 'rectangle::getLength' : function does not take 0 arguments
Error 2 error C2660: 'rectangle::getWidth' : function does not take 0 arguments
Error 3 error C2660: 'rectangle::getLength' : function does not take 0 arguments
Error 4 error C2660: 'rectangle::getWidth' : function does not take 0 arguments
Error 5 error C2660: 'rectangle::getLength' : function does not take 0 arguments
Error 6 error C2660: 'rectangle::setLength' : function does not take 0 arguments
Error 7 error C2660: 'rectangle::getWidth' : function does not take 0 arguments
Error 8 error C2660: 'rectangle::setWidth' : function does not take 0 arguments
Error 9 error C2660: 'rectangle::calcPerimeter' : function does not take 0 arguments
Error 10 error C2660: 'rectangle::calcArea' : function does not take 0 arguments
What am I not doing?
class.cpp
#include <iostream>
#include "class.h"
using namespace std;
int main()
{
cout << "Welcome to the Rectangle Calculator" << endl;
cout << "You can calculate the Perimeter and Area" << endl;
rectangle Rectangle; //instantiate the Rectangle
Rectangle.getLength();
Rectangle.setLength();
Rectangle.getWidth();
Rectangle.setWidth();
Rectangle.calcPerimeter();
Rectangle.calcArea();
return 0;
}
class.h
#ifndef CLASS_H
#define CLASS_H
using namespace std;
class rectangle
{
private:
float length; //attributes of length and width
float width;
public:
rectangle(float=1.0, float=1.0); //constructor sets length and width defaults to 1
float calcPerimeter(float, float)
{
float Peri;
Peri = getLength() *2 + getWidth() * 2;
return Peri;
}
float calcArea(float, float)
{
float Area;
Area = getLength() * getWidth();
return Area;
}
void setLength(float)
{
if (length < 0.0 && length <= 20.0)
cout << "The measure of length falls between the correct range" << endl;
else
cout << "The length does not fall between the correct range (0.0 and 20.0)";
}
void setWidth(float)
{
if (width < 0.0 && width <= 20.0)
cout << "The width falls between the correct range (0.0 and 20.0)" << endl;
else
cout << "The width does not fall between the correct range (0.0 and 20.0)" << endl;
}
float getLength(float)
{
float Len;
cout << "Enter the length: ";
cin >> Len;
cout << endl;
return Len;
}
float getWidth(float)
{
float Wid;
cout << "Enter the width: ";
cin >> Wid;
cout << endl;
return Wid;
}
};
#endif