Description
Define the Point class:
There are two data members of type int that represent their abscissa and ordinate.
Parameterless constructor, initializing two coordinates to 0.
Constructor with parameters.
Overload its output operator < < to output the abscissa and ordinate of a point, separated by a space.
Define a class template Data:
There is only one data member, data, whose type is specified by the type parameter.
Defines the constructor for this class template.
Define the void show() method to display the value of data.
Input
There are 5 lines of input.
Line 1 is a string without whitespace.
Lines 2 to 4 are integers, where lines 2 and 3 are coordinate values of points.
The last line is a character.
Output
See the example.
Sample Input
test
1
2
3
c
Sample Output
c
3
test
1 2
HINT
Append Code
append.cc,
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;
}
AC code
#include <iostream>
#include <vector>
using namespace std;
class Point
{
protected:
int _x,_y;
public:
Point(int x=0,int y=0):_x(x),_y(y){}
friend ostream& operator<<(ostream& os,const Point& p)
{
os<<p._x<<" "<<p._y<<endl;//I forgot p. you should remember it;
return os;
}
};
template<typename T>//There is no semicolon here
class Data
{
public:
T data;
public:
Data(T d):data(d){}
void show(){cout<<data<<endl;}//The data output here, not d, is clear;
};
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;
}