用c++编程。定义一个类point,该类是平面坐标系上坐标点的抽象表示。类具有的功能包括:

2024-10-28 20:24:00
推荐回答(1个)
回答1:

#include
#include
using namespace std;
class point
{
public:
point();
point(int a,int b);
void distance();
void offset(int a);
void offset(int a,int b);
void scale(int a);
void scale(int a,int b);
private:
int x;
int y;
};
point::point()
{
x=0;
y=0;
}
point::point(int a,int b)
{
x=a;
y=b;
}
void point::distance()
{
cout<<"\ndistence:"<}
void point::offset(int a)
{
cout<<"\n相同偏移前:";
cout<<"x="< cout<<"y="< x+=a;
y+=a;
cout<<"相同偏移后:";
cout<<"x="< cout<<"y="<}
void point::offset(int a,int b)
{
cout<<"\n不同偏移前:";
cout<<"x="< cout<<"y="< x+=a;
y+=b;
cout<<"不同偏移后:";
cout<<"x="< cout<<"y="<}
void point::scale(int a)
{
cout<<"\n相同缩放前:";
cout<<"x="< cout<<"y="< x*=a;
y*=a;
cout<<"相同缩放后:";
cout<<"x="< cout<<"y="<}
void point::scale(int a,int b)
{
cout<<"\n不同缩放前:";
cout<<"x=,"< cout<<"y="< x*=a;
y*=b;
cout<<"不同缩放后:";
cout<<"x=,"< cout<<"y="<}
void main()
{
int x,y,i=0;
cout<<"请输入坐标:";
cin>>x>>y;
point p(x,y);
while(1)
{
i=-1;
while(i>5||i<0)
{
cout<<"\n一、计算点到原点的距离,请按1"< cout<<"二、点坐标按给定的不同的偏移量进行偏移,请按2"< cout<<"三、点坐标按给定的相同的偏移量进行偏移,请按3"< cout<<"四、点坐标按给定的不同尺度缩放坐标值,请按4"< cout<<"五、点坐标按给定的相同尺度缩放坐标值,请按5"< cout<<"六、退出,请按0"< cout<<"\n请输入:";
cin>>i;
if(i>5||i<0) cout<<"\n输入错误请重输:";
}
if(i==0) break;
switch(i)
{
case 1:
p.distance();
break;
case 2:
int x1;
cout<<"请输入相同偏移量x1=";
cin>>x1;
p.offset(x1);
break;
case 3:
int y1;
cout<<"请输入不同偏移量x1,y1:";
cin>>x1>>y1;
p.offset(x1,y1);
break;
case 4:
cout<<"请输入相同缩放量x1=";
cin>>x1;
p.scale(x1);
break;
case 5:
cout<<"请输入不同缩放量x1,y1:";
cin>>x1>>y1;
p.scale(x1,y1);
break;
}
}
}
希望对你有所帮助