主题: help me~~
查看单个帖子
  #3 (permalink)  
旧 2005-07-25
bryant.yan bryant.yan 当前离线
初级会员
 
注册日期: 2005-07-25
帖子: 5
bryant.yan 正向着好的方向发展
默认

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

class Point
{
friend ostream &operator<<( ostream &, const Point & );
public:
Point( double=0, double=0, double=0 );
void setPoint( double, double, double );
double getX() const { return x; }
double getY() const { return y; }
double getZ() const { return z; }
protected:
double x,y,z;
};

Point::Point( double a, double b, double c ) { setPoint( a, b, c ); }

void Point:etPoint( double a, double b, double c )
{
x=a;
y=b;
z=c;
}



ostream &operator<<( ostream &output, const Point &p )
{
output << setiosflags( ios::fixed | ios:howpoint )
<< setprecision(2)
<< '[' << p.x << "," << p.y << "," << p.z << "]";
return output;
}


int main()
{
int SIZE=10;

Point p[10];

srand( time(NULL) );
for ( int i=0; i<SIZE; i++ )
p[i].setPoint( (rand()%100 ) / float(100), rand()%100/float(100), 0.03 );


for ( int i=0; i<SIZE; i++ ) {
cout << p[i] << endl;
}

system( "pause" );
return 0;
}
回复时引用此帖