注册 登录
编程论坛 C++教室

寻求解决随机数的产生原因

七夜之华 发布于 2014-09-09 23:17, 561 次点击
#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;
}
            
还请各位给点建议,关于随机数是怎么发生又是怎么来防止的建议。欢迎来访。
7 回复
#2
wp2319572014-09-10 09:40
扑通
#3
七夜之华2014-09-10 12:04
求给指导啊。。。。
#4
七夜之华2014-09-10 13:29
难道帖子要沦陷了。。。。求指教。
#5
wp2319572014-09-10 13:57
不知道你这程序是干嘛  所谓的随机数又是指的是啥东东
#6
l34562014-09-10 16:02
不懂啥意思,反正就是紫的
#7
七夜之华2014-09-10 20:17
回复 5 楼 wp231957
程序的目的就是练习类的继承,结果第二个程序(即修改过后的程序)出现了随机数,我不知道随机数是怎么产生的?求解释。。。。求帮助。。。
#8
七夜之华2014-09-10 20:19
回复 6 楼 l3456
怪我了。没让你看懂。
1