[C++]不懂的地方 幫解答
再最後一個程式碼那邊有個東西不懂
而這個是我整個程式 分成三個寫
不懂的地方後面有加註
#ifndef RECT_H
#define RECT_H
class Rectangle
{
public:
Rectangle( double = 1.0, double = 1.0 );
double perimeter( void );
double area( void );
void setWidth( double w );
void setLength( double l);
double getWidth( void );
double getLength( void );
private:
double Length;
double Width;
};
#endif
======================分隔線======================
#include "Rectangle.h"
Rectangle::Rectangle( double w, double l)
{
setWidth( w );
setLength( l );
}
double Rectangle::perimeter( void )
{
return 2 * ( Width + Length );
}
double Rectangle::area( void )
{
return Width * Length;
}
void Rectangle::setWidth( double W )
{
Width = W > 0 && W < 20.0 ? W : 1.0 ;
}
void Rectangle::setLength( double L )
{
Length = L > 0 && L < 20.0 ? L : 1.0 ;
}
double Rectangle::getWidth( void )
{
return Width;
}
double Rectangle::getLength( void )
{
return Length;
}
======================分隔線======================
#include <iostream>
using std::cout;
using std::endl;
using std::ios;
#include<iomanip>
using std::setprecision; /***這個的功用***/
using std::setiosflags; /***這個的功用***/
#include "Rectangle.h"
int main()
{
Rectangle a, b( 4.0, 5.0 ), c( 67.0, 888.0 );
cout<<setiosflags( ios::fixed | ios::showpoint ); /***這個的功用***/
cout<<setprecision( 1 ); /***這個的功用***/
cout<<"a : length = " <<a.getLength()
<<" ; width = " <<a.getWidth()
<<" ; perimeter = " <<a.perimeter()
<<" ; area = " <<a.area() <<'\n';
cout<<"b : length = " <<b.getLength()
<<" ; width = " <<b.getWidth()
<<" ; perimeter = " <<b.perimeter()
<<" ; area = " <<b.area() <<endl;
cout<<"c : length = " <<c.getLength()
<<" ; width = " <<c.getWidth()
<<" ; perimeter = " <<c.perimeter()
<<" ; area = " <<c.area() <<endl;
return 0;
}
裡面都英文我看不懂>"<
什麼事旗標值 做什麼
1 個解答
- 1 0 年前最佳解答
1.
using std::cout;
using std::endl;
using std::ios;
個人覺得滿奇怪的
沒有理由知道上面的功用
卻不知道下面的功用
using std::setprecision; /***這個的功用***/
using std::setiosflags; /***這個的功用***/
舉例來說
如果您沒有
using std::setprecision;
那麼您要使用cout的時候則必須為
std::setprecision(1);
2.
setprecision()設定浮點數的精準度
setiosflags()設定指定的旗標值
其標種類如下
http://msdn2.microsoft.com/en-us/library/d2a1929w(...
以下有個範例
http://msdn2.microsoft.com/en-us/library/8bbhbaew(...
2007-07-06 09:16:50 補充:
修正
舉例來說
如果您沒有
using std::setprecision;
那麼您要使用setprecision的時候則必須為
std::setprecision(1);
參考資料: 自己+搜尋