I guess that the first geArea() code won't know what the width and height is?
A class function has access to all of it's object data.
Of the two functions, the first one is way better. There isn't much point in using get/set functions within the class (all that function call overhead).
I think that what you are trying to do is check to see if the value of width which is being passed in through method setwidth is greater than 0. You should change your if statement to read:
if (width < 0) { ... }
The reason for this, is that when you are checking this->width, you are checking the value already stored in your class' member variable, called width. In this case, the this pointer is differentiating between that member variable and the parameter of the same name being passed in.
Another was of writing this which might be less confusing, or at least clarify what is happening here, would be like this:
1 2 3 4 5 6 7 8
void Rectange::setwidth(double w)
{
if (w < 0) {
width = 0.0;
} else {
width = w;
}
}