-
Rectangle tangle help???
Hello all! I am in a beginner c++ class and have been struggling with this problem. I get a lot of error warnings but don't know what to do to fix it. I tried everything that I can think of and am now just guessing but without any success. Hope someone can suggest a strategy. Thanks, as always in advance.
The most recent error warning.....
error C2143: syntax error : missing ';' before 'tag::id'
fatal error C1004: unexpected end of file found
Error executing cl.exe.
Code:
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(double = 1, double = 1);
double setlength( double l );
double setwidth( double w );
double getlength();
double getwidth();
void area();
void perimeter();
private:
double length;
double width;
};
Rectangle::Rectangle( double l, double w )
Rectangle::setlength( double l )
{
length = ( l >= 0.0 && l <= 20.0 ) ? l = 0;
}
Rectangle::setwidth( double w )
{
width = ( w >= 0.0 && w <= 20.0 ) ? w = 0;
}
void Rectangle::area()
{
return ( l * w );
}
void Rectangle::perimeter()
{
return ( 2 * ( l * w ));
}
int main()
{
Rectangle rect( 4, 5 );
cout << " The area of the rectangle is " << rect.area() << endl;
cout << " The perimeter of the rectangle is " << rect.perimeter() << endl;
return 0;
}
-
>Rectangle::Rectangle( double l, double w )
...
>Rectangle(double = 1, double = 1);
well, for starters, this constructor is missing a method body which cannot be initialized this way
here's a hint..
Code:
Rectangle( double l, double w )
{
// initialize vars here
}
-
>Rectangle::Rectangle( double l, double w )
You should have some code for that. That's what's causing the problem, I think.
-
Just an update folks, I've tried a few different takes on your suggestions and now the least I get is 10 errors. Was I missing any tags? When would a ',' preceed a ';'. That is one of the errors that repeatedly occurs. Thanks all!!
-
Possibly you were confused so I cleared it up a bit. I can't find any tag::id. Anyways thats what you should do to make your thing compile.
Code:
class Rectangle
{
public:
Rectangle( double l, double w );
double setlength( double l );
double setwidth( double w );
double getlength();
double getwidth();
void area();
void perimeter();
private:
double length;
double width;
};
Rectangle::Rectangle( double l, double w )
{
// you're code here to make the rectangle
}
-
Hey, Thanks everyone for the help. I still don't have it working although it's not from lack of trying and I'm off to Toronto on a 6:00 a.m. flight until Monday so I'll give it thought all week-end. I am glad though that the rest of my code looks ok to you since I am not 100% sure yet about all the syntax. This forum helped me through my C class and I am sure glad that you guys ( 'generic guys = inclusive = and gals' ) are around and willing to assist. Thanks again .....