| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:[求助]构造函数的参数都是默认值
只看楼主 加入收藏
yuanhong
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-4-2
收藏
 问题点数:0 回复次数:3 
[求助]构造函数的参数都是默认值

题目是这样给出的
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();
}
就上面说的两个地方,



搜索更多相关主题的帖子: 函数 构造 参数 
2006-09-28 22:57
朦朦胧胧
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2006-9-19
收藏
得分:0 

#include<iostream>
#include <iomanip>
using namespace std;


......

CArray::CArray(int nIntSize,int nFloatSize)//这个应该怎么写?
{

......

void main()
{
CArray A(100);//这个应该怎么写?
A.print();
}


2006-09-30 16:38
yuanhong
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-4-2
收藏
得分:0 

谢谢了,我试了,这样可以


2006-10-08 21:16
yuanhong
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-4-2
收藏
得分:0 

谢谢了,我试了,这样可以


2006-10-08 21:16
快速回复:[求助]构造函数的参数都是默认值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019957 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved