您的位置:首页 > 编程语言 > C语言/C++

(C++)类与对象2-1 Point类的定义

2016-09-21 15:01 232 查看

Problem Description

通过本题目的练习可以掌握类与对象的定义;
设计一个点类Point,它具有私有数据成员x(横坐标)、y(纵坐标);公有成员函数:SetPoint(int,int)用于设置点对象的值,ShowPoint()用于输出点对象的信息
在主函数中调用成员函数SetPoint(int,int)为点对象设置值,并调用成员函数ShowPoint()输出点的信息。

Input

 无

Output

 一对圆括号内,x和y的值用逗号间隔

Example Input



Example Output

(10,11)


Hint

 

Author

#include <iostream>

using namespace std;
class point
{
private:
int x,y;
public:
void setpoint(int a,int b)
{
x=a;
y=b;
}
void showpoint()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
};

int main()
{
point p1;
p1.setpoint(10,11);
p1.showpoint();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: