| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:寻求解决随机数的产生原因
取消只看楼主 加入收藏
七夜之华
Rank: 3Rank: 3
来 自:China
等 级:论坛游侠
威 望:5
帖 子:82
专家分:103
注 册:2014-9-7
结帖率:100%
收藏
已结贴  问题点数:5 回复次数:4 
寻求解决随机数的产生原因
#include<iostream>
#include<string>
using namespace std;
class Point
{
      protected:
              int x,y;
      public:
             void draw(int a,int b)
             {
                  x=a;
                  y=b;
             }
            
             void show()
             {
                  cout<<"This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
             }
};
class colour_Point : public Point
{
      private:
              char *colour;
      public:
              void draw(int m,int n,char *q)
             {
                  x=m;
                  y=n;
                  colour=q;
             }
             void move(int offx,int offy)
             {
                  x+=offx;
                  y+=offy;
             }
             void kuoda(int ooffx,int ooffy)
             {
                  x*=ooffx;
                  y*=ooffy;
             }
             void show1()
             {
                  cout<<"This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
                  cout<<"And The Point's colour is   "<<colour<<endl;
             }
             void show2()
             {
                  cout<<"After moving,This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
                  cout<<"And The Point's colour is   "<<colour<<endl;
             }
             void show3()
             {
                  cout<<"After kuoda_zhihou,This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
                  cout<<"And The Point's colour is   "<<colour<<endl;
             }  
};
int main()
{
   
    Point point;
    point.draw(3,4);
    point.show();
    colour_Point colour_point;
    colour_point.draw(4,5,"紫色");
    colour_point.show1();
    colour_point.move(2,3);
    colour_point.show2();
    colour_point.kuoda(2,2);
    colour_point.show3();
    system("color 05");
    system("pause");
    return 0;
}
            
该程序执行成功。如若修改成输入后获得程序结果,便出现了随机数,具体修改后的程序如下:
#include<iostream>
#include<string>
using namespace std;
class Point
{
      protected:
              int x,y;
      public:
             void draw(int a,int b)
             {
                  x=a;
                  y=b;
             }
            
             void show()
             {
                  cout<<"This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
             }
};
class colour_Point : public Point
{
      private:
              char *colour;
      public:
              void draw(int m,int n,char *q)
             {
                  x=m;
                  y=n;
                  colour=q;
             }
             void move(int offx,int offy)
             {
                  x+=offx;
                  y+=offy;
             }
             void kuoda(int ooffx,int ooffy)
             {
                  x*=ooffx;
                  y*=ooffy;
             }
             void show1()
             {
                  cout<<"This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
                  cout<<"And The Point's colour is   "<<colour<<endl;
             }
             void show2()
             {
                  cout<<"After moving,This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
                  cout<<"And The Point's colour is   "<<colour<<endl;
             }
             void show3()
             {
                  cout<<"After kuoda_zhihou,This point is the abscissa for "<<x<<", y coordinate for"<<y<<endl;
                  cout<<"And The Point's colour is   "<<colour<<endl;
             }  
};
int main()
{
    int m,n;
    cout<<"please cout the point's position!"<<endl;
    cin>>m>>n;
    int q,Q;
    cout<<"please cout the zuobiao you need move."<<q<<Q<<endl;
    Point point;
    point.draw(m,n);
    point.show();
    colour_Point colour_point;
    colour_point.draw(m,n,"紫色");
    colour_point.show1();
    colour_point.move(q,Q);
    colour_point.show2();
    colour_point.kuoda(q,q);
    colour_point.show3();
    system("color 05");
    system("pause");
    return 0;
}
            
还请各位给点建议,关于随机数是怎么发生又是怎么来防止的建议。欢迎来访。
搜索更多相关主题的帖子: private include public 
2014-09-09 23:17
七夜之华
Rank: 3Rank: 3
来 自:China
等 级:论坛游侠
威 望:5
帖 子:82
专家分:103
注 册:2014-9-7
收藏
得分:0 
求给指导啊。。。。

#############################################
##########################################
因为不懂、才要学习、只有学习、才有进步。
2014-09-10 12:04
七夜之华
Rank: 3Rank: 3
来 自:China
等 级:论坛游侠
威 望:5
帖 子:82
专家分:103
注 册:2014-9-7
收藏
得分:0 
难道帖子要沦陷了。。。。求指教。

#############################################
##########################################
因为不懂、才要学习、只有学习、才有进步。
2014-09-10 13:29
七夜之华
Rank: 3Rank: 3
来 自:China
等 级:论坛游侠
威 望:5
帖 子:82
专家分:103
注 册:2014-9-7
收藏
得分:0 
回复 5 楼 wp231957
程序的目的就是练习类的继承,结果第二个程序(即修改过后的程序)出现了随机数,我不知道随机数是怎么产生的?求解释。。。。求帮助。。。

#############################################
##########################################
因为不懂、才要学习、只有学习、才有进步。
2014-09-10 20:17
七夜之华
Rank: 3Rank: 3
来 自:China
等 级:论坛游侠
威 望:5
帖 子:82
专家分:103
注 册:2014-9-7
收藏
得分:0 
回复 6 楼 l3456
怪我了。没让你看懂。

#############################################
##########################################
因为不懂、才要学习、只有学习、才有进步。
2014-09-10 20:19
快速回复:寻求解决随机数的产生原因
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024724 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved