summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp
blob: d677b0981cc5faae2d0f4a467854d7203b3eee0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;

}