我改了以下四个#,和include ,其他的没变,运行通过 VC6.0 double m=p[i];
#include
#include
#include
#include
class T
{
public:
T() {}
~T();
void Create();
void Coutpxj();
void Coutk();
void Coutz();
void Print();
protected:
int n;
double *p;
double *pxj;
int *k;
double *mz;
};
void T::Create()
{
cout<<"请输入信源符号个数:";
cin>>n;
p=new double[n];
cout<<"请分别输入这"<
pxj=new double[n];
k=new int[n];
mz=new double[n];
double sum=0.0;
for(i=0;i
if(sum!=1.0)
throw 1;
else
{
for(i=0;i
int k=i;
for(int j=i+1;j
p[i]=p[k];
p[k]=m;
}
}
}
T::~T()
{
delete p;
delete pxj;
delete k;
delete mz;
}
void T::Coutpxj()
{
pxj[0]=0;
for(int i=1;i
pxj[i]=0;
for(int j=0;j pxj[i]+=p[j];
}
}
void T::Coutk()
{
for(int i=0;i
double d=(-1)*(log(p[i])/log(2));
if(d-(int)d>0) k[i]=(int)d+1;
else k[i]=(int)d;
}
}
void T::Print()
{
cout<<"Xi"<
for(int j=0;j
if(2*mz[i]-1>=0)
{
cout<<1;
mz[i]=2*mz[i]-1;
}
else
{
cout<<0;
mz[i]=2*mz[i];
}
}
cout<
double K=0.0,H=0.0,Y;
for(i=0;i
K+=(double)p[i]*k[i];
H+=(-1)*p[i]*(log10(p[i])/log10(2.0));
}
Y=H/K;
cout<<"平均码长:"<
void main()
{
T t;int e;
try
{
t.Create();
t.Coutpxj();
t.Coutk();
t.Print();
}
catch(int e)
{if(e==1) cout<<"输入错误,请重新运行";}
}