用c++编程。定义一个类point,该类是平面坐标系上坐标点的抽象表示。类具有的功能包括:
1)计算点到原点的距离(distance)2)点坐标按给定的不同的偏移量进行偏移(offset)3)点坐标按给定的相同的偏移量进行偏移(offset)4)点坐标按给定的不...
1)计算点到原点的距离(distance)
2)点坐标按给定的不同的偏移量进行偏移(offset)
3)点坐标按给定的相同的偏移量进行偏移(offset)
4)点坐标按给定的不同尺度缩放坐标值(scale)
5)点坐标按给定的相同尺度缩放坐标值(scale) 展开
2)点坐标按给定的不同的偏移量进行偏移(offset)
3)点坐标按给定的相同的偏移量进行偏移(offset)
4)点坐标按给定的不同尺度缩放坐标值(scale)
5)点坐标按给定的相同尺度缩放坐标值(scale) 展开
1个回答
展开全部
#include<iostream>
#include<math.h>
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:"<<sqrt(x*x+y*y)<<endl;
}
void point::offset(int a)
{
cout<<"\n相同偏移前:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
x+=a;
y+=a;
cout<<"相同偏移后:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
}
void point::offset(int a,int b)
{
cout<<"\n不同偏移前:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
x+=a;
y+=b;
cout<<"不同偏移后:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
}
void point::scale(int a)
{
cout<<"\n相同缩放前:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
x*=a;
y*=a;
cout<<"相同缩放后:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
}
void point::scale(int a,int b)
{
cout<<"\n不同缩放前:";
cout<<"x=,"<<x<<",";
cout<<"y="<<y<<endl;
x*=a;
y*=b;
cout<<"不同缩放后:";
cout<<"x=,"<<x<<",";
cout<<"y="<<y<<endl;
}
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"<<endl;
cout<<"二、点坐标按给定的不同的偏移量进行偏移,请按2"<<endl;
cout<<"三、点坐标按给定的相同的偏移量进行偏移,请按3"<<endl;
cout<<"四、点坐标按给定的不同尺度缩放坐标值,请按4"<<endl;
cout<<"五、点坐标按给定的相同尺度缩放坐标值,请按5"<<endl;
cout<<"六、退出,请按0"<<endl;
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;
}
}
}
希望对你有所帮助
#include<math.h>
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:"<<sqrt(x*x+y*y)<<endl;
}
void point::offset(int a)
{
cout<<"\n相同偏移前:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
x+=a;
y+=a;
cout<<"相同偏移后:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
}
void point::offset(int a,int b)
{
cout<<"\n不同偏移前:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
x+=a;
y+=b;
cout<<"不同偏移后:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
}
void point::scale(int a)
{
cout<<"\n相同缩放前:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
x*=a;
y*=a;
cout<<"相同缩放后:";
cout<<"x="<<x<<",";
cout<<"y="<<y<<endl;
}
void point::scale(int a,int b)
{
cout<<"\n不同缩放前:";
cout<<"x=,"<<x<<",";
cout<<"y="<<y<<endl;
x*=a;
y*=b;
cout<<"不同缩放后:";
cout<<"x=,"<<x<<",";
cout<<"y="<<y<<endl;
}
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"<<endl;
cout<<"二、点坐标按给定的不同的偏移量进行偏移,请按2"<<endl;
cout<<"三、点坐标按给定的相同的偏移量进行偏移,请按3"<<endl;
cout<<"四、点坐标按给定的不同尺度缩放坐标值,请按4"<<endl;
cout<<"五、点坐标按给定的相同尺度缩放坐标值,请按5"<<endl;
cout<<"六、退出,请按0"<<endl;
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;
}
}
}
希望对你有所帮助
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |