From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp (limited to 'Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp') diff --git a/Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp b/Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp new file mode 100644 index 0000000..d677b09 --- /dev/null +++ b/Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp @@ -0,0 +1,71 @@ +// Übung PG 2, Teil 4 +// inhomogeneous list for Shape-Objects (2nd version) +// Author: Prinz / Kirch-Prinz / Weber +// Date: 26.05.05 + +#include +#include "shapeList.h" +using namespace std; + +int main() +{ + cout << "\n\t *** Eine Liste geometrischer Figuren ***\n" + << endl; + ShapePtrList myShapes; + cout << myShapes.toString() << endl; // print list + + cout << "Elemente in die Liste einfuegen: " << endl; + // append at end of list: + myShapes.push_back( new Line( Point( 0, 0 ), Point( 2, 2 ) ) ); + myShapes.push_back( new Rectangle( Point( -1, -1 ), 2, 2) ); + + // insert ellipse at front of list: + myShapes.push_front( new Ellipse( Point( 0, 0 ), 3, 1) ); + + Point vertices[] = { Point( 0, -3 ), Point( -3, 0 ), Point( 0, 3 ), Point( 3, 0 ) }; + Shape* ptr = new Polygon( vertices, 4 ); // a rombus + // insert polygon as second element: + myShapes.insert( ++myShapes.begin(), ptr ); + + // a circle as last-but-one element: + ShapePtrList::iterator pos = // position of circle + myShapes.insert( --myShapes.end(), new Circle( Point( 0, 0 ), 5 ) ); + ( *pos )->scale( 0.7 ); // make this element smaller + + cout << "Anzahl Elemente in der Liste: " + << myShapes.size() << endl; + cout << myShapes.toString() << endl; // print list + + cout << "Figur vor dem Kreis loeschen ... " << endl; + myShapes.erase( --pos ); + + cout << "und die zweite Figur (das Polygon) verschieben: " << endl; + pos = myShapes.begin(); + ptr = *( ++pos ); // second element = pointer to polygon + ptr->move( 0, 3 ); // move upwards + + cout << "Die veraenderte Liste: " << endl + << myShapes.toString(); // print list + cin.get(); + + cout << "Kopie der Liste anlegen " + "und Groesse der Figuren verdoppeln:" << endl; + ShapePtrList yourShapes( myShapes ); // use of copy constructor + yourShapes.scale( 2.0 ); // double size of figures + cout << yourShapes.toString() << endl; // print new list + + cout << "Die urspruengliche Liste ist unveraendert:\n" + << myShapes.toString() << endl; // print old list + + cout << "Zuweisung von Listen testen!\n" + << "Erste Figur (Ellipse) in der neuen Liste loeschen" + << endl; + yourShapes.pop_front(); + cout << "und die Liste der urspruengliche Liste zuweisen:" << endl; + myShapes = yourShapes; // assignment + + cout << myShapes.toString(); // print result + cin.get(); + + return 0; +} -- cgit v1.2.3