#include"iostream"
using namespace std;
#include <stdlib.h>
#include <time.h>
class point
{
public:
int du;
int flag;
int sum;
void start(int ,int,point[] );
void change(int ,int ,point[]);
};
void point::start(int M,int N,point p[])
{
int i;
if(N>M||N<0||M<0)
{
cout<<"输入数据有误"<<endl;
return;
}
else cout<<"初始情况下的度为:"<<endl;
p[0].du=p[M-1].du=1;
i=0;
while(true)
{
if(i==0||i==M-1)
p[i].du=1;
else if(i>=M)
p[i].du=0;
else
p[i].du=2;
i++;
if(i>99)
break;
}
int sum=0;
for(i=0;i<100;i++)
{
cout<<p[i].du<<" ";
sum=sum+p[i].du;
}
cout<<endl;
cout<<"初始总度数为:"<<sum<<endl;
}
void point::change(int x,int y,point p[])
{
int i,n;
float j;
int sum=0;
for(i=0;i<100;i++)
{
sum=sum+p[i].du;
//cout<<p[i].du<<" ";
}
float pro[100],pros;
pros=0;
srand((unsigned int)time(NULL));
for(n=x;n<100;n++)
{
for(i=0;i<n;i++)
{
pro[i]=p[i].du/sum;
//cout<<p[i].du<<" ";
}
j=rand()/32767;
for(i=0;i<n;i++)
{
pros=pros+pro[i];
if(j<pros)
break;
}
p[i].du=p[i].du+y;
cout<<"p["<<i<<"].du=:"<<p[i].du<<endl;
cout<<"选中的点数为"<<i<<endl;
p[n].du+=y;
sum=sum+2*y;
}
cout<<"最终点的度数分布为:"<<endl;
for(i=0;i<100;i++)
{
cout<<p[i].du<<" ";
}
}
void main()
{
int x,y;
point z[100],p;
cout<<"请输入初始点数"<<endl;
cin>>x;
cout<<"初始点数为:"<<x<<endl;
cout<<"请输入连接的点数"<<endl;
cin>>y;
cout<<"初始连接点数:"<<y<<endl;
p.start(x,y,z);
p.change(x,y,z);
}
我只是不知道怎么把上面的程序嵌入mfc里面阿 郁闷了。我是初学者,好像说数据存在文档对象中,然后在视图对象中显示,可我就是不会阿。谢谢大家教我啊