1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#pragma once
#include<iostream>
using namespace std;
#include<iostream>
#pragma once
template <class X, class Y>
class point {
private:
X x;
Y y;
public:
point(X a, Y b);
point();
point(const point &);
void setX(X a);
void setY(Y b);
X getX();
Y getY();
void print()const;
point operator+(point po);
point operator++();
point operator+(int);
point operator--();
bool operator==(point obj);
};
template<class X, class Y>
point<X, Y>::point(X a, Y b) {
x = a;
y = b;
}
template<class X, class Y>
point <X, Y > ::point() {
x = y = 0;
}
template<class X, class Y>
point<X, Y>::point(const point &o) {
x = o.x;
y = o.y;
}
template<class X, class Y>
void point<X, Y>::setX(X a) {
x = a;
}
template<class X, class Y>
void point<X, Y>::setY(Y b) {
y = b;
}
template<class X, class Y>
X point<X, Y>::getX() {
return x;
}
template<class X, class Y>
Y point<X, Y>::getY() {
return y;
}
template<class X, class Y>
void point<X, Y>::print() const{
cout << "(" << x << "," << y <<")"<< endl;
}
template<class X,class Y>
point<X,Y> point<X, Y>::operator+(point po) {
point temp;
temp.x = x + po.x;
temp.y = y + po.y;
return temp;
}
template<class X,class Y>
point<X, Y> point<X, Y>::operator++() {
x++;
y++;
return *this;
}
template<class X,class Y>
point<X, Y> point<X, Y>::operator+(int n) {
point temp;
temp.x = x + n;
temp.y = y + n;
return temp;
}
template<class X,class Y>
point<X, Y> point<X, Y>::operator--() {
x--;
y--;
return *this;
}
template<class X,class Y>
bool point<X, Y>::operator==(point obj) {
return (x == obj.x && y ==obj.y);
}
#include<iostream>
#include"Header.h"
using namespace std;
int main() {
point<int, double>point1(1, 2.0);
point<int ,double> point2;
point <int, double>point3(5, 3.1);
point2 = point1;
point2 = point1 + point3;
point <int, int>point4(1, 2);
++point4;
point<int, int>point5;
point5.setX(11);
point5.setY(4);
point<double, double>point6(5.1, 4.3);
//point6 = point6 + 1.1;
point<int, int>point7(1, 1);
point<int, int>point8(2, 1);
if (point7 == point8)
cout << "EQUAL";
else
cout << "not equal";
system("pause");
return 0;
}
|