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
| #include <iostream>
//#include <string>
using namespace std;
class Point
{
private:
int x, y, z;
string Name;
public:
Point(string name, int a, int b, int c) : Name{name}, x{a}, y{b}, z{c} {}
//setteurs:
void Name_(string name) { Name = name; }
void x_(int a) { x = a; }
void y_(int b) { y = b; }
void z_(int c) { z = c; }
//accesseurs
string Name_() const { return Name; }
int x_() const { return x; }
int y_() const { return y; }
int z_() const { return z; }
};
//Surcharge d el'opérateur <<
ostream &operator<<(ostream &COUT, Point &point)
{
COUT << point.Name_() << "(" << point.x_() << ";" << point.y_() << ";" << point.z_() << ")" << endl;
return COUT;
}
int main()
{
Point p1("p1", 2, 4, 7);
Point p2("p2", 2, 3, 4);
Point p3("p3", 10, 20, 56);
std::cout << "Liste des points :\n";
std::cout << p1;
std::cout << p2;
std::cout << p3;
return 0;
} |
Partager