Problem D: 模板是个好东西
来源:互联网 发布:鳄鱼皮 知乎 编辑:程序博客网 时间:2024/05/16 14:32
Description
定义Point类:
1. 有两个int类型的数据成员,表示其横纵坐标。
2. 无参构造函数,初始化两个坐标为0。
3. 带参构造函数。
4. 重载其输出运算符<<,用于输出一个点的横坐标和纵坐标,中间用一个空格隔开。
定义一个类模板Data:
1. 只有一个数据成员data,data的类型是由类型参数指定的。
2. 定义该类模板的构造函数。
3. 定义void show()方法,用于显示data的值。
Input
输入有5行。
第1行是一个不含空白符的字符串。
第2~4行分别是一个整数,其中第2、3行是点的坐标值。
最后一行是一个字符。
Output
见样例。
Sample Input
test123c
Sample Output
c3test1 2
#include <bits/stdc++.h>using namespace std;class Point{ private: int x;int y; public: Point():x(0),y(0){} Point(int a,int b):x(a),y(b){} friend ostream &operator<<(ostream &os,const Point&p){ os<<p.x<<" "<<p.y<<endl; } ~Point(){}};template <class A>class Data{ private: A date; public: Data(A p):date(p){} void show(){ cout<<date<<endl; }};int main(){ string n; int x, y, d; char c; cin>>n; cin>>x>>y>>d; cin>>c; Point p(x, y); Data<char> aChar(c); Data<int> anInt(d); Data<Point> aPoint(p); Data<string> aString(n); aChar.show(); anInt.show(); aString.show(); aPoint.show(); return 0;}
0 0
- Problem D: 模板是个好东西
- Problem D: 模板是个好东西
- Problem D: 模板是个好东西
- Problem B: 模板是个好东西
- Problem E: 模板是个好东西(C++期末)
- CF 776D The Door Problem TwoSAT 模板题
- Problem D
- Problem D
- Problem D
- problem D
- Problem D
- Problem D
- Problem D
- Problem D
- Problem-D
- Problem D
- Problem D
- Problem D
- 【XML】——XML之创建
- 3. Longest Substring Without Repeating Characters
- 方法调用
- Java中的三目运算符
- Spring + Spring Mvc + MyBatis 整合
- Problem D: 模板是个好东西
- 167. Two Sum II
- POJ 3311 Hie with the Pie(Floyd + 状压dp)
- 为什么使用%lf读取double型的值,而用%f进行显示?
- Tomcat启动时卡在“INFO: Deploying web application directory ”
- 计算机图形学实验————漫游三维迷宫
- 没有实习的我,如何拿到阿里产品 offer
- android客户端直接调用芝麻信用的人脸认证
- MySQL concat、concat_ws、group_concat函数用法