•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,800 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,365 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 2666 | Replies: 6 | Solved
![]() |
•
•
Join Date: Jun 2006
Posts: 25
Reputation:
Rep Power: 3
Solved Threads: 1
This is a simple Rectangle calculator that uses classes.
Ok, so I keep getting errors like.
What am I not doing?
class.cpp
class.h
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•
•
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation:
Rep Power: 6
Solved Threads: 29
Yuo should run throught tutorial. You should know the diffrence from set and get. For example
you need
For set func
The constructor is wrong also you cant assign values to types.
instead
float getLength(float)
{
float Len;
cout << "Enter the length: ";
cin >> Len;
cout << endl;
return Len;
}float getLength(void)
{
return length;
}void setLength(float someLen)
{
length = someLen;
}rectangle(float=1.0, float=1.0);
rectangle(float Len, float Width)
{
length = Len;
width = Width;
} Last edited by andor : Sep 29th, 2006 at 10:13 am.
If you want to win, you must not loose (Alan Ford)
•
•
Join Date: Jun 2006
Posts: 25
Reputation:
Rep Power: 3
Solved Threads: 1
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
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
Last edited by hoosier23 : Sep 29th, 2006 at 10:34 am.
•
•
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation:
Rep Power: 6
Solved Threads: 29
•
•
•
•
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
Last edited by andor : Sep 29th, 2006 at 10:48 am.
If you want to win, you must not loose (Alan Ford)
•
•
Join Date: Jun 2006
Posts: 25
Reputation:
Rep Power: 3
Solved Threads: 1
also.. i have changed the class.h and now receive only 2 errors
does anyone have any suggestions?
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 Last edited by hoosier23 : Sep 29th, 2006 at 11:05 am.
•
•
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation:
Rep Power: 6
Solved Threads: 29
Change the constructor to
or
Compile and run
rectangle()
{
length = 1;
width = 1;
} //constructor sets length and width defaults to 1rectangle():length(1), width(1) {} Last edited by andor : Sep 29th, 2006 at 11:05 am.
If you want to win, you must not loose (Alan Ford)
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- writing my own MID FUNCTION (Visual Basic 4 / 5 / 6)
- Homework Help/Feedback (C++)
- Batch file that takes arguments (C)
Other Threads in the C++ Forum
- Previous Thread: Reading in file input up to newline
- Next Thread: Arrays?


Linear Mode