c++矩形类问题,为什么这个输出为乱码

#include
using namespace std;
class Rectangle{
public:
Rectangle();
Rectangle(int _length,int _width);
void ShowArea();
void setRectangle(int,int);
void getArea(int);
~Rectangle(){cout<<"GoodBye!"<<endl;
}
private:
int length,width,area;

};
Rectangle::Rectangle() {setRectangle(0,0);}
Rectangle::Rectangle(int _length,int _width){setRectangle(_length,_width);
}
void Rectangle::setRectangle(int _length,int _width){length=_length;width=_width;
}
void Rectangle::getArea(int area){area=length*width;
}
void Rectangle::ShowArea(){cout<<"矩形的面积为:"<<area<<endl; }
int main(){int a=1,b=2;
Rectangle myRectangle;
cout<<"请输入矩形的长和宽;"<<endl;
myRectangle.setRectangle(a,b);
myRectangle.ShowArea();
return 0;
}

img

你的getArea获取了面积不返回的吗?showArea()里面都没有参数,它要显示的area是从石头里蹦出来的吗?

#include <iostream>
using namespace std;
class Rectangle{
public:
Rectangle();
Rectangle(int _length,int _width);
void ShowArea(int);
void setRectangle(int,int);
int getArea();
~Rectangle(){cout<<"GoodBye!"<<endl;
}
private:
int length,width,area;

};
Rectangle::Rectangle() {setRectangle(0,0);}
Rectangle::Rectangle(int _length,int _width){setRectangle(_length,_width);
}
void Rectangle::setRectangle(int _length,int _width){length=_length;width=_width;
}
int Rectangle::getArea(){
    int area=length*width;
    cout<<area<<endl;
    return area;
}
void Rectangle::ShowArea(int area){cout<<"矩形的面积为:"<<area<<endl; }

int main()
{
int a=1,b=2;
Rectangle myRectangle;
cout<<"请输入矩形的长和宽;"<<endl;
cin>>a >> b;
myRectangle.setRectangle(a,b);
int area = myRectangle.getArea();
myRectangle.ShowArea(area);
return 0;
}