📄 canshuhua.cpp
字号:
#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include<time.h>
#include<math.h>
const unsigned long max1=65536L;
const unsigned long max2=25536L;
const unsigned long mul=1194211693L;
const unsigned long add=12345;
class RandomNum
{
private:
unsigned long seed;
public:
RandomNum(unsigned long s=0);
unsigned short Random(unsigned long n);
double fRandom(void);
};
RandomNum::RandomNum(unsigned long s)
{
if(s==0)
seed=time(0);
else
seed=s;
}
unsigned short RandomNum::Random(unsigned long n)
{
seed=mul*seed+add;
return (unsigned short)((seed>>16)%n);
}
double RandomNum::fRandom(void)
{
return Random(max1)/double(max2);
}
struct point
{
double x,y,z;
}P[1001];
void main()
{
RandomNum Num;
double u[1001];
u[0]=0.0;
int i,j;
double temp,p;
ofstream file("result.txt");
for(i=0;i<=1000;i++)
P[i].x=Num.fRandom();
file<<"***作业1:参数化****"<<<<endl
<<"P的值如下:"<<endl;
for(i=0;i<1001;i++)
{
for(j=0;j<1001-i;j++)
{
if(P[j].x<P[j+1].x)
{
temp=P[j].x;
P[j].x=P[j+1].x;
P[j+1].x=temp;
}
}
}
for(i=0;i<1001;i++)
{
P[i].y=Num.fRandom();
P[i].z=Num.fRandom();
file<<"("<<P[i].x<<","<<P[i].y<<","<<P[i].z<<") ";
}
file<<endl<<"U的值:"<<u[0]<<", "<<endl;
for(i=1;i<1001;i++)
{
p=sqrt((P[i].x-P[i-1].x)*(P[i].x-P[i-1].x)+(P[i].y-P[i-1].y)*(P[i].y-P[i-1].y)
+(P[i].z-P[i-1].z)*(P[i].z-P[i-1].z));
u[i]=u[i-1]+p;
}
for(i=1;i<1001;i++)
{
u[i]=u[i]/u[1000];
file<<u[i]<<", ";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -