寻求解决随机数的产生原因
#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;
}
还请各位给点建议,关于随机数是怎么发生又是怎么来防止的建议。欢迎来访。