level 3
#include<windows.h>
#include<iostream>
usingnamespacestd;
classRectangle{
private:
doublem_length=1;
doublem_width=1;
public:
doublePerimeter(){return2*(m_length+m_width);}
doubleArea(){returnm_length*m_width;}
voidSetWidth(doublew){m_width=w;}
doubleGetWidth(){returnm_width;}
voidSetLength(doublel){m_length=l;}
doubleGetLength(){returnm_length;}
boolSet_(){
booln=1;
if(0>m_length||20<m_length){
cout<<"lengthisnotin0.0-20.0"<<endl;
n=0;
}
if(0>m_width||20<m_width){
cout<<"widthisnotin0.0-20.0"<<endl;
n=0;
}
if(n)
cout<<"lengthandwidtharebothin0.0-20.0"<<endl;
returnn;
}
};
intmain(){
Rectanglerec;
cout<<"Length:"<<rec.GetLength()<<""<<"Width:"<<rec.GetWidth()<<endl;
rec.Set_();
cout<<endl<<endl;
rec.SetLength(5.2);
rec.SetWidth(4);
cout<<"Length:"<<rec.GetLength()<<""<<"Width:"<<rec.GetWidth()<<endl;
rec.Set_();
cout<<endl<<endl;
rec.SetWidth(25);
cout<<"Length:"<<rec.GetLength()<<""<<"Width:"<<rec.GetWidth()<<endl;
rec.Set_();
cout<<endl<<endl;
return0;
}
2022年12月10日 05点12分
4
level 6
你这个类名是编译器内部定义过的了,类名改个名字就好了
2022年12月10日 06点12分
6
level 3
给你的类换个合法名字,原来的与windows.h里的函数冲突了。
2022年12月10日 18点12分
7