diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp')
| -rw-r--r-- | Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp b/Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp new file mode 100644 index 0000000..17a829f --- /dev/null +++ b/Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp @@ -0,0 +1,115 @@ +// Übung PG 2, Teil 2
+// test Shape, Polyline, Line, Polygon, Rectangle, Ellipse, Circle.
+// Author: Prinz / Kirch-Prinz / Weber
+// Date: 26.05.05
+
+#include "shape.h"
+
+int main()
+{
+ cout << "\nGeometrische Figuren\n" << endl;
+
+ Point vertices[] = { Point( -1, 0 ), Point( 0, 2 ), Point( 1, 0 ) };
+
+ Polyline poly1,
+ poly2( Point( 1, 2 ), Point( 2, 0 ) ),
+ poly3( vertices, 3 ),
+ poly4( poly3 ); // use of copy constructor
+
+ cout << "Die Punkte der vier Linienzuege: \n"
+ << poly1.toString() << endl
+ << poly2.toString() << endl
+ << poly3.toString() << endl
+ << poly4.toString() << endl;
+ cin.get();
+
+ cout << "Zuweisungen testen:" << endl; // test assignment
+ poly1 = poly4;
+ cout << poly1.toString() << endl;
+ poly1 = Polyline();
+ cout << poly1.toString() << endl << endl;
+
+ cout << "Punkte anhaengen:" << endl; // append points
+ poly1 += Point( 0.5, 2.5 );
+ cout << poly1.toString() << endl;
+ poly4 += Point( 2, 2 );
+ cout << poly4.toString() << endl;
+ cout << "Anzahl Linien: " << poly4.getNumberOfLines() << endl
+ << "Laenge : " << poly4.getLength() << endl;
+
+ cout << "Nach der Skalierung mit dem Faktor 2.0" << endl;
+ poly4.scale( 2.0 );
+ cout << poly4.toString() << endl << endl;
+
+ cout << "Linienzuege anhaengen:" << endl; // append lines
+ poly2 += poly1;
+ cout << poly2.toString() << endl;
+ poly4 += poly3;
+ cout << poly4.toString() << endl << endl;
+
+ cout << "Linienzug verschieben:" << endl; // displacement
+ poly4.move( 1,0 );
+ cout << poly4.toString() << endl;
+ cout << "Neuer Anker: " << poly4.getAnchor() << endl;
+ cin.get();
+
+ cout << "Linien testen: " << endl;
+ Line line1( 0, 0, 1, 1 ),
+ *pLine = new Line( line1 ); // use of copy constructor
+ cout << line1.toString() << endl;
+ pLine->move( -1.0, -1.0 ); // displacement
+ cout << pLine->toString() << endl;
+
+ cout << "Laenge der Line: " << pLine->getLength() << endl;
+ cout << "Nach der Skalierung mit dem Faktor 2.0" << endl;
+ pLine->scale( 2.0 );
+ cout << pLine->toString() << endl;
+
+ line1 = *pLine; // test assignment
+ delete pLine;
+ cout << "Nach der Zuweisung:" << endl;
+ cout << line1.toString() << endl << endl;
+
+ cout << "Polygone testen: " << endl;
+ Polygon *pPolygon = new Polygon,
+ triangle( vertices, 3 ),
+ quadrangle( triangle ); // use of copy constructor
+ quadrangle += Point( 0, -2 );
+
+ cout << pPolygon->toString() << endl;
+ cout << "Dreieck: " << triangle.toString() << endl;
+ cout << "Viereck: " << quadrangle.toString() << endl;
+ cout << "Anzahl Ecken: " << quadrangle.getNumberOfVertices() << endl
+ << "Umfang : " << quadrangle.getCircumference() << endl;
+
+ cout << "Zuweisung:" << endl;
+ *pPolygon = triangle; // test assignment
+ cout << pPolygon->toString() << endl;
+ cout << "Umfang des Dreiecks: "
+ << pPolygon->getCircumference() << endl << endl;
+ delete pPolygon;
+
+ cout << "Rechtecke:" << endl;
+ Rectangle rect1( Point( -2, -1 ), 2, 1 ), // left lower corner, width, height
+ rect2( Point( 0, 0 ), Point( 1, 1 ) );
+ cout << rect1.toString() << endl;
+ cout << rect2.toString() << endl;
+ cout << "Umfang der Rechtecke: "
+ << rect1.getCircumference() << " und "
+ << rect2.getCircumference() << endl;
+ cin.get();
+
+ cout << "Ellipsen und Kreise:" << endl;
+ Ellipse ellipse( Point( 0, 0 ), 2, 1 ); // center, semi-axis
+ cout << ellipse.toString() << endl;
+ cout << "Umfang: " << ellipse.getCircumference() << endl;
+
+ Circle circle( Point( 0, 0 ), 1 );
+ cout << circle.toString() << endl;
+ cout << "Umfang: " << circle.getCircumference() << endl;
+ circle.scale( 2.0 );
+ cout << circle.toString() << endl;
+ cout << "Umfang: " << circle.getCircumference() << endl;
+
+ return 0;
+}
|
