4.
#include<iostream>
using namespace std;
class CRectangle
{
private:
double h,w;
public:
CRectangle(double h=1,double w=1):h(h),w(w)
{
}
void input()
{
cin>>h>>w;
if(h<0||h>50)
h=1.0;
if(w<0||w>50)
w=1.0;
}
void Perimeter()
{
cout<<(h+w)*2;
}
};
int main()
{
CRectangle A;
A.input();
A.Perimeter();
return 0;
}
bool CalNormalVector(double x1,double y1,double z1,double x2,double y2,double z2,double x3,double y3,double z3,double &dx,double &dy,double &dz)
{
double pt1pt2[3]={x2-x1,y2-y1,z2-z1};
double pt2pt3[3]={x3-x2,y3-y2,z3-z2};
double pt1pt3[3]={x3-x1,y3-y1,z3-z1};
double nx=0.0,ny=0.0,nz=0.0f;
cross(pt1pt2[0],pt1pt2[1],pt1pt2[2],pt2pt3[0],pt2pt3[1],pt2pt3[2],nx,ny,nz);
if (nx>-MYFLOAT0&&nx<MYFLOAT0&&
ny>-MYFLOAT0&&ny<MYFLOAT0&&
nz>-MYFLOAT0&&nz<MYFLOAT0)
{
return false;
}
//
bool flag=normalize(nx,ny,nz,dx,dy,dz);
if (!flag)
{
return false;
}
//测试,三向量与法向量数量积都是0
double dot1n1=dot(dx,dy,dz,pt1pt2[0],pt1pt2[1],pt1pt2[2]);
double dot2n1=dot(dx,dy,dz,pt2pt3[0],pt2pt3[1],pt2pt3[2]);
double dot3n1=dot(dx,dy,dz,pt1pt3[0],pt1pt3[1],pt1pt3[2]);
if (!(dot1n1>-MYFLOAT0&&dot1n1<MYFLOAT0&&
dot2n1>-MYFLOAT0&&dot2n1<MYFLOAT0&&
dot2n1>-MYFLOAT0&&dot2n1<MYFLOAT0))
{
return false;
}
return true;
}