// Uebung4.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. // #include "stdafx.h" #include "stdlib.h" #include "conio.h" #include using namespace std; class Punkt { private: static int anzahl; public: static int wieViele() { return anzahl; } private: float x,y; public: Punkt() {} Punkt(float x1, float y1) {x=x1; y=y1; anzahl++;} ~Punkt() {} void verschiebe(int dx, int dy) {x+=dx; y+=dy;} void printOn(ostream& strm = cout) const { strm << "(" << x << "," << y << ")"; } }; class Gerade { public: Gerade(); Gerade(Punkt p1, Punkt p2) {anf=p1; end=p2;} void verschiebe(int dx, int dy) {anf.verschiebe(dx,dy); end.verschiebe(dx,dy);} void zeichne() { cout << "Gerade von "; anf.printOn(cout); cout << " nach "; end.printOn(cout); cout << endl; } private: Punkt anf, end; }; inline ostream& operator << (ostream& strm, const Punkt& p) { p.printOn (strm); return strm; } int _tmain(int argc, _TCHAR* argv[]) { Punkt p1(3.0, 4.0), p2(5.0,6.0); cout << "Der Punkt " << p1 << " hat die Nummer " << Punkt::wieViele() << endl; Gerade g1(p1,p2); g1.zeichne(); return 0; }