Problem F: 平面上的点——Point类 (VI)
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和接口描述中的方法和函数。
接口描述:
showPoint()函数:按输出格式输出Point对象。
Point::show()方法:按输出格式输出Point对象。
Point::showSumOfPoint()方法:按格式输出程序运行至当前存在过的Point对象总数。
Point::x()方法:取x坐标。
Point::y()方法:取y坐标。
Point::x(double)方法:传参数设置x坐标并返回。
Point::y(double)方法:传参数设置y坐标并返回。
Point::setPoint(double,double)方法:设置Point对象的x坐标(第一个参数)和y坐标(第二个参数)并返回本对象。
Point::isEqual()方法:判断传入的参数与对象的坐标是否相同,相同返回true。
Point::copy()方法:传参数复制给对象。
Point::inverse()方法,有两个版本:不传参数则将对象自身的x坐标和y坐标互换;若将Point对象做参数传入,则将传入对象的坐标交换复制给对象自身,不修改参数的值。
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
用ShowPoint()函数来输出(通过参数传入的)Point对象的值或坐标值:X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。
对每个Point对象,调用show()方法输出其值,输出格式与ShowPoint()函数略有不同:“Point[i] :”,i表示这是程序运行过程中第i个被创建的Point对象。
调用showSumOfPoint()输出Point对象的计数统计,输出格式见sample。
C语言的输入输出被禁用。
Sample Input
3,3
2,1
Sample Output
Point[1] : (2, 1)
Point[4] : (3, 3)
Point[1] : (3, 3)
Point[5] : (1, 2)
Point[1] : (1, 2)
Point[2] : (0, 0)
==========gorgeous separator==========
Point[2] : (-7, 5)
Point[3] : (1, 2)
Point[4] : (3, 3)
Point[5] : (1, 2)
Point[6] : (-7, 5)
==========gorgeous separator==========
Point[63] : (3, 3)
Point : (3, 3)
Point : (3, 3)
Point : (3, 3)
In total : 64 points.
HINT
给函数正确的返回值。注意常量对象调用的函数。
Append Code
int main(){ int l(0); char c; double a, b; Point p, q, pt[60]; while(std::cin>>a>>c>>b) { if(a == b) p.copy(pt[l].setPoint(a, b)); if(a > b) p.copy(pt[l].setPoint(a, b).inverse()); if(a < b) p.inverse(pt[l].setPoint(a, b)); if(a < 0) q.copy(p).inverse(); if(b < 0) q.inverse(p).copy(pt[l]); pt[l++].show(); p.show(); } q.show(); cout<<"==========gorgeous separator=========="<<endl; double x(0), y(0); for(int i = 0; i < l; i++) x += pt[i].x(), y -= pt[i].y(); pt[l].x(y), pt[l].y(x); q.copy(pt[l]).show(); for(int i = 0; i <= l; i++) pt[i].show(); cout<<"==========gorgeous separator=========="<<endl; const Point const_point(3, 3); const_point.show(); for(int i = 0; i <= l; i++) { if(const_point.isEqual(pt[i])) { ShowPoint(const_point); ShowPoint(const_point.x(), const_point.y()); ShowPoint(Point(const_point.x(), const_point.y())); } } const_point.showSumOfPoint();}#include <iomanip>
using namespace std;
class Point
{
double m,n;
int count;
static int sum;
public :
friend void ShowPoint(Point);
friend void ShowPoint(double, double);
void show()const
{
cout<<setprecision(16)<<"Point["<<count<<"] : ("<<m<<", "<<n<<")"<<endl;
}
double x(double a)
{
m = a;
return a;
}
double y(double b)
{
n = b;
return b;
}
double x()const
{
return m;
}
double y()const
{
return n;
}
Point &setPoint(double a,double b)
{
m=a;
n=b;
return *this;
}void showSumOfPoint()const
{
cout << "In total : " <<sum << " points." << endl;
}
Point(double a,double b)
{
m = a;
n = b;
sum++;
count =sum;
}
Point():m(0),n(0)
{
sum++;
count =sum;
}
Point (Point p)
{
setPoint(p.getx(),p.gety());
return *this;
}
Point& inverse()
{
double temp=m;
m=n;
n=temp;
return *this;
}
Point& inverse(Point p)
{
m=p.n;
n=p.m;
return *this;
}
double getx()
{
return this->m;
}
double gety()
{
return this->n;
}
bool isEqual(const Point &p)const
{
if(p.m == m && p.n == n)
return true;
return false;
}
};
void ShowPoint(Point p)
{
cout<<std::setprecision(16)<<"Point : ("<< p.x() <<", "<< p.y() <<")"<<endl;
}
void ShowPoint(double a,double b)
{
cout<<std::setprecision(16)<<"Point : ("<<a<<", "<<b<<")"<<endl;
}
int Point::sum = 0;
int main()
{
int l(0);
char c;
double a, b;
Point p, q, pt[60];
while(std::cin>>a>>c>>b)
{
if(a == b)
p.copy(pt[l].setPoint(a, b));
if(a > b)
p.copy(pt[l].setPoint(a, b).inverse());
if(a < b)
p.inverse(pt[l].setPoint(a, b));
if(a < 0)
q.copy(p).inverse();
if(b < 0)
q.inverse(p).copy(pt[l]);
pt[l++].show();
p.show();
}
q.show();
cout<<"==========gorgeous separator=========="<<endl;
double x(0), y(0);
for(int i = 0; i < l; i++)
x += pt[i].x(), y -= pt[i].y();
pt[l].x(y), pt[l].y(x);
q.copy(pt[l]).show();
for(int i = 0; i <= l; i++)
pt[i].show();
cout<<"==========gorgeous separator=========="<<endl;
const Point const_point(3, 3);
const_point.show();
for(int i = 0; i <= l; i++)
{
if(const_point.isEqual(pt[i]))
{
ShowPoint(const_point);
ShowPoint(const_point.x(), const_point.y());
ShowPoint(Point(const_point.x(), const_point.y()));
}
}
const_point.showSumOfPoint();
}
Problem F: 平面上的点——Point类 (VI)的更多相关文章
- Problem E: 平面上的点和线——Point类、Line类 (V)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...
- Problem D: 平面上的点和线——Point类、Line类 (IV)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...
- Problem C: 平面上的点和线——Point类、Line类 (III)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...
- Problem B: 平面上的点和线——Point类、Line类 (II)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...
- Problem A: 平面上的点和线——Point类、Line类 (I)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...
- Problem E: 平面上的点——Point类 (V)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...
- Problem D: 平面上的点——Point类 (IV)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...
- Problem C: 平面上的点——Point类 (III)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...
- Problem B: 平面上的点——Point类 (II)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...
随机推荐
- flask框架----信号
一.实例化补充 instance_path和instance_relative_config是配合来用的.这两个参数是用来找配置文件的,当用app.config.from_pyfile('settin ...
- G711 G723 G729线路占多少带宽问题
G.711 G.711 也称为PCM(脉冲编码调制),是国际电信联盟订定出来的一套语音压缩标准,主要用于电话.它主要用脉冲编码调制对音频采样,采样率为8k每秒.它利用一个 64Kbps 未压缩 ...
- loj6068. 「2017 山东一轮集训 Day4」棋盘 二分图,网络流
loj6068. 「2017 山东一轮集训 Day4」棋盘 链接 https://loj.ac/problem/6068 思路 上来没头绪,后来套算法,套了个网络流 经典二分图 左边横,右边列 先重新 ...
- Bytom Java版本离线签名
比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom tx_s ...
- 【Entity Framework】Model First Approach
EF中的model first 所谓mf, 就是使用vs提供的edm designer去设计model,然后将设计好的model使用vs在指定的数据库中生成数据库即可. 当你的项目既没有数据库也没有c ...
- Mac OS X 避免产生临时文件 .DS_Store
参考: 删除Mac中所有 .DS_Store 隐藏文件 Mac OS X 避免产生临时文件 .DS_Store .DS_Store 隐藏文件保存针对目录的特殊信息和设置配置,例如查看方式,图标大小以及 ...
- 使用vue.js + laravel开发单页面应用
最近学了vuejs和laravel,然后顺便就撸了简单的demo,这里将会根据这个demo介绍下如何使用vuejs+laravel开发一个简单的单页面应用,demo的github地址是https:// ...
- python 字符串与16进制 转化
def str_to_hex(s): return r"/x"+r'/x'.join([hex(ord(c)).replace('0x', '') for c in s]) def ...
- ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet………
在照着这里例子学习ssm时,在部署阶段遇到了这个问题“ASM ClassReader failed to parse class file - probably due to a new Java c ...
- C#---装箱、拆箱的一个案例
using System; namespace ConsoleApplication1 { interface IInterface { void Add(int num); } struct Tes ...