C++でもPointクラスを作ってみた
まあ、あまり意味は無いかもしれないけど、やっぱりC++をおぼえようという気力がなければいけないのかもしれない。まだまだC++とはいえどもまだ使われているし、使うメリットもあるからである。
#include <iostream> #include <cstdlib> using namespace std; class Point { private: double x; double y; public: void set(double a, double b) { x = a; y = b; } double getX() { return x; } double getY() { return y; } Point(double a, double b) { this->x = a; this->y = b; } void PrintPoint() { cout << this->getX() << " " << this->getY() << endl; } void SetPoint(double a, double b) { this->x = a; this->y = b; return; } }; int main() { Point *p = new Point(1.3, 4.5); p->PrintPoint(); p->SetPoint(2.3, 8.7); cout << p->getX() << endl; cout << p->getY() << endl; return EXIT_SUCCESS; }