返回   cpper编程论坛 > Zion/测试
注册账号 论坛帮助 会员列表 日历事件 搜索 今日新帖 标记版面已读

Zion/测试 惹人烦的东西这边来

回复
 
LinkBack 主题工具 显示模式
  #1 (permalink)  
旧 2005-07-22
初级会员
 
注册日期: 2005-07-22
帖子: 5
cell_liu 正向着好的方向发展
默认 help me~~

我需要用C++建立一个3维坐标系,(X,Y,Z)
X,Y随机在0~1之间取值,Z恒等于0.03
这样取10个点就可以了,那位高手指点一下,急急~~
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #2 (permalink)  
旧 2005-07-23
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,135
文章: 20
polyrandom 正向着好的方向发展
默认

老大,你都22了,不小了。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #3 (permalink)  
旧 2005-07-25
初级会员
 
注册日期: 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;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #4 (permalink)  
旧 2005-07-25
初级会员
 
注册日期: 2005-07-25
帖子: 5
bryant.yan 正向着好的方向发展
默认

初学c++ 语法生疏 练习一下
可以把类免掉。。不必这么烦琐 稍改改就行
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #5 (permalink)  
旧 2005-07-25
初级会员
 
注册日期: 2005-07-22
帖子: 5
cell_liu 正向着好的方向发展
默认 高手,再帮帮忙啊~~

我把程序编译了,但是出现了5个错误呢?

U:\C++\renyi\ren.cpp(36) : error C2248: 'x' : cannot access protected member declared in class 'Point'
U:\C++\renyi\ren.cpp(1 : see declaration of 'x'
U:\C++\renyi\ren.cpp(36) : error C2248: 'y' : cannot access protected member declared in class 'Point'
U:\C++\renyi\ren.cpp(1 : see declaration of 'y'
U:\C++\renyi\ren.cpp(36) : error C2248: 'z' : cannot access protected member declared in class 'Point'
U:\C++\renyi\ren.cpp(1 : see declaration of 'z'
U:\C++\renyi\ren.cpp(52) : error C2374: 'i' : redefinition; multiple initialization
U:\C++\renyi\ren.cpp(4 : see declaration of 'i'
U:\C++\renyi\ren.cpp(53) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.

renyi.exe - 5 error, 0 warning

怎麽办呢?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #6 (permalink)  
旧 2005-07-25
初级会员
 
注册日期: 2005-07-22
帖子: 5
cell_liu 正向着好的方向发展
默认 高手,再帮帮忙啊~~

我把程序编译了,但是出现了5个错误呢?

U:\C++\renyi\ren.cpp(36) : error C2248: 'x' : cannot access protected member declared in class 'Point'
U:\C++\renyi\ren.cpp(1 : see declaration of 'x'
U:\C++\renyi\ren.cpp(36) : error C2248: 'y' : cannot access protected member declared in class 'Point'
U:\C++\renyi\ren.cpp(1 : see declaration of 'y'
U:\C++\renyi\ren.cpp(36) : error C2248: 'z' : cannot access protected member declared in class 'Point'
U:\C++\renyi\ren.cpp(1 : see declaration of 'z'
U:\C++\renyi\ren.cpp(52) : error C2374: 'i' : redefinition; multiple initialization
U:\C++\renyi\ren.cpp(4 : see declaration of 'i'
U:\C++\renyi\ren.cpp(53) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.

renyi.exe - 5 error, 0 warning

怎麽办呢?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #7 (permalink)  
旧 2005-07-25
初级会员
 
注册日期: 2005-07-25
帖子: 5
bryant.yan 正向着好的方向发展
默认

我用的是 dev c++ 编译通过的
用不同编译器 编译器 是不同的
你用的是什么编译器??
根据你的错误信息 改了一下 试试吧
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

class 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; }
private:
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;
}


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 j=0; j<SIZE; j++ ) {
cout << setiosflags( ios::fixed | ios:howpoint )
<< setprecision(2)
<< '[' << p[j].getX() << "," << p[j].getY() << "," << p[j].getZ() << "]";
cout << endl;
}

system( "pause" );
return 0;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #8 (permalink)  
旧 2005-07-25
初级会员
 
注册日期: 2005-07-25
帖子: 5
bryant.yan 正向着好的方向发展
默认

srand( time(NULL) );
for ( int i=0; i<SIZE; i++ ) {
p[i].setPoint( (rand()%100 ) / float(100), rand()%100/float(100), 0.03 );
}
其实关键就在这里。。其他的代码不是很重要。
我用的方法还是c的, 而不是c++推荐的。。
我写的只是参考 你还是要自己实践一下的,只是为了应付。骗的只是自己而已。
我也是新手 看了一通书 有点消化不了。现在是c++ 连 stl一起啃
最近我会长期泡在这里。 希望大家一起切磋
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
回复

书签
主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用



所有时间均为格林尼治时间 +9。现在的时间是 09:26 AM


Powered by vBulletin® 版本 3.7.0
版权所有 ©2000 - 2008,Jelsoft Enterprises Ltd.
(C) Copy Right All Right Reserved 2001 - 2007

Search Engine Friendly URLs by vBSEO 3.1.0