summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Z-Uebung
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Prog2/Z-Uebung')
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil1/Teil1.dsp108
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil1/main1.cpp61
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil1/shape.cpp114
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil1/shape.h120
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil2/Teil2.dsp108
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp115
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil2/shape.cpp114
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil2/shape.h260
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil3/Teil3.dsp108
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil3/main3.cpp77
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil3/shape.cpp132
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil3/shape.h258
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil4/Teil4.dsp112
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp71
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil4/shape.cpp116
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil4/shape.h265
-rw-r--r--Bachelor/Prog2/Z-Uebung/Teil4/shapeList.h89
-rw-r--r--Bachelor/Prog2/Z-Uebung/Z-Uebung.htm330
-rw-r--r--Bachelor/Prog2/Z-Uebung/Z_Ueb.zipbin0 -> 21843 bytes
-rw-r--r--Bachelor/Prog2/Z-Uebung/Z_Uebung.dsw65
20 files changed, 2623 insertions, 0 deletions
diff --git a/Bachelor/Prog2/Z-Uebung/Teil1/Teil1.dsp b/Bachelor/Prog2/Z-Uebung/Teil1/Teil1.dsp
new file mode 100644
index 0000000..3fd8d7a
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil1/Teil1.dsp
@@ -0,0 +1,108 @@
+# Microsoft Developer Studio Project File - Name="Teil1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Teil1 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "Teil1.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "Teil1.mak" CFG="Teil1 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "Teil1 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "Teil1 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Teil1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "Teil1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GR- /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Teil1 - Win32 Release"
+# Name "Teil1 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main1.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\shape.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\shape.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog2/Z-Uebung/Teil1/main1.cpp b/Bachelor/Prog2/Z-Uebung/Teil1/main1.cpp
new file mode 100644
index 0000000..3dbd65d
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil1/main1.cpp
@@ -0,0 +1,61 @@
+// Übung PG 2, Teil 1
+// test Shape and Polyline
+// Author: Prinz / Kirch-Prinz / Weber
+// Date: 26.05.05
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::cin;
+
+#include "shape.h"
+
+int main()
+{
+ cout << "\nGeometrische Figuren: Linienzuege\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;
+
+ return 0;
+}
diff --git a/Bachelor/Prog2/Z-Uebung/Teil1/shape.cpp b/Bachelor/Prog2/Z-Uebung/Teil1/shape.cpp
new file mode 100644
index 0000000..b23dfab
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil1/shape.cpp
@@ -0,0 +1,114 @@
+// shape.cpp
+// Implementation of classes Shape and Polyline.
+
+#include "shape.h"
+
+// class Shape
+// all methods inline
+
+// class Polyline
+Polyline::Polyline( Point arr[], int n )
+{
+ arrPoints = NULL;
+ nLines = 0;
+ if( n > 0 ) {
+ anchor = arr[ 0 ]; // anchor
+ if( n > 1 ) {
+ nLines = n - 1;
+ // save points relatively to anchor
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < n-1; ++i )
+ arrPoints[ i ] = arr[ i + 1 ] - anchor;
+ }
+ }
+}
+
+Polyline::Polyline( const Polyline& src ) // copy constructor
+{
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+
+ if( src.nLines > 0 ) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+}
+
+Polyline& Polyline::operator=( const Polyline& src ) // assignment
+{
+ if( this != &src ) {
+ delete [] arrPoints;
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+ if( src.nLines > 0 ) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+ }
+ return *this;
+}
+
+double Polyline::getLength() const
+{
+ double len = 0.0;
+ if( nLines > 0 ) {
+ Point begin( 0, 0 );
+ for( int i = 0; i < nLines; ++i ) {
+ len += begin.distance( arrPoints[ i ] );
+ begin = arrPoints[ i ];
+ }
+ }
+ return len;
+}
+
+// append one more point:
+Polyline& Polyline::operator+=( const Point& p )
+{
+ Point* ptr = new Point[ nLines + 1 ]; // new array
+ for( int i = 0 ; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ ptr[ nLines ] = p - anchor; // add new point
+ ++nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ return *this;
+}
+
+// append a second line:
+Polyline& Polyline::operator+=( const Polyline& src )
+{
+ if( src.nLines > 0 ) {
+ Point last = Point( 0, 0 ); // rel. coordinates of last point
+ if( nLines > 0 )
+ last = arrPoints[ nLines - 1 ];
+ Point* ptr = new Point[ nLines + src.nLines ]; // new array
+ int i;
+ for( i = 0; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ for( i = 0; i < src.nLines; ++i ) // append points of src
+ ptr[ nLines + i ] = last + src.arrPoints[ i ];
+
+ nLines += src.nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ }
+ return *this;
+}
+
+void Polyline::scale( double scalingFactor )
+{
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] *= scalingFactor;
+}
+
+string Polyline::toString() const // points of line
+{
+ string str = anchor.toString();
+ for( int i = 0; i < nLines; ++i )
+ str += " ", str += ( anchor + arrPoints[ i ] ).toString();
+ return str;
+}
diff --git a/Bachelor/Prog2/Z-Uebung/Teil1/shape.h b/Bachelor/Prog2/Z-Uebung/Teil1/shape.h
new file mode 100644
index 0000000..a304329
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil1/shape.h
@@ -0,0 +1,120 @@
+// shape.h
+// Definition of classes Point, Shape and Polyline.
+
+#ifndef SHAPE_H
+#define SHAPE_H
+
+#include <sstream>
+using std::string;
+using std::stringstream;
+using std::ostream;
+
+#include <cmath> // sqrt
+
+// class Point
+struct Point
+{
+ double x, y;
+ Point( double xx = 0.0, double yy = 0.0 )
+ : x( xx ), y( yy ) { }
+
+ double distance( const Point& p2 ) const
+ {
+ double dx = x - p2.x,
+ dy = y - p2.y;
+ return sqrt( dx * dx + dy * dy );
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << '(' << x << ", " << y << ')';
+ return sstream.str();
+ }
+ Point& operator*=( double c )
+ { x *= c; y *= c; return *this; }
+};
+
+inline Point operator+( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x + p2.x, p1.y + p2.y );
+}
+
+inline Point operator-( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x - p2.x, p1.y - p2.y );
+}
+
+inline bool operator==( const Point& p1, const Point& p2 )
+{
+ return p1.x == p2.x && p1.y == p2.y;
+}
+
+inline bool operator!=( const Point& p1, const Point& p2 )
+{
+ return !( p1 == p2 );
+}
+
+inline ostream& operator<<( ostream& os, const Point& p )
+{
+ os << p.toString();
+ return os;
+}
+
+// class Shape
+class Shape
+{
+ protected:
+ Point anchor; // anchor: point of reference for position of figure
+ public:
+ Shape( const Point& a = Point() ) : anchor( a ) { }
+ virtual ~Shape() {}
+
+ Point getAnchor() const { return anchor; }
+ void setAnchor( Point a ) { anchor = a; }
+
+ void move( double dx, double dy ) // displacement
+ { anchor.x += dx; anchor.y += dy; }
+
+ virtual void scale( double scalingFactor ) = 0;
+ virtual void draw() const = 0;
+
+ virtual string toString() const
+ {
+ string str( "Shape-Anker: " );
+ return str += anchor.toString();
+ }
+};
+
+// class Polyline
+class Polyline : public Shape
+{
+ protected:
+ Point* arrPoints; // end-points of lines, relativ to anchor
+ int nLines; // number of line-segments == number of end-points
+
+ public:
+ Polyline( const Point& a = Point() ) // only one point
+ : Shape( a ), nLines( 0 ), arrPoints( NULL ) { }
+ Polyline( const Point& p1, const Point& p2 ) // one line
+ : Shape( p1 ), nLines( 1 )
+ {
+ arrPoints = new Point( p2 - p1 );
+ }
+ Polyline( Point arr[], int n );
+ Polyline( const Polyline& src ); // copy constructor
+ ~Polyline() { delete [] arrPoints; } // destructor
+
+ Polyline& operator=( const Polyline& src ); // assignment
+
+ int getNumberOfLines() const { return nLines; }
+ double getLength() const;
+ void scale( double scalingFactor ); // scaling
+ virtual void draw() const { }
+
+ Polyline& operator+=( const Point& p ); // appends a new point
+ Polyline& operator+=( const Polyline& pl ); // appends a new line
+
+ string toString() const;
+};
+
+#endif
diff --git a/Bachelor/Prog2/Z-Uebung/Teil2/Teil2.dsp b/Bachelor/Prog2/Z-Uebung/Teil2/Teil2.dsp
new file mode 100644
index 0000000..4b7ce61
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil2/Teil2.dsp
@@ -0,0 +1,108 @@
+# Microsoft Developer Studio Project File - Name="Teil2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Teil2 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "Teil2.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "Teil2.mak" CFG="Teil2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "Teil2 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "Teil2 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Teil2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "Teil2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GR- /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Teil2 - Win32 Release"
+# Name "Teil2 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main2.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\shape.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\shape.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
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;
+}
diff --git a/Bachelor/Prog2/Z-Uebung/Teil2/shape.cpp b/Bachelor/Prog2/Z-Uebung/Teil2/shape.cpp
new file mode 100644
index 0000000..87c75fe
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil2/shape.cpp
@@ -0,0 +1,114 @@
+// shape.cpp
+// Implementation of classes Shape and Polyline.
+
+#include "shape.h"
+
+// class Shape
+// all methods inline
+
+// class Polyline
+Polyline::Polyline( Point arr[], int n )
+{
+ arrPoints = NULL;
+ nLines = 0;
+ if( n > 0 ) {
+ anchor = arr[ 0 ]; // anchor
+ if( n > 1 ) {
+ nLines = n - 1;
+ // save points relatively to anchor
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < n-1; ++i )
+ arrPoints[ i ] = arr[ i + 1 ] - anchor;
+ }
+ }
+}
+
+Polyline::Polyline( const Polyline& src ) // copy constructor
+{
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+
+ if( src.nLines > 0) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+}
+
+Polyline& Polyline::operator=( const Polyline& src ) // assignment
+{
+ if( this != &src) {
+ delete [] arrPoints;
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+ if( src.nLines > 0 ) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+ }
+ return *this;
+}
+
+double Polyline::getLength() const
+{
+ double len = 0.0;
+ if( nLines > 0 ) {
+ Point begin( 0, 0 );
+ for( int i = 0; i < nLines; ++i ) {
+ len += begin.distance( arrPoints[ i ] );
+ begin = arrPoints[ i ];
+ }
+ }
+ return len;
+}
+
+// append one more point:
+Polyline& Polyline::operator+=( const Point& p )
+{
+ Point* ptr = new Point[ nLines + 1 ]; // new array
+ for( int i = 0 ; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ ptr[ nLines ] = p - anchor; // add new point
+ ++nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ return *this;
+}
+
+// append a second line:
+Polyline& Polyline::operator+=( const Polyline& src )
+{
+ if( src.nLines > 0 ) {
+ Point last = Point( 0, 0 ); // rel. coordinates of last point
+ if( nLines > 0 )
+ last = arrPoints[ nLines - 1 ];
+ Point* ptr = new Point[ nLines + src.nLines ]; // new array
+ int i;
+ for( i = 0; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ for( i = 0; i < src.nLines; ++i ) // append points of src
+ ptr[ nLines + i ] = last + src.arrPoints[ i ];
+
+ nLines += src.nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ }
+ return *this;
+}
+
+void Polyline::scale( double scalingFactor )
+{
+ for( int i=0; i < nLines; ++i )
+ arrPoints[ i ] *= scalingFactor;
+}
+
+string Polyline::toString() const // points of line
+{
+ string str = anchor.toString();
+ for( int i = 0; i < nLines; ++i )
+ str += " ", str += ( anchor + arrPoints[ i ] ).toString();
+ return str;
+}
diff --git a/Bachelor/Prog2/Z-Uebung/Teil2/shape.h b/Bachelor/Prog2/Z-Uebung/Teil2/shape.h
new file mode 100644
index 0000000..454613b
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil2/shape.h
@@ -0,0 +1,260 @@
+// shape.h
+// Definition of classes Point, Shape, Polyline,
+// Line, Polygon, Rectangle, Ellipse, Circle.
+
+#ifndef SHAPE_H
+#define SHAPE_H
+
+#include <sstream>
+using std::string;
+using std::stringstream;
+using std::ostream;
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::cin;
+
+#include <cmath> // sqrt
+
+// class Point
+struct Point
+{
+ double x, y;
+ Point( double xx = 0.0, double yy = 0.0 )
+ : x( xx ), y( yy ) { }
+
+ double distance( const Point& p2 ) const
+ {
+ double dx = x - p2.x,
+ dy = y - p2.y;
+ return sqrt( dx * dx + dy * dy );
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << '(' << x << ", " << y << ')';
+ return sstream.str();
+ }
+ Point& operator*=( double c)
+ {
+ x *= c;
+ y *= c;
+ return *this;
+ }
+};
+
+inline Point operator+( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x + p2.x, p1.y + p2.y );
+}
+
+inline Point operator-( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x - p2.x, p1.y - p2.y );
+}
+
+inline bool operator==( const Point& p1, const Point& p2 )
+{
+ return p1.x == p2.x && p1.y == p2.y;
+}
+
+inline bool operator!=( const Point& p1, const Point& p2 )
+{
+ return !(p1 == p2);
+}
+
+inline ostream& operator<<( ostream& os, const Point& p )
+{
+ os << p.toString();
+ return os;
+}
+
+// class Shape
+class Shape
+{
+ protected:
+ Point anchor; // anchor: point of reference for position of figure
+ public:
+ Shape( const Point& a = Point() ) : anchor( a ) { }
+ virtual ~Shape() { }
+
+ Point getAnchor() const { return anchor; }
+ void setAnchor( Point a ) { anchor = a; }
+
+ void move( double dx, double dy ) // displacement
+ { anchor.x += dx; anchor.y += dy; }
+
+ virtual void scale( double scalingFactor ) = 0;
+ virtual void draw() const = 0;
+
+ virtual string toString() const
+ {
+ string str( "Shape-Anker: " );
+ return str += anchor.toString();
+ }
+};
+
+// class Polyline
+class Polyline : public Shape
+{
+ protected:
+ Point* arrPoints; // end-points of lines, relativ to anchor
+ int nLines; // number of line-segments == number of end-points
+
+ public:
+ Polyline( const Point& a = Point() ) // only one point
+ : Shape( a ), nLines( 0 ), arrPoints( NULL ) { }
+ Polyline( const Point& p1, const Point& p2 ) // one line
+ : Shape( p1 ), nLines( 1 )
+ {
+ arrPoints = new Point( p2 - p1 );
+ }
+ Polyline( Point arr[], int n );
+ Polyline( const Polyline& src ); // copy constructor
+ ~Polyline() { delete [] arrPoints; } // destructor
+
+ Polyline& operator=( const Polyline& src ); // assignment
+
+ int getNumberOfLines() const { return nLines; }
+ double getLength() const;
+ void scale( double scalingFactor ); // scaling
+ virtual void draw() const { }
+
+ Polyline& operator+=( const Point& p ); // appends a new point
+ Polyline& operator+=( const Polyline& pl ); // appends a new line
+
+ string toString() const;
+};
+
+// class Line
+class Line : public Polyline
+{
+ public:
+ Line( Point a, Point b ) : Polyline( a, b ) { }
+ Line( double x1, double y1, double x2, double y2 )
+ : Polyline( Point( x1, y1 ), Point( x2, y2 ) ) { }
+ private:
+ Polyline& operator+=( const Point& ); // not allowed
+ Polyline& operator+=( const Polyline& ); // not allowed
+};
+
+// class Polygon
+class Polygon : public Polyline
+{
+ public:
+ Polygon( Point a = Point( 0, 0 ) ) : Polyline( a ) { }
+ Polygon( Point arr[ ], int n )
+ : Polyline( arr, n )
+ { }
+
+ int getNumberOfVertices() const
+ {
+ if( nLines == 0 || arrPoints[ nLines - 1 ] != anchor )
+ return nLines + 1;
+ else
+ return nLines;
+ }
+ int getNumberOfLines() const
+ { return getNumberOfVertices(); }
+
+ double getCircumference() const
+ {
+ double len = Polyline::getLength();
+ if( nLines > 0 )
+ len += anchor.distance( anchor + arrPoints[ nLines - 1 ] );
+ return len;
+ }
+ double getLength() const { return getCircumference(); }
+};
+
+// class Rectangle
+class Rectangle : public Polygon // rectangle
+{ // anchor: left lower corner
+ public:
+ Rectangle( Point lBottom, double w, double h )
+ : Polygon( lBottom )
+ {
+ nLines = 3; // number of lines: nLines + 1
+ arrPoints = new Point[ 3 ];
+ arrPoints[ 0 ] = Point( 0, h );
+ arrPoints[ 1 ] = Point( w, h );
+ arrPoints[ 2 ] = Point( w, 0 );
+ }
+ Rectangle( Point lBottom, Point rTop )
+ {
+ *this = Rectangle( lBottom, rTop.x - lBottom.x, rTop.y - lBottom.y );
+ }
+ double getHeight() const { return arrPoints[ 0 ].y; }
+ double getWidth() const { return arrPoints[ 2 ].x; }
+ double getArea() const { return getHeight() * getWidth(); }
+
+ private:
+ Polyline& operator+=( const Point& ); // not allowed
+ Polyline& operator+=( const Polyline& ); // not allowed
+};
+
+// class Ellipse
+class Ellipse : public Shape // anchor-centered ellipse
+{
+ protected:
+ double a, b; // semi-major and semi-minor axis
+
+ public:
+ Ellipse( Point m, double aa, double bb )
+ : Shape( m ), a( aa ), b( bb )
+ { }
+ double getSemimajorAxis() const { return a; }
+ double getSemiminorAxis() const { return b; }
+ bool setSemimajorAxis( double aa )
+ {
+ if( aa >= 0) { a = aa; return true; }
+ else return false;
+ }
+ bool setSemiminorAxis( double bb )
+ {
+ if( bb >= 0 ) { b = bb; return true; }
+ else return false;
+ }
+ void scale( double scalingFactor ) // scaling
+ {
+ a *= scalingFactor; b *= scalingFactor;
+ }
+ virtual void draw() const { }
+ double getCircumference() const
+ {
+ return 3.14159 * ( 1.5 * ( a + b ) - sqrt( a * b ) );
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << "Ellipsen-Mittelpunkt: " << anchor.toString()
+ << " Grosse Halbachse: " << a
+ << " Kleine Halbachse: " << b;
+ return sstream.str();
+ }
+};
+
+// class Circle
+class Circle : public Ellipse // anchor-centered circle
+{
+ public:
+ Circle( Point m, double r )
+ : Ellipse( m, r, r )
+ {}
+ double getRadius() const { return a; }
+ bool setRadius( double r)
+ {
+ if( r >= 0 ) { a = r; b = r; return true; }
+ else return false;
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << "Kreis-Mittelpunkt: " << anchor.toString()
+ << " Radius: " << a;
+ return sstream.str();
+ }
+};
+
+#endif
diff --git a/Bachelor/Prog2/Z-Uebung/Teil3/Teil3.dsp b/Bachelor/Prog2/Z-Uebung/Teil3/Teil3.dsp
new file mode 100644
index 0000000..a97b9e2
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil3/Teil3.dsp
@@ -0,0 +1,108 @@
+# Microsoft Developer Studio Project File - Name="Teil3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Teil3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "Teil3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "Teil3.mak" CFG="Teil3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "Teil3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "Teil3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Teil3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "Teil3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GR /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Teil3 - Win32 Release"
+# Name "Teil3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main3.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\shape.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\shape.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog2/Z-Uebung/Teil3/main3.cpp b/Bachelor/Prog2/Z-Uebung/Teil3/main3.cpp
new file mode 100644
index 0000000..94e76ac
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil3/main3.cpp
@@ -0,0 +1,77 @@
+// Übung PG 2, Teil 3
+// inhomogeneous list for Shape-Objects
+// Author: Prinz / Kirch-Prinz / Weber
+// Date: 26.05.05
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::cin;
+using std::left;
+
+#include <typeinfo>
+#include <list> // class-Template list< T >
+ // T is type of list elements
+#include "shape.h"
+
+typedef std::list< Shape* > ShapePtrList;
+
+void printShapeList( const ShapePtrList& spl );
+
+int main()
+{
+ cout << "\n\t *** Eine Liste geometrischer Figuren ***\n"
+ << endl;
+ ShapePtrList myShapes;
+ printShapeList( myShapes );
+
+ cout << "\nElemente 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;
+ printShapeList( myShapes ); // 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;
+ printShapeList( myShapes ); // print list
+
+ return 0;
+}
+
+void printShapeList( const ShapePtrList& spl )
+{
+ if( spl.empty() ) {
+ cout << "Die Liste ist leer!" << endl;
+ return;
+ }
+ ShapePtrList::const_iterator pos = spl.begin();
+ for( ; pos != spl.end(); ++pos ) {
+ cout.width(20);
+ cout << left << typeid( **pos ).name();
+ cout << ( *pos )->toString() << endl;
+ }
+ cout << endl;
+}
diff --git a/Bachelor/Prog2/Z-Uebung/Teil3/shape.cpp b/Bachelor/Prog2/Z-Uebung/Teil3/shape.cpp
new file mode 100644
index 0000000..7f078f3
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil3/shape.cpp
@@ -0,0 +1,132 @@
+// shape.cpp
+// Implementation of classes Shape and Polyline.
+
+#include "shape.h"
+
+// class Shape
+// all methods inline
+
+// class Polyline
+Polyline::Polyline( Point arr[], int n )
+{
+ arrPoints = NULL;
+ nLines = 0;
+ if( n > 0 ) {
+ anchor = arr[ 0 ]; // anchor
+ if( n > 1 ) {
+ nLines = n - 1;
+ // save points relatively to anchor
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < n - 1; ++i )
+ arrPoints[ i ] = arr[ i + 1 ] - anchor;
+ }
+ }
+}
+
+Polyline::Polyline( const Polyline& src ) // copy constructor
+{
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+
+ if( src.nLines > 0 ) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+}
+
+Polyline& Polyline::operator=( const Polyline& src ) // assignment
+{
+ if( this != &src) {
+ delete [] arrPoints;
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+ if( src.nLines > 0 ) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+ }
+ return *this;
+}
+
+double Polyline::getLength() const
+{
+ double len = 0.0;
+ if( nLines > 0 ) {
+ Point begin( 0, 0 );
+ for( int i = 0; i < nLines; ++i ) {
+ len += begin.distance( arrPoints[ i ] );
+ begin = arrPoints[ i ];
+ }
+ }
+ return len;
+}
+
+// append one more point:
+Polyline& Polyline::operator+=( const Point& p )
+{
+ Point* ptr = new Point[ nLines + 1 ]; // new array
+ for( int i = 0 ; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ ptr[ nLines ] = p - anchor; // add new point
+ ++nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ return *this;
+}
+
+// append a second line:
+Polyline& Polyline::operator+=( const Polyline& src )
+{
+ if( src.nLines > 0 ) {
+ Point last = Point( 0, 0 ); // rel. coordinates of last point
+ if( nLines > 0 )
+ last = arrPoints[ nLines - 1 ];
+ Point* ptr = new Point[ nLines + src.nLines ]; // new array
+ int i;
+ for( i = 0; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ for( i = 0; i < src.nLines; ++i ) // append points of src
+ ptr[ nLines + i ] = last + src.arrPoints[ i ];
+
+ nLines += src.nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ }
+ return *this;
+}
+
+void Polyline::scale( double scalingFactor )
+{
+ for( int i=0; i < nLines; ++i )
+ arrPoints[i] *= scalingFactor;
+}
+
+string Polyline::toString() const // points of line
+{
+ string str = anchor.toString();
+ for( int i=0; i < nLines; ++i )
+ str += " ", str += ( anchor + arrPoints[ i ] ).toString();
+ return str;
+}
+/*
+string Line::toString() const
+{
+ string str( "Linie, Start- und Endpunkt: ");
+ str += anchor.toString();
+ str += " ", str += ( anchor + arrPoints[ 0 ] ).toString();
+ return str;
+}
+
+string Polygon::toString() const
+{
+ string str( "Die Ecken des Polygons: " );
+ str += anchor.toString();
+ for( int i=0; i < nLines; ++i )
+ str += " ", str += ( anchor + arrPoints[ i ] ).toString();
+ return str;
+}
+*/
diff --git a/Bachelor/Prog2/Z-Uebung/Teil3/shape.h b/Bachelor/Prog2/Z-Uebung/Teil3/shape.h
new file mode 100644
index 0000000..84f2b77
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil3/shape.h
@@ -0,0 +1,258 @@
+// shape.h
+// Definition of classes Point, Shape, Polyline,
+// Line, Polygon, Rectangle, Ellipse, Circle.
+
+#ifndef SHAPE_H
+#define SHAPE_H
+
+#include <sstream>
+using std::string;
+using std::stringstream;
+using std::ostream;
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::cin;
+
+#include <cmath> // sqrt
+
+// class Point
+struct Point
+{
+ double x, y;
+ Point( double xx = 0.0, double yy = 0.0 )
+ : x( xx ), y( yy ) { }
+
+ double distance( const Point& p2 ) const
+ {
+ double dx = x - p2.x,
+ dy = y - p2.y;
+ return sqrt( dx * dx + dy * dy );
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << '(' << x << ", " << y << ')';
+ return sstream.str();
+ }
+ Point& operator*=( double c )
+ {
+ x *= c;
+ y *= c;
+ return *this;
+ }
+};
+
+inline Point operator+( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x + p2.x, p1.y + p2.y );
+}
+
+inline Point operator-( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x - p2.x, p1.y - p2.y );
+}
+
+inline bool operator==( const Point& p1, const Point& p2 )
+{
+ return p1.x == p2.x && p1.y == p2.y;
+}
+
+inline bool operator!=( const Point& p1, const Point& p2 )
+{
+ return !( p1 == p2 );
+}
+
+inline ostream& operator<<( ostream& os, const Point& p )
+{
+ os << p.toString(); return os;
+}
+
+// class Shape
+class Shape
+{
+ protected:
+ Point anchor; // anchor: point of reference for position of figure
+ public:
+ Shape( const Point& a = Point() ) : anchor( a ) { }
+ virtual ~Shape() { }
+
+ Point getAnchor() const { return anchor; }
+ void setAnchor( Point a ) { anchor = a; }
+
+ void move( double dx, double dy ) // displacement
+ { anchor.x += dx; anchor.y += dy; }
+
+ virtual void scale( double scalingFactor ) = 0;
+ virtual void draw() const = 0;
+
+ virtual string toString() const
+ {
+ string str( "Shape-Anker: " );
+ return str += anchor.toString();
+ }
+};
+
+// class Polyline
+class Polyline : public Shape
+{
+ protected:
+ Point* arrPoints; // end-points of lines, relativ to anchor
+ int nLines; // number of line-segments == number of end-points
+
+ public:
+ Polyline( const Point& a = Point() ) // only one point
+ : Shape( a ), nLines( 0 ), arrPoints( NULL ) { }
+ Polyline( const Point& p1, const Point& p2 ) // one line
+ : Shape( p1 ), nLines( 1 )
+ {
+ arrPoints = new Point( p2 - p1 );
+ }
+ Polyline( Point arr[], int n );
+ Polyline( const Polyline& src ); // copy constructor
+ ~Polyline() { delete [] arrPoints; } // destructor
+
+ Polyline& operator=( const Polyline& src ); // assignment
+
+ int getNumberOfLines() const { return nLines; }
+ double getLength() const;
+ void scale( double scalingFactor ); // scaling
+ virtual void draw() const { }
+
+ Polyline& operator+=( const Point& p ); // appends a new point
+ Polyline& operator+=( const Polyline& pl ); // appends a new line
+
+ string toString() const;
+};
+
+// class Line
+class Line : public Polyline
+{
+ public:
+ Line( Point a, Point b ) : Polyline( a, b ) { }
+ Line( double x1, double y1, double x2, double y2 )
+ : Polyline( Point( x1, y1 ), Point( x2, y2 ) ) { }
+ private:
+ Polyline& operator+=( const Point& ); // not allowed
+ Polyline& operator+=( const Polyline& ); // not allowed
+};
+
+// class Polygon
+class Polygon : public Polyline
+{
+ public:
+ Polygon( Point a = Point( 0, 0 ) ) : Polyline( a ) {}
+ Polygon( Point arr[], int n )
+ : Polyline( arr, n )
+ {}
+
+ int getNumberOfVertices() const
+ {
+ if( nLines == 0 || arrPoints[ nLines - 1 ] != anchor )
+ return nLines + 1;
+ else
+ return nLines;
+ }
+ int getNumberOfLines() const
+ { return getNumberOfVertices(); }
+
+ double getCircumference() const
+ {
+ double len = Polyline::getLength();
+ if( nLines > 0 )
+ len += anchor.distance( anchor + arrPoints[ nLines - 1 ] );
+ return len;
+ }
+ double getLength() const { return getCircumference(); }
+};
+
+// class Rectangle
+class Rectangle : public Polygon // rectangle
+{ // anchor: left lower corner
+ public:
+ Rectangle( Point lBottom, double w, double h )
+ : Polygon( lBottom )
+ {
+ nLines = 3; // number of lines: nLines + 1
+ arrPoints = new Point[ 3 ];
+ arrPoints[ 0 ] = Point( 0, h );
+ arrPoints[ 1 ] = Point( w, h );
+ arrPoints[ 2 ] = Point( w, 0 );
+ }
+ Rectangle( Point lBottom, Point rTop )
+ {
+ *this = Rectangle( lBottom, rTop.x - lBottom.x, rTop.y - lBottom.y );
+ }
+ double getHeight() const { return arrPoints[ 0 ].y; }
+ double getWidth() const { return arrPoints[ 2 ].x; }
+ double getArea() const { return getHeight() * getWidth(); }
+
+ private:
+ Polyline& operator+=( const Point& ); // not allowed
+ Polyline& operator+=( const Polyline& ); // not allowed
+};
+
+// class Ellipse
+class Ellipse : public Shape // anchor-centered ellipse
+{
+ protected:
+ double a, b; // semi-major and semi-minor axis
+
+ public:
+ Ellipse( Point m, double aa, double bb )
+ : Shape( m ), a( aa ), b( bb )
+ { }
+ double getSemimajorAxis() const { return a; }
+ double getSemiminorAxis() const { return b; }
+ bool setSemimajorAxis( double aa )
+ {
+ if( aa >= 0 ) { a = aa; return true; }
+ else return false;
+ }
+ bool setSemiminorAxis( double bb )
+ {
+ if( bb >= 0 ) { b = bb; return true; }
+ else return false;
+ }
+ void scale( double scalingFactor ) // scaling
+ {
+ a *= scalingFactor; b *= scalingFactor;
+ }
+ virtual void draw() const { }
+ double getCircumference() const
+ {
+ return 3.14159 * ( 1.5 * ( a + b ) - sqrt( a * b ) );
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << "Ellipsen-Mittelpunkt: " << anchor.toString()
+ << " Halbachsen: " << a << " und " << b;
+ return sstream.str();
+ }
+};
+
+// class Circle
+class Circle : public Ellipse // anchor-centered circle
+{
+ public:
+ Circle( Point m, double r )
+ : Ellipse( m, r, r )
+ { }
+ double getRadius() const { return a; }
+ bool setRadius( double r )
+ {
+ if( r >= 0 ) { a = r; b = r; return true; }
+ else return false;
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << "Kreis-Mittelpunkt: " << anchor.toString()
+ << " Radius: " << a;
+ return sstream.str();
+ }
+};
+
+#endif
diff --git a/Bachelor/Prog2/Z-Uebung/Teil4/Teil4.dsp b/Bachelor/Prog2/Z-Uebung/Teil4/Teil4.dsp
new file mode 100644
index 0000000..5c1d3d5
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil4/Teil4.dsp
@@ -0,0 +1,112 @@
+# Microsoft Developer Studio Project File - Name="Teil4" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Teil4 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "Teil4.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "Teil4.mak" CFG="Teil4 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "Teil4 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "Teil4 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Teil4 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "Teil4 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GR /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Teil4 - Win32 Release"
+# Name "Teil4 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main4.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\shape.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\shape.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\shapeList.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
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 <iostream>
+#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;
+}
diff --git a/Bachelor/Prog2/Z-Uebung/Teil4/shape.cpp b/Bachelor/Prog2/Z-Uebung/Teil4/shape.cpp
new file mode 100644
index 0000000..16d2478
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil4/shape.cpp
@@ -0,0 +1,116 @@
+// shape.cpp
+// Implementation of classes Shape and Polyline.
+
+#include "shape.h"
+
+// class Shape
+// all methods inline
+
+// class Polyline
+Polyline::Polyline( Point arr[], int n)
+{
+ arrPoints = NULL;
+ nLines = 0;
+ if( n > 0) {
+ anchor = arr[ 0 ]; // anchor
+ if( n > 1) {
+ nLines = n - 1;
+ // save points relatively to anchor
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < n - 1; ++i)
+ arrPoints[i] = arr[ i + 1 ] - anchor;
+ }
+ }
+}
+
+Polyline::Polyline( const Polyline& src ) // copy constructor
+{
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+
+ if( src.nLines > 0 ) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+}
+
+Polyline& Polyline::operator=( const Polyline& src ) // assignment
+{
+ if( this != &src )
+ {
+ delete [] arrPoints;
+ nLines = src.nLines;
+ anchor = src.anchor;
+ arrPoints = NULL;
+ if( src.nLines > 0 ) {
+ arrPoints = new Point[ nLines ];
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] = src.arrPoints[ i ];
+ }
+ }
+ return *this;
+}
+
+double Polyline::getLength() const
+{
+ double len = 0.0;
+ if( nLines > 0 ) {
+ Point begin( 0, 0 );
+ for( int i = 0; i < nLines; ++i ) {
+ len += begin.distance( arrPoints[ i ] );
+ begin = arrPoints[ i ];
+ }
+ }
+ return len;
+}
+
+// append one more point:
+Polyline& Polyline::operator+=( const Point& p )
+{
+ Point* ptr = new Point[ nLines + 1 ]; // new array
+ for( int i = 0 ; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ ptr[ nLines ] = p - anchor; // add new point
+ ++nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ return *this;
+}
+
+// append a second line:
+Polyline& Polyline::operator+=( const Polyline& src )
+{
+ if( src.nLines > 0 )
+ {
+ Point last = Point( 0, 0 ); // rel. coordinates of last point
+ if( nLines > 0 )
+ last = arrPoints[ nLines - 1 ];
+ Point* ptr = new Point[ nLines + src.nLines ]; // new array
+ int i;
+ for( i = 0; i < nLines; ++i ) // copy points into new array
+ ptr[ i ] = arrPoints[ i ];
+ for( i = 0; i < src.nLines; ++i ) // append points of src
+ ptr[ nLines + i ] = last + src.arrPoints[ i ];
+
+ nLines += src.nLines;
+ delete [] arrPoints; // free old array
+ arrPoints = ptr;
+ }
+ return *this;
+}
+
+void Polyline::scale( double scalingFactor )
+{
+ for( int i = 0; i < nLines; ++i )
+ arrPoints[ i ] *= scalingFactor;
+}
+
+string Polyline::toString() const // points of line
+{
+ string str = anchor.toString();
+ for( int i = 0; i < nLines; ++i )
+ str += " ", str += ( anchor + arrPoints[ i ] ).toString();
+ return str;
+}
diff --git a/Bachelor/Prog2/Z-Uebung/Teil4/shape.h b/Bachelor/Prog2/Z-Uebung/Teil4/shape.h
new file mode 100644
index 0000000..9b84b3b
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil4/shape.h
@@ -0,0 +1,265 @@
+// shape.h
+// Definition of classes Point, Shape, Polyline,
+// Line, Polygon, Rectangle, Ellipse, Circle
+// including virtual method clone()
+
+#ifndef SHAPE_H
+#define SHAPE_H
+
+#include <sstream>
+using std::string;
+using std::stringstream;
+using std::ostream;
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::cin;
+
+#include <cmath> // sqrt
+
+// class Point
+struct Point
+{
+ double x, y;
+ Point( double xx = 0.0, double yy = 0.0 )
+ : x( xx ), y( yy ) { }
+
+ double distance( const Point& p2 ) const
+ {
+ double dx = x - p2.x,
+ dy = y - p2.y;
+ return sqrt( dx * dx + dy * dy );
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << '(' << x << ", " << y << ')';
+ return sstream.str();
+ }
+ Point& operator*=( double c )
+ {
+ x *= c;
+ y *= c;
+ return *this;
+ }
+};
+
+inline Point operator+( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x + p2.x, p1.y + p2.y );
+}
+
+inline Point operator-( const Point& p1, const Point& p2 )
+{
+ return Point( p1.x - p2.x, p1.y - p2.y );
+}
+
+inline bool operator==( const Point& p1, const Point& p2 )
+{
+ return p1.x == p2.x && p1.y == p2.y;
+}
+
+inline bool operator!=( const Point& p1, const Point& p2 )
+{
+ return !( p1 == p2 );
+}
+
+inline ostream& operator<<( ostream& os, const Point& p )
+{
+ os << p.toString();
+ return os;
+}
+
+// class Shape
+class Shape
+{
+ protected:
+ Point anchor; // anchor: point of reference for position of figure
+ public:
+ Shape( const Point& a = Point() ) : anchor( a ) { }
+ virtual ~Shape() { cout << "Shape-Destruktor" << endl; }
+
+ Point getAnchor() const { return anchor; }
+ void setAnchor( Point a ) { anchor = a; }
+
+ void move( double dx, double dy ) // displacement
+ { anchor.x += dx; anchor.y += dy; }
+
+ virtual void scale( double scalingFactor ) = 0;
+ virtual void draw() const = 0;
+
+ virtual string toString() const
+ {
+ string str( "Shape-Anker: " );
+ return str += anchor.toString();
+ }
+ virtual Shape* clone() const = 0;
+};
+
+// class Polyline
+class Polyline : public Shape
+{
+ protected:
+ Point* arrPoints; // end-points of lines, relativ to anchor
+ int nLines; // number of line-segments == number of end-points
+
+ public:
+ Polyline( const Point& a = Point() ) // only one point
+ : Shape( a ), nLines( 0 ), arrPoints( NULL ) { }
+ Polyline( const Point& p1, const Point& p2 ) // one line
+ : Shape( p1 ), nLines( 1 )
+ {
+ arrPoints = new Point( p2 - p1 );
+ }
+ Polyline( Point arr[], int n );
+ Polyline( const Polyline& src ); // copy constructor
+ ~Polyline() { delete [] arrPoints; } // destructor
+
+ Polyline& operator=( const Polyline& src ); // assignment
+
+ int getNumberOfLines() const { return nLines; }
+ double getLength() const;
+ void scale( double scalingFactor ); // scaling
+ virtual void draw() const { }
+
+ Polyline& operator+=( const Point& p ); // appends a new point
+ Polyline& operator+=( const Polyline& pl ); // appends a new line
+
+ string toString() const;
+ Shape* clone() const { return new Polyline( *this ); }
+};
+
+// class Line
+class Line : public Polyline
+{
+ public:
+ Line( Point a, Point b ) : Polyline( a, b ) { }
+ Line( double x1, double y1, double x2, double y2 )
+ : Polyline( Point( x1, y1 ), Point( x2, y2 ) ) { }
+ Shape* clone() const { return new Line( *this ); }
+
+ private:
+ Polyline& operator+=( const Point& ); // not allowed
+ Polyline& operator+=( const Polyline& ); // not allowed
+};
+
+// class Polygon
+class Polygon : public Polyline
+{
+ public:
+ Polygon( Point a = Point( 0, 0 ) ) : Polyline( a ) { }
+ Polygon( Point arr[], int n )
+ : Polyline( arr, n )
+ { }
+
+ int getNumberOfVertices() const
+ {
+ if( nLines == 0 || arrPoints[ nLines - 1 ] != anchor )
+ return nLines + 1;
+ else
+ return nLines;
+ }
+ int getNumberOfLines() const
+ { return getNumberOfVertices(); }
+
+ double getCircumference() const
+ {
+ double len = Polyline::getLength();
+ if( nLines > 0 )
+ len += anchor.distance( anchor + arrPoints[ nLines - 1 ] );
+ return len;
+ }
+ double getLength() const { return getCircumference(); }
+ Shape* clone() const { return new Polygon( *this ); }
+};
+
+// class Rectangle
+class Rectangle : public Polygon // rectangle
+{ // anchor: left lower corner
+ public:
+ Rectangle( Point lBottom, double w, double h )
+ : Polygon( lBottom )
+ {
+ nLines = 3; // number of lines: nLines + 1
+ arrPoints = new Point[ 3 ];
+ arrPoints[ 0 ] = Point( 0, h );
+ arrPoints[ 1 ] = Point( w, h );
+ arrPoints[ 2 ] = Point( w, 0 );
+ }
+ Rectangle( Point lBottom, Point rTop )
+ {
+ *this = Rectangle( lBottom, rTop.x - lBottom.x, rTop.y - lBottom.y );
+ }
+ double getHeight() const { return arrPoints[ 0 ].y; }
+ double getWidth() const { return arrPoints[ 2 ].x; }
+ double getArea() const { return getHeight() * getWidth(); }
+ Shape* clone() const { return new Rectangle( *this ); }
+
+ private:
+ Polyline& operator+=( const Point& ); // not allowed
+ Polyline& operator+=( const Polyline& ); // not allowed
+};
+
+// class Ellipse
+class Ellipse : public Shape // anchor-centered ellipse
+{
+ protected:
+ double a, b; // semi-major and semi-minor axis
+
+ public:
+ Ellipse( Point m, double aa, double bb )
+ : Shape( m ), a( aa ), b( bb )
+ { }
+ double getSemimajorAxis() const { return a; }
+ double getSemiminorAxis() const { return b; }
+ bool setSemimajorAxis( double aa )
+ { if( aa >= 0 ) { a = aa; return true; }
+ else return false;
+ }
+ bool setSemiminorAxis( double bb )
+ { if( bb >= 0 ) { b = bb; return true; }
+ else return false;
+ }
+ void scale( double scalingFactor ) // scaling
+ {
+ a *= scalingFactor; b *= scalingFactor;
+ }
+ virtual void draw() const { }
+ double getCircumference() const
+ {
+ return 3.14159 * ( 1.5 * ( a + b ) - sqrt( a * b ) );
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << "Ellipsen-Mittelpunkt: " << anchor.toString()
+ << " Halbachsen: " << a << " und " << b;
+ return sstream.str();
+ }
+ Shape* clone() const { return new Ellipse( *this ); }
+};
+
+// class Circle
+class Circle : public Ellipse // anchor-centered circle
+{
+ public:
+ Circle( Point m, double r )
+ : Ellipse( m, r, r )
+ { }
+ double getRadius() const { return a; }
+ bool setRadius( double r)
+ { if( r >= 0) { a = r; b = r; return true; }
+ else return false;
+ }
+ string toString() const
+ {
+ stringstream sstream;
+ sstream << "Kreis-Mittelpunkt: " << anchor.toString()
+ << " Radius: " << a;
+ return sstream.str();
+ }
+ Shape* clone() const { return new Circle( *this ); }
+};
+
+#endif
diff --git a/Bachelor/Prog2/Z-Uebung/Teil4/shapeList.h b/Bachelor/Prog2/Z-Uebung/Teil4/shapeList.h
new file mode 100644
index 0000000..2a4698f
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Teil4/shapeList.h
@@ -0,0 +1,89 @@
+// shapeList.h
+// Definition of classes ShapePtr and ShapePtrList
+// inhomogeneous list for Shape-Objects
+
+#ifndef SHAPELIST_H
+#define SHAPELIST_H
+
+#include <iostream>
+using std::cerr;
+using std::left;
+
+#include <cstdlib> // exit()
+#include <list> // class-Template list< T >
+ // T is type of list elements
+#include "shape.h"
+
+class ShapePtr
+{
+private:
+ Shape* ptr;
+public:
+ ShapePtr( Shape* p = NULL ) : ptr( p ) { } // constructors
+ ShapePtr( const ShapePtr& sp ) { ptr = sp->clone(); }
+
+ ~ShapePtr() { delete ptr; } // destructor
+
+ ShapePtr& operator=( Shape* p ) // assignments
+ {
+ delete ptr;
+ ptr = p->clone();
+ return *this;
+ }
+
+ ShapePtr& operator=( ShapePtr& a )
+ {
+ delete ptr;
+ ptr = a->clone();
+ return *this;
+ }
+
+ Shape& operator*() const // dereferencing
+ {
+ if( !ptr ) {
+ cerr << "ShapePtr::operator* : Kein Objekt!" << endl;
+ exit( 100 );
+ }
+ return *ptr;
+ }
+
+ Shape* operator->() const // member selection via pointer
+ {
+ if( !ptr ) {
+ cerr << "ShapePtr::operator-> : Kein Objekt!" << endl;
+ exit( 101 );
+ }
+ return ptr;
+ }
+
+ operator Shape*() const { return ptr; } // cast
+};
+
+class ShapePtrList : public std::list< ShapePtr >
+{
+public:
+ void scale( double scalingFactor )
+ {
+ ShapePtrList::iterator pos;
+ for( pos = begin(); pos != end(); ++pos )
+ ( *pos )->scale( scalingFactor );
+ }
+
+ string toString() const
+ {
+ stringstream sstream;
+ if( empty() )
+ sstream << "Die Liste ist leer!";
+ else {
+ ShapePtrList::const_iterator pos;
+ for( pos = begin(); pos != end(); ++pos ) {
+ sstream.width( 20 );
+ sstream << left << typeid( **pos ).name();
+ sstream << ( *pos )->toString() << endl;
+ }
+ }
+ return sstream.str();
+ }
+};
+
+#endif \ No newline at end of file
diff --git a/Bachelor/Prog2/Z-Uebung/Z-Uebung.htm b/Bachelor/Prog2/Z-Uebung/Z-Uebung.htm
new file mode 100644
index 0000000..0790d88
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Z-Uebung.htm
@@ -0,0 +1,330 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="Author" content="Hans-Peter Weber">
+ <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+ <title>Klausur SS 04</title>
+</head>
+<body>
+&nbsp;
+<table BORDER WIDTH="100%" >
+<tr>
+<td WIDTH="25%" BGCOLOR="#EFEFDE">FH Darmstadt&nbsp;
+<br>FB Informatik
+<p>Prof.Dr.H.P.Weber</td>
+
+<td>
+<p align="center">
+<center><font size=+3>Programmieren II</font></center>
+<br>
+<center><font size="+3">Übung</font></center>
+</td>
+
+<td WIDTH="25%" BGCOLOR="#EFEFDE">
+<center>
+<p><font size="6">&nbsp;&nbsp;&nbsp; </font><font size="5">Juni 2005</font></p>
+</center>
+</td>
+</tr>
+</table>
+
+<br>
+
+<table>
+<tr VALIGN=TOP>
+<td>Es soll die folgende Klassenhierarchie für zweidimensionale Figuren
+implementiert werden:<br>
+ Abstrakte Basisklasse <b><tt>Shape</tt></b>, davon direkt abgeleitet die
+ Klassen <b><tt>
+Polyline</tt></b> und <b><tt>Ellipse</tt></b>. Von <b><tt>
+Polyline</tt></b> direkt abgeleitet die Klassen <b><tt>L</tt></b><b><tt>ine</tt></b>
+ und <b><tt>Polygon</tt></b> und zusätzlich von <b><tt>Polygon</tt></b>
+ abgeleitet die Klasse <b><tt>Rectangle</tt></b>. Außerdem von <b><tt>Ellipse</tt></b>
+ abgeleitet die Klasse <b><tt>Circle</tt></b>.</td>
+</tr>
+</table>
+
+<br>
+
+<table WIDTH="100%" BGCOLOR="#EFEFDE" >
+<tr>
+<td>Teil 1:</td>
+</tr>
+</table>
+
+<p>Zunächst werden nur die grundlegenden Klassen <b> <tt>Shape</tt></b> und <b> <tt>
+Polyline</tt></b> entwickelt und getestet. Da die Klassen der <b> <tt>Shape</tt></b>-Hierarchie
+mit Punkten arbeiten, wird zur Darstellung eines Punktes auch eine Klasse <b> <tt>
+Point</tt></b> definiert:</p>
+<ul>
+<li>
+Die Klasse <b> <tt>Point</tt></b> besitzt die <b> <tt>public</tt></b>-Elemente <tt> <b>
+x</b></tt> und <b> <tt>y</tt></b> vom Typ <b><tt>double</tt></b> und einen
+entsprechenden Konstruktor mit zwei Parametern, die beide den Default-Wert <tt>
+<b> 0.0</b></tt> haben.<br>
+Die Methode <b> <tt>distance</tt></b> liefert den Abstand zu einem zweiten
+Punkt, der als Argument übergeben wird. Der Abstand von zwei Punkten (x1, y1)
+und (x2, y2) ist die Wurzel aus (x2 - x1)<sup>2</sup> + (y2 - y1)<sup>2</sup> .
+<br>
+Die Methode <b> <tt>toString</tt></b> liefert den Punkt als String in der Form <b> <tt>
+(x, y)</tt></b>.<br>
+Der Operator <b> <tt>*=</tt></b> multipliziert den Punkt mit einer
+Gleitpunktzahl.<br>
+Außerdem werden die folgenden globalen Operationen bereitgestellt:<br>
+<b> <tt>+</tt></b> und <b> <tt>-</tt></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+Liefert die Summe bzw. Differenz zweier Punkte.<br>
+<b> <tt>==</tt></b> und <b> <tt>!=</tt></b>&nbsp;&nbsp;&nbsp; Vergleicht zwei
+Punkte.<br>
+<b> <tt>&lt;&lt;</tt></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+Gibt einen Punkt auf einen Stream aus.</li>
+<li>
+Die <b> <tt>Shape</tt></b>-Klasse enthält ein Attribut <b> <tt>anchor</tt></b> (Anker,
+Bezugspunkt), das die Lage der Figur festlegt. Durch Verschiebung des Ankers
+wird also die gesamte Figur verschoben. Der Anker wird in der <b> <tt>Shape</tt></b>-Klasse
+als <b> <tt>protected</tt></b>-Element gespeichert. Der Konstruktor
+initialisiert den Anker mit dem als Argument übergebenen Punkt oder mit dem
+Default-Wert <b><tt>Point(0,0)</tt></b>. Zugriffsmethoden erlauben das Lesen und
+Setzen des Ankers. Die Verschiebung erfolgt mit der Methode <b><tt>move</tt></b>,
+die zwei Parameter für die Verschiebung in x- und y-Richtung besitzt.</li>
+
+<li>
+Die Klasse <b><tt>Shape</tt></b> ist eine abstrakte Klasse. Neben dem virtuellen
+Destruktor stellt sie das folgende polymorphe Interface bereit: Die Methode <tt><b>toString</b></tt>
+liefert die Daten einer Figur als String. Für die Klasse <b><tt>Shape</tt></b>
+sind das die Koordinaten des Ankers. Außerdem enthält <b><tt>Shape</tt></b>
+die rein virtuellen Methoden <b><tt>scale</tt></b> und <b><tt>draw</tt></b>. <b><tt>scale</tt></b>
+verkleinert oder vergrößert die Figur um einen Faktor, der als Argumnet
+übergeben wird. Die Methode <b><tt>draw</tt></b> wird zum Zeichnen einer Figur
+bereitgestellt, aber nicht genutzt (d.h. leer implementiert).</li>
+
+<li>
+Die Klasse <b> <tt>Polyline</tt></b> stellt einen Linienzug dar. Beispielsweise
+besteht folgender Linienzug : Anker - E1 - E2 - E3 - E4 aus vier Linien mit den Endpunkten E1 bis E4. Die Endpunkte werden relativ zum
+Anker in einem dynamisch erzeugten Array gespeichert. Entsprechend besitzt die
+Klasse <b><tt>Polyline</tt></b> zwei Datenelemente: Ein dynamisches Element,
+nämlich einen Zeiger auf das Array mit <b> <tt>Point</tt></b>-Elementen, und
+eine Variable für die Anzahl der Linien. Definieren Sie verschiedene
+Konstruktoren: Einen Default-Konstruktor, einen Konstruktor mit einem <b> <tt>Point</tt></b>-Parameter
+zur Festlegung des Ankers, einen Konstruktor mit zwei <b> <tt>Point</tt></b>-Parametern
+für eine Linie und einen Konstruktor, dem ein Array mit den Punkten eines
+Linienzuges und die Anzahl der Punkte übergeben werden. Jeder Konstruktor setzt
+den Zeiger und die Anzahl der Linien auf <b><tt>0</tt></b>, wenn das Objekt noch
+keine Linie enthält. Andernfalls erzeugt der Konstruktor dynamisch das Array für
+die Endpunkte gemäß der aktuellen Anzahl Linien. Für jeden Endpunkt wird
+die Differenz zum Anker gespeichert. Das dynamische Array wird vom Destruktor
+wieder freigegeben. Da die Klasse <b><tt>Polyline</tt></b> ein dynamisches
+Element besitzt müssen auch Kopierkonstruktor und Zuweisungsoperator definiert
+werden.</li>
+
+<li>
+Redefinieren Sie für die Klasse <b><tt>Polyline</tt></b> alle rein virtuellen
+Methoden der Klasse <b><tt>Shape</tt></b> und die Methode <tt><b>toString</b></tt>, die
+die Koordinaten der Eckpunkte als String liefert.
+Stellen Sie ferner eine Methode bereit, die die Anzahl Linien im Polygon
+zurückgibt, und eine Methode, die die Gesamtlänge liefert.</li>
+
+<li>
+
+Überladen Sie schließlich zweimal den <b><tt>operator+=</tt></b>: Ist das
+Argument ein Punkt, soll eine weitere Linie zu diesem Punkt angehängt werden.
+Ist das Argument ein <b><tt>Polyline</tt></b>-Objekt, soll dessen gesamter
+Linienzug an den letzten Punkt angehängt werden.
+<ul>
+<li>
+Wenn eine Linie angehängt wird, muss das Array mit den Endpunkten vergrößert
+werden.
+</li>
+<li>
+Zu den relativen Koordinaten des anzuhängenden Linienzugs müssen die relativen
+Koordinaten des letzten Punktes addiert werde.
+</li>
+</ul>
+Testen Sie die Klasse <b><tt>Polyline</tt></b>, indem Sie mit jedem zur
+Verfügung stehenden Konstruktor ein Objekt erzeugen und sich anzeigen lassen.
+Rufen Sie dann jede Methode der Klasse mindestens einmal auf.</li>
+
+</ul>
+
+<table WIDTH="100%" BGCOLOR="#EFEFDE" >
+<tr>
+<td>Teil 2:</td>
+</tr>
+</table>
+
+<p>Ergänzen Sie die <b> <tt>Shape</tt></b>-Klassenhierarchie um die noch
+fehlenden Klassen <b><tt>Line</tt></b>, <b><tt>Polygon</tt></b>, <b><tt>Rectangle</tt></b>,
+<b><tt>Ellipse</tt></b> und <b><tt>Circle</tt></b>:</p>
+<ul>
+<li>
+Die Klasse <b><tt>Line</tt></b> besitzt mindestens zwei Konstruktoren: Die
+Endpunkte einer Linie sollen als zwei <b><tt>Point</tt></b>-Objekte oder direkt
+in x-, y-Koordinaten angegeben werden können. Die Redefinition von geerbten
+Methoden ist nicht notwendig. Allerdings soll es nicht möglich sein, an eine
+Linie einen weiteren Punkt oder einen Linienzug anzuhängen!</li>
+<li>
+Ein <b><tt>Polygon</tt></b> wird als geschlossener Linienzug betrachtet: Die Linie vom letzten
+Punkt zum ersten Punkt (=Anker) gehört logisch zur Figur. Entsprechend müssen
+die Methoden redefiniert werden, die die Anzahl Linien bzw. die Gesamtlänge
+zurückgeben. Stellen Sie zusätzlich Methoden bereit, die die Anzahl Ecken (=
+Anzahl Linien) und den Umfang (=Gesamtlänge) liefern:</li>
+<li>
+Die Klasse <b><tt>Rectangle</tt></b> beschreibt Vierecke mit der linken unteren
+Ecke als Anker, deren Seiten parallel zu den x- und y-Koordinaten verlaufen.
+Definieren Sie zuerst einen Konstruktor, dem der Anker sowie die Breite und
+Höhe des Rechtecks übergeben wird. Ein zweiter Konstruktor erzeugt ein
+Rechteck aus zwei Punkten, nämlich der linken unteren Ecke und der rechten
+oberen Ecke. Stellen Sie Methoden bereit, die die Höhe und Breite des Rechtecks
+liefern. Auch für Rechtecke soll es nicht möglich sein, einen weiteren Punkt
+oder einen Linienzug anzuhängen.</li>
+
+<li>
+Definieren Sie schließlich die Klassen <b><tt>Ellipse</tt></b> und <b><tt>Circle</tt></b>.
+Eine Ellipse wird durch den Mittelpunkt und die beiden Halbachsen a und b
+beschrieben. Der Mittelpunkt ist der Anker der Figur. Neben einem Konstruktor
+und den Zugriffsmethoden für die Halbachsen soll auch eine Methode definiert
+werden, die den Umfang der Ellipse liefert (Verwenden Sie zur Berechnung des
+Umfangs einer Ellipse die Näherungsformel U = PI * ( 3/2*(a+b) - sqrt(a*b) )
+wobei PI = 3.14159). Außerdem müssen die geerbten Methoden <b><tt>scale</tt></b>
+und <b><tt>toString</tt></b> redefiniert werden.</li>
+
+<li>
+Ein Kreis ist eine Ellipse, deren Halbachsen gleich lang sind und den Radius des
+Kreises bilden. Außer einem Konstruktor soll die Klasse <b><tt>Circle</tt></b>
+zusätzlich die Methoden <b><tt>getRadius</tt></b> und <b><tt>setRadius</tt></b>
+bereitstellen. Auch ist die Methode <b><tt>toString</tt></b> zu redefinieren.</li>
+
+<li>
+
+Erweitern Sie das Anwendungsprogramm aus Teil 1 so, dass auch die neuen Klassen
+getestet werden.
+</li>
+
+</ul>
+
+
+<table WIDTH="100%" BGCOLOR="#EFEFDE" >
+<tr>
+<td>Teil 3:</td>
+</tr>
+</table>
+
+<p>Die Figuren eines 'Bildes' bestehend aus Objekten der <b> <tt>Shape</tt></b>-Hierarchie
+werden in einer verketteten Liste verwaltet und in der Reihenfolge 'gezeichnet',
+wie sie in der Liste vorkommen. Dazu soll <b><tt>std::list</tt></b> aus der STL
+verwendet werden:</p>
+
+<ul>
+<li>
+Zur Realisierung einer inhomogenen Liste werden nicht die Objekte selbst sondern
+<tt><b>Shape</b></tt>-Zeiger in der&nbsp;Liste gespeichert. Dem Listentyp soll
+daher der Name <b><tt>ShapePtrList</tt></b> mittels <b><tt>typedef</tt></b>
+zugewiesen werden. Danach können Objekte dieses Typs angelegt und die in <b><tt>std::list</tt></b>
+vorhandenen Methoden aufgerufen werden, z.B. wird mit <b><tt>push_back</tt></b>
+ein <tt><b>Shape*</b></tt> auf ein zuvor erzeugtes Objekt der <tt><b>Shape</b></tt>-Hierarchie
+an die Liste angehängt.</li>
+<li>
+Schreiben Sie ein Anwendungsprogramm, das Zeiger auf verschiedene Objekte der <tt><b>Shape</b></tt>-Hierarchie
+in eine Liste vom Typ <b><tt>ShapePtrList</tt></b> einfügt. Die Objekte sollen
+mit <tt><b>new</b></tt> dynamisch erzeugt werden. Geben Sie die <tt><b>Shape</b></tt>-Objekte
+der Liste aus. Löschen Sie dann einige Elemente und zeigen Sie die Liste erneut
+an. Schreiben Sie zur Ausgabe der <tt><b>Shape</b></tt>-Objekte eine globale
+Funktion <b><tt>printShapeList</tt></b>, die als Argument eine Referenz auf die
+Liste erhält und mithilfe der Methoden <b><tt>t</tt></b><b><tt>oString</tt></b>
+die <tt><b>Shape</b></tt>-Objekte der Liste anzeigt. Geben Sie zusätzlich mit
+dem Operator <b><tt>type</tt></b><b><tt>id</tt></b> auch den Typ der Objekte
+aus.</li>
+</ul>
+
+<table WIDTH="100%" BGCOLOR="#EFEFDE" >
+<tr>
+<td>Teil 4:</td>
+</tr>
+</table>
+
+<p>Die Klasse <b><tt>ShapePtrList</tt></b> wird noch in zwei Schritten
+verbessert:</p>
+
+<ul>
+<li>
+Bisher speichert jedes Listenelement einen einfachen <tt><b>Shape</b></tt>-Zeiger.
+Deshalb wird beim Löschen eines Listenelements nur der Zeiger nicht aber das <tt><b>Shape</b></tt>-Objekt
+selbst gelöscht, was zu Speicherlecks führt. Ebenso werden beim Kopieren und
+Zuweisen ganzer Listen nur die Zeiger kopiert ('flache Kopie'), was gravierende
+Laufzeitfehler verursachen kann. Daher sollen die Zeiger durch 'intelligente
+Zeiger (smart pointer)' ersetzt werden, die z.B. das adressierte Objekt
+zerstören, wenn sie selbst zerstört werden. Gehen Sie dazu wie folgt vor:</li>
+<ul>
+<li>
+Ergänzen Sie zuerst die <tt><b>Shape</b></tt>-Klasse durch eine rein virtuelle
+Methode <tt><b>clone</b></tt>. Diese Methode muss in jeder abgeleiteten Klasse
+redefiniert werden, indem sie eine dynamisch erzeugte Kopie des aktuellen
+Objekts zurückgibt.</li>
+<li>
+Definieren Sie dann die Klasse <b><tt>ShapePtr</tt></b> zur Darstellung eines
+intelligenten Zeigers auf <tt><b>Shape</b></tt>-Objekte. Als Attribut besitzt
+die Klasse einen <tt><b>Shape</b></tt>-Zeiger, der vom Konstruktor mit dem
+Parameter vom Typ <tt><b>Shape*</b></tt> bzw. dem Default-Wert 0 initialisiert
+wird. Außerdem muss ein eigener Kopierkonstruktor definiert werden. Dieser
+erzeugt zunächst mithilfe der Methode <tt><b>clone</b></tt> eine Kopie des <tt><b>Shape</b></tt>-Objekts
+und läßt den <tt><b>Shape</b></tt>-Zeiger auf diese Kopie zeigen. Der
+Destruktor zerstört das <tt><b>Shape</b></tt>-Objekt, auf das der Zeiger
+verweist. Der Zuweisungsoperator wird zweifach überladen, so dass sowohl ein
+anderes <tt><b>ShapePtr</b></tt>-Objekt als auch ein einfacher <tt><b>Shape</b></tt>-Zeiger
+zugewiesen werden kann. In beiden Fällen wird das aktuelle <tt><b>Shape</b></tt>-Objekt
+zerstört und der Zeiger auf eine Kopie des <tt><b>Shape</b></tt>-Objekts
+gesetzt, auf das der übergebene Zeiger verweist. Die Operatoren <tt><b>*</b></tt>
+und <tt><b>-&gt;</b></tt> sind so zu überladen, dass ein <tt><b>ShapePtr</b></tt>-Objekt
+wie ein gewöhnlicher Zeiger verwendet werden kann. Der
+Dereferenzierungsoperator liefert eine Referenz auf das adressierte <tt><b>Shape</b></tt>-Objekt
+und der Pfeiloperator liefert den <tt><b>Shape</b></tt>-Zeiger selbst.
+Schließlich soll auch eine Konvertierung eines <tt><b>ShapePtr</b></tt>-Objekts
+in einen <tt><b>Shape</b></tt>-Zeiger möglich sein. Fügen Sie deshalb noch die
+entsprechende Konvertierungsfunktion hinzu.</li>
+</ul>
+Die Definition der Liste mit Zeiger auf <tt><b>Shape</b></tt>-Objekte lautet nun
+wie folgt:<br>
+<tt><b>typedef List&lt; ShapePtr &gt; ShapePtrList;<br>
+</b></tt>Stellen Sie die Definitionen der Klassen <tt><b>ShapePtr</b></tt> und <tt><b>ShapePtrList</b></tt>
+in eine neue Header-Datei <tt><b>ShapeList.h</b></tt>. Verwenden Sie zum Testen
+die Funktionen <tt><b>main</b></tt> und <tt><b>printShapeList</b></tt> aus Teil
+3. Diese sollten unverändert mit der neuen Definition der Liste lauffähig
+sein.
+<li>
+Um die Klasse <tt><b>ShapePtrList</b></tt> mit eigenen Methoden erweitern zu
+können, wird jetzt die Klasse <tt><b>ShapePtrList</b></tt> von der
+Standardklasse <tt><b>std::list</b></tt> abgeleitet:<br>
+<tt><b>class ShapePtrList : public list&lt; ShapePtr &gt;<br>
+</b></tt>Ergänzen Sie die Klasse <tt><b>ShapePtrList</b></tt> durch die
+Methoden <tt><b>scale</b></tt> und <tt><b>toString</b></tt>. Die Methode <tt><b>scale</b></tt>
+verkleinert oder vergrößert jede Figur der Liste um einen Faktor, der als
+Argument übergeben wird. Die Methode <tt><b>toString</b></tt> liefert einen
+String mit dem Inhalt der Liste: Für jede Figur der Liste wird in einer neuen
+Zeile zuerst der Typname der Figur in den String geschrieben und dann das
+Ergebnis der Aufrufes der <tt><b>toString</b></tt>-Methode für die jeweilige
+Figur.
+</li>
+</ul>
+Testen Sie die verbesserte Klasse
+<tt><b> ShapePtrList</b></tt>. Ändern Sie die&nbsp; <tt><b>main</b></tt>-Funktion
+aus Teil 3 wie folgt: Entfernen Sie die globale Funktion <tt><b>printShapeList</b></tt>
+und verwenden Sie zur Ausgabe der Liste die Methode <tt><b>toString</b></tt>.
+Erzeugen Sie eine Kopie der Liste und modifizieren Sie die Figuren der neuen
+Liste durch einen Aufruf der Methode <tt><b>scale</b></tt>. Nur die Figuren der
+neuen Liste dürfen sich dadurch verändern. Testen Sie auch die Zuweisung
+ganzer Listen. Den Aufruf der Destruktoren können Sie sichtbar&nbsp; machen,
+indem Sie im virtuellen Destruktor der Klasse <tt><b>Shape</b></tt> eine
+Meldung ausgeben.
+<br>
+
+<table>
+<tr>
+<td COLSPAN = 2>
+<hr width="100%">
+<font size=-1>Quelle: Prinz / Kirch-Prinz: C++ Das Übungsbuch</font>
+<br>
+</td>
+</tr>
+</table>
+
+</body> \ No newline at end of file
diff --git a/Bachelor/Prog2/Z-Uebung/Z_Ueb.zip b/Bachelor/Prog2/Z-Uebung/Z_Ueb.zip
new file mode 100644
index 0000000..9da9e07
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Z_Ueb.zip
Binary files differ
diff --git a/Bachelor/Prog2/Z-Uebung/Z_Uebung.dsw b/Bachelor/Prog2/Z-Uebung/Z_Uebung.dsw
new file mode 100644
index 0000000..566fddd
--- /dev/null
+++ b/Bachelor/Prog2/Z-Uebung/Z_Uebung.dsw
@@ -0,0 +1,65 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "Teil1"=".\Teil1\Teil1.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "Teil2"=".\Teil2\Teil2.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "Teil3"=".\Teil3\Teil3.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "Teil4"=".\Teil4\Teil4.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+