Problem F: 平面上的点——Point类 (VI)
Problem F: 平面上的点——Point类 (VI)
Time Limit: 1 Sec Memory Limit: 4 MB
Submit: 6636 Solved: 3048
[ Submit][ Status][ Web Board]
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
Sample Output
HINT
给函数正确的返回值。注意常量对象调用的函数。
Append Code
[ Submit][ Status][ Web Board]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#clude<iostream>
#include<iomanip>
using namespace std;
class Point{
private :
double m,n;
int d;
static int sum;
public :
double x() const { return m;}
double y() const { return n;}
double x( double a){m=a; return m;}
double y( double b){n=b; return n;}
double getX(){ return m;}
double getY(){ return n;}
double setX( double a){ return m=a;}
double setY( double b){ return n=b;}
Point & setPoint( double a, double b){m=a;n=b; return * this ;}
Point( double a=0){m=a;n=a;sum++;d=sum;}
Point( double a, double b){m=a;n=b;sum++;d=sum;}
bool isEqual(Point &p) const { if (p.m==m&&p.n==n) return true ; else return false ;}
Point& copy(Point &p){m=p.m;n=p.n; return * this ;}
Point& inverse(){ double tmp;tmp=m;m=n;n=tmp; return * this ;}
Point& inverse(Point &p){m=p.n;n=p.m; return * this ;}
void show() const {cout<<setprecision(16)<< "Point[" <<d<< "] : (" <<m<< ", " <<n<< ")" <<endl;}
static void showSumOfPoint(){cout<<setprecision(16)<< "In total : " <<sum<< " points." <<endl;}
};
int Point::sum=0;
void ShowPoint( const Point &p)
{
cout<<std::setprecision(16)<< "Point : (" <<p.x()<< ", " <<p.y()<< ")" <<endl;
}
void ShowPoint( double x, double y)
{
cout<<std::setprecision(16)<< "Point : (" <<x<< ", " <<y<< ")" <<endl;
}
void ShowPoint(Point &p, double x, double y)
{
cout<<std::setprecision(16)<< "Point : (" <<p.x(x)<< ", " <<p.x(y)<< ")" <<endl;
}
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)相关推荐
- 平面上的点——Point类 (VI)
Problem D: 平面上的点--Point类 (VI)Time Limit: 1 Sec Memory Limit: 4 MB Submit: 7868 Solved: 3620 [Submit] ...
- Problem D: 平面上的点——Point类 (IV)
Problem D: 平面上的点--Point类 (IV) Time Limit: 1 Sec Memory Limit: 4 MB Submit: 5400 Solved: 3167 [ S ...
- Problem A: 平面上的点——Point类 (I)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个"Point类"来实现平面上的点的操作. 根据"append.c ...
- Problem E: 平面上的点——Point类 (II)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个"Point类"来实现平面上的点的操作. 根据"append.c ...
- 平面上的点——Point类
Problem A: 平面上的点--Point类 (I) Time Limit: 1 Sec Memory Limit: 4 MB Submit: 11586 Solved: 5189 [Subm ...
- 平面上的点——Point类 (II)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个"Point类"来实现平面上的点的操作. 根据"append.c ...
- 平面上的点——Point类 (I)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个"Point类"来实现平面上的点的操作. 根据"append.c ...
- java定义一个点_JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point类中要定义它的三个构造函数...
JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point类中要定义它的三个构造函数 JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point ...
- 《玩不够的数学:算术与几何的妙趣》:第一章 平面上的几何艺术
第一章 平面上的几何艺术 人们往往从悖论中获得思维的乐趣,而几何学的悖论就是不可能图形.如今我们已创造出数千种这样的二维图像,不断挑战我们的眼睛和思维.三角形.披萨饼.七巧板也蕴藏着无穷的变化和巧妙的 ...
最新文章
- java编程石头剪刀布图片_石头、剪刀、布!10分钟带你打开深度学习大门,代码已开源...
- C++ 二分查找函数 lower_bound upper_bound
- JAVA线程的生命周期以及5种状态转换
- ajax success function_Ajax封装
- CF1497E1 Square-free division (easy version)
- android 指示灯权限,Android实现LED灯显示效果
- 一个好的桌面图标的网站
- Android开发指南(41) —— Searchable Configuration
- javascript:控制一个元素高度始终等于浏览器高度
- LintCode 合并二维数组
- 花了半个多小时,纯手点,为500多人点赞
- flash builder 序列号
- FileUtils(文件读写操作工具类)
- PHP生成二维码与识别二维码
- mysql proxy maxscale_maxscale参数配置
- 【百科】有关地震的一些知识
- 不用爬虫,也能写一个聚合搜索引擎
- 幼麟棋牌登录socket服务器分析
- Unity基本认识——走进Unity
- 【免费内网穿透】Windows远程桌面连接树莓派
热门文章
- Linux系统中QSettings配置信息存放
- python人脸识别从入门到工程pdf_《Python人脸识别:从入门到工程实践》 ——1.1.2 人脸识别的应用...
- java计算机毕业设计疫情防控期间人员档案追演示录像上源码+数据库+系统+lw文档+mybatis+运行部署
- cdn.jsdelivr 的替代方案
- 2010ACM-ICPC世界总决赛I题、UVA 1098 Robots on ice JAVA题解
- C# winform程序运行过程中提示尝试读取或写入受保护的内存.这通常指示其他内存已损坏的
- ”Windows 安全中心“真的有用吗?
- 微力同步如何运行Linux,微力同步Linux版怎么使用?微力同步Linux版使用详细教程与下载地址...
- 湖北黄冈中学2021年高考成绩查询,黄冈中学2020年高考喜报 2020年黄冈中学高考成绩...
- 伦敦金交易时间的起始点