永发信息网

明天要交的C++作业

答案:3  悬赏:80  手机版
解决时间 2021-12-03 19:49
  • 提问者网友:山高云阔
  • 2021-12-03 02:58
明天要交的C++作业
最佳答案
  • 五星知识达人网友:雾月
  • 2021-12-03 03:12
做了一点修改;
可以编译通过了.自己试试
---------1----------
#include
class rectangl
{
private:
double high;
double with;
public:

void GetValue(double w ,double h ){ with =w;high=h;cout<<"长方形";}
void GetValue(double h){cout<<"正方形";} //重用函数;
void Publish(){ cout<<"宽: "<
void Test1p(double t){

cout<<"测试重用函数的可用性1:\n"
<<"测试只有一个变量的情况 ** void GetValue(double h){cin>>h;} **\n"
<<"测试时只显示一个数值表示函数完成成功:\n"
<<"测试开始:"< cout<}
void Test1p(double t,double w){

cout<<"测试重用函数的可用性2:\n"
<<"测试只有两个变量的情况 ** void GetValue(double h,double w){cin>>h>>w;} **\n"
<<"测试时显示两个个数值表示函数完成成功:\n"
<<"测试开始:"<cout<}

};

void main(){
rectangl m2s;

m2s.Test1p(2,5);
m2s.GetValue(20,50);

m2s.Test1p(2);
m2s.GetValue(20);
m2s.Publish();

}

------------------2----------------
#include
class counting
{
public:
float square(float,float);
counting(float,float,float);
private:
float lenth;
float width;
float high;

};
counting::counting(float x,float y,float z){ //结构函数;

lenth=x;width=y;high=z;
}
float counting::square (float x,float y){
x=2*x*y;return x;}
void main()
{
float x,y,z,s1,s2,s3;
cin>>x>>y>>z;
counting paper(x,y,z);
s1=paper.square (x,y);
s2=paper.square (z,y);
s3=paper.square (x,z);
}
全部回答
  • 1楼网友:不甚了了
  • 2021-12-03 04:51
自己做个正确的贴上 谢谢楼上两位的答案 小弟感激万分。
----------1---------------
#include
class rectangl
{
private:
double high; //分别定义私有函数成员;
double width;
public:

void GetValue(double w ,double h ){ width =w;high=h;cout<<"长方形";}
void GetValue(double h){ width=high=h; cout<<"正方形";} //重用函数;
void Publish(){ cout<<"宽: "<
void Test1p(double t){

cout<<"测试重用函数的可用性1:\n"
<<"测试只有一个变量的情况 ** void GetValue(double h){cin>>h;} **\n"
<<"测试时只显示一个数值表示函数完成成功:\n"
<<"测试开始:"<cout<}
void Test1p(double t,double w){

cout<<"测试重用函数的可用性2:\n"
<<"测试只有两个变量的情况 ** void GetValue(double h,double w){cin>>h>>w;} **\n"
<<"测试时显示两个个数值表示函数完成成功:\n"
<<"测试开始:"<cout<}


};

void main(){
rectangl m2s;

m2s.Test1p(2,5);
m2s.GetValue(20,50);

m2s.Test1p(2);
m2s.GetValue(20);
m2s.Publish();

}
------------2------------------
#include
class counting
{
public:
float square1();
float square2();
float square3();
counting(float,float,float);
private:
float lenth;
float width;
float high;

};
counting::counting(float x,float y,float z){ //结构函数;
cout<<"长,宽,高输入等待:(单位:米)\n";
cout<<"长:\t";cin>>x;
cout<<"宽:\t";cin>>y;
cout<<"高:\t";cin>>z;
lenth=x;width=y;high=z;
}
float counting::square1 (){ float x;
x=2*lenth*width;return x;}
float counting::square2 (){ float x;
x=2*high*width;return x;}
float counting::square3 (){ float x;
x=2*lenth*high;return x;}
void main()
{
float x,y,z,s1,s2,s3;
counting paper(x,y,z);
s1=paper.square1 ();
s2=paper.square2 ();
s3=paper.square3 ();
cout<<"俯视面面积="<cout<<"侧视面面积="<cout<<"主视面面积="<cout<<"木箱的总造价为:"<}
  • 2楼网友:duile
  • 2021-12-03 04:02
1.错的有两个地方,一个是构造函数没有初始化
另一个把Test1p写成了text1p
修改后为:

#include
class rectangl
{
private:
double high,with;
public:
void GetValue(double ,double ){cout<<"长方形";}
void GetValue(double h){cout<<"正方形";} //重用函数;
void Publish(){ cout<<"宽: "<
void Test1p(double t){

cout<<"测试重用函数的可用性1:\n"
<<"测试只有一个变量的情况 ** void GetValue(double h){cin>>h;} **\n"
<<"测试时只显示一个数值表示函数完成成功:\n"
<<"测试开始:"<cout<}
void Test1p(double t,double w){

cout<<"测试重用函数的可用性2:\n"
<<"测试只有两个变量的情况 ** void GetValue(double h,double w){cin>>h>>w;} **\n"
<<"测试时显示两个个数值表示函数完成成功:\n"
<<"测试开始:"<cout<}
rectangl::rectangl(double w=0,double h=0){
w=with;
h=high;
}
};

void main(){
rectangl m2s;

m2s.Test1p(2,5);
m2s.GetValue(20,50);

m2s.Test1p(2);
m2s.GetValue(20);
//m2s.Publish();
}

2.--------------这个不给你解释了,自己比较吧---------------------------

#include
class counting
{
public:
float square1();
float square2();
float square3();
counting(float,float,float);
private:
float lenth,width,high;

};
counting::counting(float x,float y,float z){ //结构函数;
cin>>x>>y>>z;
lenth=x;width=y;high=z;
}
float counting::square1 (){ float x;
x=2*lenth*width;return x;}
float counting::square2 (){ float x;
x=2*high*width;return x;}
float counting::square3 (){ float x;
x=2*lenth*high;return x;}
void main()
{
float x,y,z,s1,s2,s3;
counting paper(x,y,z);
s1=paper.square1 ();
s2=paper.square2 ();
s3=paper.square3 ();
cout<<"s1="<cout<<"s2="<cout<<"s3="<
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯