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

Yuo should run throught tutorial. You should know the diffrence from set and get. For example

float getLength(float)
    {
        float Len;
        cout << "Enter the length: ";
        cin >> Len;
        cout << endl;
        return Len;
    }

you need

float getLength(void)
    {
        
        return length;
    }

For set func

void setLength(float someLen)
{
   length = someLen;
}

The constructor is wrong also you cant assign values to types.

rectangle(float=1.0, float=1.0);

instead

rectangle(float Len, float Width)
{
   length = Len;
   width = Width;
}

i believe you can set the data type to zero in this instance, unless my book is wrong...

they have..


class Time {
public:
Time(int = 0, int = 0, int = 0); //default constructor
private:
int hour;
int minute;
int second;
};


//i am also not using a get or set function from a library... this is just my variable name

i believe you can set the data type to zero in this instance, unless my book is wrong...

they have..


class Time {
public:
Time(int = 0, int = 0, int = 0); //default constructor
private:
int hour;
int minute;
int second;
};


//i am also not using a get or set function from a library... this is just my variable name

Hm never seen that (probably becouse I'm not c++ programmer). But the book never lies. Make a test just leave the construtor and what will the copiler tell U

also.. i have changed the class.h and now receive only 2 errors

does anyone have any suggestions?

Error 1 error LNK2019: unresolved external symbol "public: __thiscall rectangle::rectangle(float,float)" (??0rectangle@@QAE@MM@Z) referenced in function _main class.obj
Error 2 fatal error LNK1120: 1 unresolved externals

#ifndef CLASS_H
#define CLASS_H

using namespace std;

class rectangle
{
private:
    float length;                            //attributes of length and width
    float width;
public:
    rectangle(float length=1.0, float width=1.0);            //constructor sets length and width defaults to 1

    float calcPerimeter()
    {
        float Peri;
        Peri = getLength() * 2 + getWidth() * 2;
        return Peri;
    }
    float calcArea()
    {
        float Area;
        Area = getLength() * getWidth();
        return Area;
    }
    void setLength()
    {
        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()
    {
        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()
    {
        cout << "Enter the length: ";
        cin >> length;
        cout << endl;
        return length;
    }
    float getWidth()
    {
        cout << "Enter the width: ";
        cin >> width;
        cout << endl;
        return width;
    }
};
#endif

Change the constructor to

rectangle()
    {
      length = 1;
      width = 1;
    }            //constructor sets length and width defaults to 1

or

rectangle():length(1), width(1) {}

Compile and run

commented: very thorough +1

Excellent work. Praise be to andor.

Thanks buddy. Viehlen Danke!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.