#include<iostream>
using namespace std;
class Rectangle
{
private:
double a, b, c, d;
public:
void setRectangle(double newa, double newb)
{
a = newa;
b = newb;
};
double getGirth()
{
c= (a + b) * 2;
return c;
};
double getArea()
{
d= a * b;
return d;
};
void showRectangle()
{
cout << a << " " << b << " " << c << " " << d;
};
int main()
{
Rectangle myRectangle;
myRectangle.setRectangle(2.0, 4.0);
myRectangle.getGirth();
myRectangle.getArea();
myRectangle.showRectangle();
return 0;
}
理想是输出2.00 4.00 12.00 8.00
感谢
cout 输出如果浮点数小数点后面是0的话,默认是不输出小数点的,只有小数点后面不是0就会自动输出小数,如果你想再任何情况下都输出小数点后面数据的话打印前加上showpoint ,如下
cout <<showpoint << a <<" " << b << " " << c << " " << d;
我的结果是 2 4 12 8
还是2 4 12 8欸
showpoint不是保留两位欸 目前的解决方法是用的#include<iomanip>那个头文件