可以编译通过了.自己试试
---------1----------
#include <iostream.h>
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<<"宽: "<<high<<"\t高: "<<with<<endl; }
void Test1p(double t){
cout<<"测试重用函数的可用性1:\n"
<<"测试只有一个变量的情况 ** void GetValue(double h){cin>>h;} **\n"
<<"测试时只显示一个数值表示函数完成成功:\n"
<<"测试开始:"<<endl;
cout<<t<<endl;
}
void Test1p(double t,double w){
cout<<"测试重用函数的可用性2:\n"
<<"测试只有两个变量的情况 ** void GetValue(double h,double w){cin>>h>>w;} **\n"
<<"测试时显示两个个数值表示函数完成成功:\n"
<<"测试开始:"<<endl;
cout<<t<<'\t'<<w<<endl;
}
};
void main(){
rectangl m2s;
m2s.Test1p(2,5);
m2s.GetValue(20,50);
m2s.Test1p(2);
m2s.GetValue(20);
m2s.Publish();
}
------------------2----------------
#include <iostream.h>
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);
}
温馨提示:答案为网友推荐,仅供参考