>>679
#include <iostream>
class Rectangle {
int width, height;
public:
void setWidthHeight(int w, int h) {
std::cout << "横幅に" << w << "が高さに" << h
<< "が入力されました" << std::endl;
if ( w < 0 || h < 0) {
width = 0;
height = 0;
std::cout << "横幅や高さには正の値を入れる必要があります。"
"どちらも0にします。" << std::endl;
} else {
width = w;
height = h;
}
}
void calcArea() {
std::cout << "面積は" << width * height << "です。" << std::endl;
}
};
int main()
{
Rectangle r;
r.setWidthHeight(6, 8);
r.calcArea();
r.setWidthHeight(-6, 8);
r.calcArea();
return 0;
}