3-1 Point类的构造函数(构造函数的重载)
来源:互联网 发布:数据库decimal类型 编辑:程序博客网 时间:2024/05/16 05:34
3-1 Point类的构造函数
Time Limit: 1000MS Memory limit: 65536K
题目描述
通过本题目的练习可以掌握类的构造函数的定义;
设计一个点类Point,私有数据成员有x、y;公有成员函数有:无参数的构造函数Point(),带参数的构造函数Point(int,int);ShowPoint()输出点对象的信息
在主函数main()中调用相应成员函数,从键盘接收时间对象的x和y的值,并向显示器输出相应的值。
输入
输入2个整数,用一个空格间隔
输出
要求先输出默认的点值,再输出用户构造的点的值
点的格式为:一对圆括号内 x,y的值,中间用“,”间隔;
示例输入
10 11
示例输出
(0,0)(10,11)
提示
来源
黄晶晶
示例程序
#include<iostream>using namespace std;class point{private: int x,y;public: point() { x=0; y=0; } point(int a,int b) { x=a; y=b; } void showpoint() { cout<<"("<<x<<","<<y<<")"<<endl; }};int main(){ point p1; int a, b; cin>>a>>b; p1.showpoint(); point p2(a,b); p2.showpoint(); return 0;}
1 0
- 3-1 Point类的构造函数(构造函数的重载)
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- 3-1 Point类的构造函数
- stcmp源码分析
- 解决Win7访问Windows 2003、XP共享慢的问题
- TaskOne YYJ学java
- 【搜索】 HDU 5012 Dice
- 采用链地址法处理冲突构造哈希表
- 3-1 Point类的构造函数(构造函数的重载)
- hdu 4993(简单枚举或者hash)
- hdu5001 dp
- 百度以图搜图API介绍
- GIS 像素和米在转化
- Hadoop集群上使用Lzo压缩
- Android进程间通信方式总结(IPC)
- Java虚拟机hotspot源码分析之找门
- C++中抽象类和接口