题目是这样给出的
class CArray{
public:
CArray(int nIntSize=100,int nFloatSize=200); //这个题目给出就是这样的
void put(int n);
void put(float n);
int getInt(int index);
float getFloat(int index);
~CArray();
void print();
private:
int nIntSize;
int nNumOfInt;
int nFloatSize;
int nNumOfFloat;
int * pInt;
float * pFloat;
};
CArray::CArray(int nIntSize=100 ,int nFloatSize=200)//这个应该怎么写?
{
pInt=new int[nIntSize];
pFloat=new float[nFloatSize];
int n;
float m;
nNumOfInt=0;
nNumOfFloat=0;
cout<<"Please input the datas to the int array(end by -9999)"<<endl;
cin>>n;
while(n!=-9999&&nNumOfInt<=nIntSize)
{
nNumOfInt++;
put(n);
cin>>n;
}
cout<<endl;
cout<<"Please intput the datas to the float arrat(end by -0.0)"<<endl;
cin>>m;
while(m!=(-0.0)&&nNumOfFloat<=nFloatSize)
{
nNumOfFloat++;
put(m);
cin>>m;
}
cout<<endl;
}
void CArray::put(int n)
{
int position=nNumOfInt-1;
pInt[position]=n;
}
void CArray::put(float n)
{
int position=nNumOfFloat-1;
pFloat[position]=n;
}
int CArray::getInt(int index)
{
return pInt[index];
}
float CArray::getFloat(int index)
{
return pFloat[index];
}
void CArray::print()
{
int i;
for(i=0;i<nNumOfInt;i++)
{
cout<<setw(5)<<getInt(i);
}
cout<<endl;
for(i=0;i<nNumOfFloat;i++)
{
cout<<setw(5)<<getFloat(i);
}
cout<<endl;
}
CArray::~CArray()
{
delete[] pInt;
delete[] pFloat;
}
void main()
{
CArray A(100);//这个应该怎么写?
A.print();
}
就上面说的两个地方,