(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; }
相关文章推荐
- C++中定义对象的语法,带括号与不带括号有什么区别?
- C++基础——定义对象
- 定义Point类的无参数构造函数,将point对象的数据成员初始化为0。
- C++中定义类的对象:用new和不用new有何区别?
- 转:C++中定义类的对象:用new和不用new有何区别?
- [C++]实验五:掌握类的声明和对象的定义
- C++中使用类模板定义对象时出现:“error LNK2019: 无法解析的外部符号”的解决办法
- 用c++编写一个不能被继承的类(但是可以在类外部定义该类的对象)
- 关于面向对象一些名词的定义(C++)
- C++中自己定义函数对象
- C++中定义类的对象:用new和不用new有何区别?
- C++中定义类的对象:用new和不用new有何区别?
- 为什么C++中的类不能定义自身类的对象,而java可以? 【转载】
- C++第七周【任务3】扩展版:设计Complex,使实部和虚部的类型为定义对象时用的实际类型。
- C++中定义对象的语法,带括号与不带括号有什么区别?
- C++中全局对象的定义先于main()函数执行吗
- C++中预定义的运算符的操作对象只能是基本的数据类型
- 第七周C++ 任务三。模板类设计Complex,使实部和虚部为定义对象时用的实际类型
- 【c++】iostreeam中的类为何不可以直接定义一个无参对象呢
- 为什么C++中的类不能定义自身类的对象?