关于c++的问题(2)加分加分!!

2024-12-15 18:35:22
推荐回答(2个)
回答1:

我都运行过的哦。你自己也可以试试看
第一题:
#include
class Rect
{public:
int Area_int();
Rect(int l, int w);
~Rect();
private:
int nLength;
int nWidth;
};
int Rect::Area_int() {return nLength*nWidth;}

Rect::Rect(int l,int w) {nLength=l;nWidth=w;}

Rect::~Rect() {cout<<"Class Rect's destructor"<
int main()
{
Rect s(2,4);
cout<<"Area="<return 0;
}

第二题
#include
class Rect
{public:
int Area_int();
double Area_double();
Rect(double l, double w);
Rect(int l, int w);
~Rect();
private:
int nLength;
int nWidth;
double mLength;
double mWidth;
};

int Rect::Area_int() {return nLength*nWidth;}
double Rect::Area_double() {return mLength*mWidth;}

Rect::Rect(int l,int w) {nLength=l;nWidth=w;}
Rect::Rect(double l,double w) {mLength=l;mWidth=w;}

Rect::~Rect() {cout<<"Class Rect's destructor"<
int main()
{
Rect s1(2,4),s2(3.2,4.0);
cout<<"Area1="<cout<<"Area2="<return 0;
}
第三题
#include
class countstr
{
private:
int count;
char a[100];
public:
countstr() {count=0;}
void countchar();
int getchar() {return count;}
};
void countstr::countchar()
{
cout<<"enter the string"<cin>>a;
while(a[count]!='\0')
{
count++;
}
}

int main()
{
countstr c;
c.countchar();
cout<<"the number="<return 0;
}
2、

输出结果是:
constructing A
constructing B
constructing C
destructing C
destructing B
destructing A

回答2:

我不晓得,我是不清楚才来看看滴~