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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#include <iostream>
using namespace std;
#include <vector>
class OnePoint {
private:
double xvalue;
double yvalue;
public:
OnePoint(double x = 0.0, double y = 0.0) {
xvalue = x;
yvalue = y;
}
friend ostream& operator<<(ostream& printh, OnePoint& cPoint) {
printh << "(" << cPoint.xvalue << ',' << cPoint.yvalue << ")";
return printh;
}
void Plus(OnePoint a) {
xvalue = xvalue + a.xvalue;
yvalue = yvalue + a.yvalue;
}
void Minus(OnePoint b) {
xvalue = xvalue + b.xvalue;
yvalue = yvalue + b.yvalue;
}
OnePoint Plustwo(OnePoint a) {
return (xvalue + a.xvalue, yvalue - a.yvalue);
}
void Change(double a, double b) {
xvalue += a;
yvalue += b;
}
void Print(OnePoint b) {
cout << xvalue << "," << yvalue << endl;
}
/*OnePoint operator-(OnePoint a) {
OnePoint temp;
temp.xvalue = xvalue + a.xvalue;
temp.yvalue = yvalue + a.yvalue;
return temp;
}
friend OnePoint operator+(OnePoint a, OnePoint b) {
OnePoint temp;
temp.xvalue = a.xvalue + b.xvalue;
temp.yvalue = a.yvalue + b.yvalue;
return temp;
}*/
};
class Line {
private:
OnePoint onevalue;
OnePoint twovalue;
public:
Line(OnePoint a = OnePoint(), OnePoint b = OnePoint ()) {
onevalue = a;
twovalue = b;
}
OnePoint getonevalue() {
return onevalue;
}
OnePoint gettwovalue() {
return twovalue;
}
friend ostream& operator<<(ostream& print, Line& cLine){
print << "{"<< cLine.onevalue << ',' << cLine.twovalue << "}";
return print;
}
/*friend Line operator+(OnePoint a, OnePoint b) {
Line temp(a, b);
return temp;
}*/
};
class Polygon{
private:
vector <OnePoint> polly;
public:
Polygon(OnePoint a = OnePoint(), OnePoint b = OnePoint(), OnePoint c = OnePoint()) {
polly.push_back(a);
polly.push_back(b);
polly.push_back(c);
}
friend ostream& operator<<(ostream& print, Polygon& polly) {
for (unsigned int i = 0; i < polly.polly.size(); i++) {
print << polly[i]; // ERROR HERE. Polygon does not define this operator or a conversion to a type acceptable to the predefined operator
}
return print;
}
void outputvector() {
for (unsigned int i = 0; i < polly.size(); i++) {
cout << polly[i];
}
}
};
Line operator+(const OnePoint &lhs, const OnePoint &rhs)
{
Line retval(lhs, rhs);
return retval;
}
int main(){
OnePoint a(3.0, 3.0);
OnePoint b(1.0, 1.0);
OnePoint y(3.0, 4.0);
Line d(a, b);
Polygon j(a, b, y);
Line o;
o = a + b;
j.outputvector();
cout << j;
cout << a << endl;
cout << d << endl;
cout << o << endl;
}
|