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/20050401.jpg | Bin 0 -> 229161 bytes .../1_ch09/Fig09_10_11/CircleTest/circle2.cpp | 74 +++++ .../1_ch09/Fig09_10_11/CircleTest/circle2.h | 44 +++ .../1_ch09/Fig09_10_11/CircleTest/point.cpp | 65 ++++ .../1_ch09/Fig09_10_11/CircleTest/point.h | 40 +++ .../1_ch09/Fig09_12_16/CircleTest3/circle3.cpp | 74 +++++ .../1_ch09/Fig09_12_16/CircleTest3/circle3.h | 44 +++ .../1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp | 63 ++++ .../1_ch09/Fig09_12_16/CircleTest3/point2.cpp | 65 ++++ .../1_ch09/Fig09_12_16/CircleTest3/point2.h | 40 +++ .../ConstructorsAndDestructors/circle5.cpp | 88 ++++++ .../ConstructorsAndDestructors/circle5.h | 45 +++ .../ConstructorsAndDestructors/fig09_29.cpp | 44 +++ .../ConstructorsAndDestructors/point4.cpp | 77 +++++ .../ConstructorsAndDestructors/point4.h | 41 +++ .../elevatorinheritance/ElevatorSimulation.cpp | 45 +++ .../1_ch09/elevatorinheritance/bell.cpp | 44 +++ .../1_ch09/elevatorinheritance/bell.h | 30 ++ .../1_ch09/elevatorinheritance/building.cpp | 65 ++++ .../1_ch09/elevatorinheritance/building.h | 42 +++ .../1_ch09/elevatorinheritance/button.cpp | 52 ++++ .../1_ch09/elevatorinheritance/button.h | 41 +++ .../1_ch09/elevatorinheritance/clock.cpp | 52 ++++ .../1_ch09/elevatorinheritance/clock.h | 34 +++ .../1_ch09/elevatorinheritance/door.cpp | 81 +++++ .../1_ch09/elevatorinheritance/door.h | 40 +++ .../1_ch09/elevatorinheritance/elevator.cpp | 231 ++++++++++++++ .../1_ch09/elevatorinheritance/elevator.h | 75 +++++ .../1_ch09/elevatorinheritance/elevatorButton.cpp | 49 +++ .../1_ch09/elevatorinheritance/elevatorButton.h | 32 ++ .../1_ch09/elevatorinheritance/floor.cpp | 98 ++++++ .../1_ch09/elevatorinheritance/floor.h | 63 ++++ .../1_ch09/elevatorinheritance/floorButton.cpp | 54 ++++ .../1_ch09/elevatorinheritance/floorButton.h | 35 +++ .../1_ch09/elevatorinheritance/light.cpp | 64 ++++ .../1_ch09/elevatorinheritance/light.h | 35 +++ .../1_ch09/elevatorinheritance/person.cpp | 91 ++++++ .../1_ch09/elevatorinheritance/person.h | 42 +++ .../1_ch09/elevatorinheritance/scheduler.cpp | 133 +++++++++ .../1_ch09/elevatorinheritance/scheduler.h | 53 ++++ .../1_ch09/fig09_04_06/PointTest/point.cpp | 65 ++++ .../1_ch09/fig09_04_06/PointTest/point.h | 40 +++ .../1_ch09/fig09_04_06/PointTest/pointtest.cpp | 43 +++ .../1_ch09/fig09_07_09/CircleTest/circle.cpp | 102 +++++++ .../1_ch09/fig09_07_09/CircleTest/circle.h | 50 ++++ .../1_ch09/fig09_07_09/CircleTest/circletest.cpp | 63 ++++ .../1_ch09/fig09_17_21/CircleTest4/circle4.cpp | 74 +++++ .../1_ch09/fig09_17_21/CircleTest4/circle4.h | 44 +++ .../1_ch09/fig09_17_21/CircleTest4/circletest4.cpp | 63 ++++ .../1_ch09/fig09_17_21/CircleTest4/point3.cpp | 65 ++++ .../1_ch09/fig09_17_21/CircleTest4/point3.h | 40 +++ .../1_ch09/fig09_22_24/CylinderTest/circle4.cpp | 74 +++++ .../1_ch09/fig09_22_24/CylinderTest/circle4.h | 44 +++ .../1_ch09/fig09_22_24/CylinderTest/cylinder.cpp | 68 +++++ .../1_ch09/fig09_22_24/CylinderTest/cylinder.h | 42 +++ .../fig09_22_24/CylinderTest/cylindertest.cpp | 70 +++++ .../1_ch09/fig09_22_24/CylinderTest/point3.cpp | 65 ++++ .../1_ch09/fig09_22_24/CylinderTest/point3.h | 40 +++ .../Codebeispiele/2_ch10/fig10_01_05/Fig10_05.cpp | 75 +++++ .../Codebeispiele/2_ch10/fig10_01_05/circle.cpp | 74 +++++ .../Codebeispiele/2_ch10/fig10_01_05/circle.h | 44 +++ .../Codebeispiele/2_ch10/fig10_01_05/point.cpp | 65 ++++ .../Prog2/Codebeispiele/2_ch10/fig10_01_05/point.h | 40 +++ .../Codebeispiele/2_ch10/fig10_06/Fig10_06.cpp | 31 ++ .../Prog2/Codebeispiele/2_ch10/fig10_06/circle.cpp | 74 +++++ .../Prog2/Codebeispiele/2_ch10/fig10_06/circle.h | 44 +++ .../Prog2/Codebeispiele/2_ch10/fig10_06/point.cpp | 65 ++++ .../Prog2/Codebeispiele/2_ch10/fig10_06/point.h | 40 +++ .../Prog2/Codebeispiele/2_ch10/fig10_07/circle.cpp | 74 +++++ .../Prog2/Codebeispiele/2_ch10/fig10_07/circle.h | 44 +++ .../Codebeispiele/2_ch10/fig10_07/fig10_07.cpp | 48 +++ .../Prog2/Codebeispiele/2_ch10/fig10_07/point.cpp | 65 ++++ .../Prog2/Codebeispiele/2_ch10/fig10_07/point.h | 40 +++ .../Codebeispiele/2_ch10/fig10_08_12/Fig10_10.cpp | 80 +++++ .../Codebeispiele/2_ch10/fig10_08_12/circle.cpp | 74 +++++ .../Codebeispiele/2_ch10/fig10_08_12/circle.h | 44 +++ .../Codebeispiele/2_ch10/fig10_08_12/point.cpp | 65 ++++ .../Prog2/Codebeispiele/2_ch10/fig10_08_12/point.h | 40 +++ .../Codebeispiele/2_ch10/fig10_13_20/Fig10_20.cpp | 120 ++++++++ .../Codebeispiele/2_ch10/fig10_13_20/circle.cpp | 81 +++++ .../Codebeispiele/2_ch10/fig10_13_20/circle.h | 47 +++ .../Codebeispiele/2_ch10/fig10_13_20/cylinder.cpp | 75 +++++ .../Codebeispiele/2_ch10/fig10_13_20/cylinder.h | 46 +++ .../Codebeispiele/2_ch10/fig10_13_20/point.cpp | 72 +++++ .../Prog2/Codebeispiele/2_ch10/fig10_13_20/point.h | 45 +++ .../Codebeispiele/2_ch10/fig10_13_20/shape.cpp | 36 +++ .../Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.h | 41 +++ .../Codebeispiele/2_ch10/fig10_23_33/baseplus.cpp | 65 ++++ .../Codebeispiele/2_ch10/fig10_23_33/baseplus.h | 40 +++ .../2_ch10/fig10_23_33/commission.cpp | 76 +++++ .../Codebeispiele/2_ch10/fig10_23_33/commission.h | 44 +++ .../Codebeispiele/2_ch10/fig10_23_33/employee.cpp | 86 ++++++ .../Codebeispiele/2_ch10/fig10_23_33/employee.h | 50 ++++ .../Codebeispiele/2_ch10/fig10_23_33/fig10_33.cpp | 100 +++++++ .../Codebeispiele/2_ch10/fig10_23_33/hourly.cpp | 80 +++++ .../Codebeispiele/2_ch10/fig10_23_33/hourly.h | 44 +++ .../Codebeispiele/2_ch10/fig10_23_33/salaried.cpp | 61 ++++ .../Codebeispiele/2_ch10/fig10_23_33/salaried.h | 40 +++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_01.CPP | 68 +++++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_02.CPP | 97 ++++++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_03.CPP | 38 +++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_04.CPP | 43 +++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_05.CPP | 75 +++++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_06.CPP | 71 +++++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_07.CPP | 69 +++++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_08.CPP | 50 ++++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_09.CPP | 57 ++++ Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_10.CPP | 44 +++ Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_11.cpp | 59 ++++ Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_12.cpp | 65 ++++ Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_04.cpp | 61 ++++ Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_07.cpp | 78 +++++ Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_08.cpp | 163 ++++++++++ Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_12.cpp | 53 ++++ Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_13.cpp | 94 ++++++ Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_14.cpp | 91 ++++++ Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_15.cpp | 331 +++++++++++++++++++++ Bachelor/Prog2/Codebeispiele/4_ch14/clientData.cpp | 105 +++++++ Bachelor/Prog2/Codebeispiele/4_ch14/clientData.h | 56 ++++ Bachelor/Prog2/Codebeispiele/5_ch11/Tstack1.h | 98 ++++++ Bachelor/Prog2/Codebeispiele/5_ch11/fig11_01.cpp | 59 ++++ Bachelor/Prog2/Codebeispiele/5_ch11/fig11_03.cpp | 67 +++++ Bachelor/Prog2/Codebeispiele/5_ch11/fig11_04.cpp | 63 ++++ .../Codebeispiele/6_ch17/fig17_03_05/fig17_05.cpp | 105 +++++++ .../Prog2/Codebeispiele/6_ch17/fig17_03_05/list.h | 216 ++++++++++++++ .../Codebeispiele/6_ch17/fig17_03_05/listnode.h | 56 ++++ .../Codebeispiele/6_ch17/fig17_10_11/fig17_11.cpp | 72 +++++ .../Prog2/Codebeispiele/6_ch17/fig17_10_11/list.h | 216 ++++++++++++++ .../Codebeispiele/6_ch17/fig17_10_11/listnode.h | 56 ++++ .../Prog2/Codebeispiele/6_ch17/fig17_10_11/stack.h | 57 ++++ .../Codebeispiele/6_ch17/fig17_12/fig17_12test.cpp | 69 +++++ .../Prog2/Codebeispiele/6_ch17/fig17_12/list.h | 216 ++++++++++++++ .../Prog2/Codebeispiele/6_ch17/fig17_12/listnode.h | 56 ++++ .../6_ch17/fig17_12/stackcomposition.h | 62 ++++ .../Codebeispiele/6_ch17/fig17_13_14/fig17_14.cpp | 72 +++++ .../Prog2/Codebeispiele/6_ch17/fig17_13_14/list.h | 216 ++++++++++++++ .../Codebeispiele/6_ch17/fig17_13_14/listnode.h | 56 ++++ .../Prog2/Codebeispiele/6_ch17/fig17_13_14/queue.h | 57 ++++ .../6_ch17/fig17_13_14/queuecomposition.h | 59 ++++ .../Prog2/Codebeispiele/6_ch17/fig17_17_19/Tree.h | 159 ++++++++++ .../Codebeispiele/6_ch17/fig17_17_19/Treenode.h | 54 ++++ .../Codebeispiele/6_ch17/fig17_17_19/fig17_19.cpp | 76 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_05.CPP | 46 +++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_14.CPP | 85 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_15.CPP | 86 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_17.CPP | 145 +++++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_18.CPP | 57 ++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_19.CPP | 90 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_20.CPP | 68 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_21.CPP | 62 ++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_22.CPP | 68 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_23.CPP | 74 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_24.CPP | 46 +++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_25.CPP | 46 +++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_26.CPP | 73 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_27.cpp | 86 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_28.cpp | 102 +++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_29.CPP | 99 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_30.CPP | 116 ++++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_31.CPP | 97 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_32.CPP | 60 ++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_33.CPP | 79 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_34.CPP | 69 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_35.CPP | 94 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_36.CPP | 96 ++++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_37.CPP | 79 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_38.cpp | 38 +++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_40.CPP | 82 +++++ Bachelor/Prog2/Codebeispiele/7_ch21/fig21_42.cpp | 86 ++++++ Bachelor/Prog2/Codebeispiele/8_ch13/Fig13_01.cpp | 89 ++++++ Bachelor/Prog2/Codebeispiele/8_ch13/fig13_02.cpp | 71 +++++ Bachelor/Prog2/Codebeispiele/8_ch13/fig13_03.cpp | 63 ++++ Bachelor/Prog2/Codebeispiele/8_ch13/fig13_04.cpp | 49 +++ Bachelor/Prog2/Codebeispiele/8_ch13/fig13_05.cpp | 54 ++++ Bachelor/Prog2/Codebeispiele/8_ch13/fig13_06.cpp | 53 ++++ Bachelor/Prog2/Codebeispiele/8_ch13/fig13_07.cpp | 86 ++++++ Bachelor/Prog2/Codebeispiele/Student/StudDat.cpp | 35 +++ Bachelor/Prog2/Codebeispiele/Student/Student.cpp | 49 +++ Bachelor/Prog2/Codebeispiele/Student/Student.h | 26 ++ Bachelor/Prog2/Codebeispiele/ex9_21.zip | Bin 0 -> 183012 bytes Bachelor/Prog2/FileIn/Demo.txt | 16 + Bachelor/Prog2/FileIn/FileIn.cpp | 67 +++++ Bachelor/Prog2/Folien/1_chapter09.ppt | Bin 0 -> 376712 bytes Bachelor/Prog2/Folien/2_chapter10.ppt | Bin 0 -> 379206 bytes Bachelor/Prog2/Folien/3_chapter15.ppt | Bin 0 -> 174454 bytes Bachelor/Prog2/Folien/4_chapter14.ppt | Bin 0 -> 318829 bytes Bachelor/Prog2/Folien/5_chapter11.ppt | Bin 0 -> 120340 bytes Bachelor/Prog2/Folien/6_chapter17.ppt | Bin 0 -> 332000 bytes Bachelor/Prog2/Folien/7_chapter21.ppt | Bin 0 -> 558263 bytes Bachelor/Prog2/Folien/8_chapter13.ppt | Bin 0 -> 113643 bytes Bachelor/Prog2/Folien/chap9_21.zip | Bin 0 -> 500316 bytes Bachelor/Prog2/ListIterator/ListIter.cpp | 46 +++ Bachelor/Prog2/ListIterator/list1.h | 248 +++++++++++++++ Bachelor/Prog2/Prakt1/index.htm | 186 ++++++++++++ .../Prakt1/prg2p1/mastermind/Debug/mastermind.ilk | Bin 0 -> 886637 bytes .../Prakt1/prg2p1/mastermind/Debug/mastermind.pch | Bin 0 -> 2040260 bytes .../Prakt1/prg2p1/mastermind/Debug/mastermind.pdb | Bin 0 -> 1363124 bytes .../Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.idb | Bin 0 -> 83028 bytes .../Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.pdb | Bin 0 -> 111517 bytes Bachelor/Prog2/Prakt1/prg2p1/mastermind/main.cpp | 73 +++++ .../Prog2/Prakt1/prg2p1/mastermind/mastermind.cpp | 0 .../Prog2/Prakt1/prg2p1/mastermind/mastermind.dsp | 108 +++++++ .../Prog2/Prakt1/prg2p1/mastermind/mastermind.dsw | 33 ++ .../Prog2/Prakt1/prg2p1/mastermind/mastermind.h | 0 .../Prog2/Prakt1/prg2p1/mastermind/mastermind.ncb | Bin 0 -> 50210 bytes .../Prog2/Prakt1/prg2p1/mastermind/mastermind.opt | Bin 0 -> 54462 bytes .../Prog2/Prakt1/prg2p1/mastermind/mastermind.plg | 33 ++ Bachelor/Prog2/Prakt2/SmartHouse/.cdtbuild | 25 ++ Bachelor/Prog2/Prakt2/SmartHouse/.cdtproject | 18 ++ Bachelor/Prog2/Prakt2/SmartHouse/.project | 19 ++ Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.cpp | 42 +++ Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.h | 26 ++ .../Prog2/Prakt2/SmartHouse/Debug/Coffeemachine.d | 11 + .../Prog2/Prakt2/SmartHouse/Debug/GeneralDevice.d | 8 + Bachelor/Prog2/Prakt2/SmartHouse/Debug/Heating.d | 10 + Bachelor/Prog2/Prakt2/SmartHouse/Debug/Radio.d | 10 + Bachelor/Prog2/Prakt2/SmartHouse/Debug/SmartHouse | Bin 0 -> 847098 bytes Bachelor/Prog2/Prakt2/SmartHouse/Debug/main.d | 15 + Bachelor/Prog2/Prakt2/SmartHouse/Debug/makefile | 30 ++ Bachelor/Prog2/Prakt2/SmartHouse/Debug/objects.mk | 13 + Bachelor/Prog2/Prakt2/SmartHouse/Debug/sources.mk | 16 + Bachelor/Prog2/Prakt2/SmartHouse/Debug/subdir.mk | 48 +++ Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.cpp | 42 +++ Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.h | 28 ++ Bachelor/Prog2/Prakt2/SmartHouse/Heating.cpp | 40 +++ Bachelor/Prog2/Prakt2/SmartHouse/Heating.h | 26 ++ Bachelor/Prog2/Prakt2/SmartHouse/Radio.cpp | 38 +++ Bachelor/Prog2/Prakt2/SmartHouse/Radio.h | 25 ++ Bachelor/Prog2/Prakt2/SmartHouse/main.cpp | 61 ++++ Bachelor/Prog2/Prakt2/SmartHouse/prg2p2_1.zip | Bin 0 -> 3735 bytes Bachelor/Prog2/Prakt2/geomObj/.cdtbuild | 25 ++ Bachelor/Prog2/Prakt2/geomObj/.cdtproject | 18 ++ Bachelor/Prog2/Prakt2/geomObj/.project | 19 ++ Bachelor/Prog2/Prakt2/geomObj/Circle.cpp | 27 ++ Bachelor/Prog2/Prakt2/geomObj/Circle.h | 18 ++ Bachelor/Prog2/Prakt2/geomObj/Debug/Circle.d | 10 + Bachelor/Prog2/Prakt2/geomObj/Debug/Rectangle.d | 10 + Bachelor/Prog2/Prakt2/geomObj/Debug/Shape.d | 8 + Bachelor/Prog2/Prakt2/geomObj/Debug/Square.d | 12 + Bachelor/Prog2/Prakt2/geomObj/Debug/geomObj | Bin 0 -> 197267 bytes Bachelor/Prog2/Prakt2/geomObj/Debug/main.d | 14 + Bachelor/Prog2/Prakt2/geomObj/Debug/makefile | 30 ++ Bachelor/Prog2/Prakt2/geomObj/Debug/objects.mk | 13 + Bachelor/Prog2/Prakt2/geomObj/Debug/sources.mk | 16 + Bachelor/Prog2/Prakt2/geomObj/Debug/subdir.mk | 48 +++ Bachelor/Prog2/Prakt2/geomObj/Rectangle.cpp | 25 ++ Bachelor/Prog2/Prakt2/geomObj/Rectangle.h | 19 ++ Bachelor/Prog2/Prakt2/geomObj/Shape.cpp | 14 + Bachelor/Prog2/Prakt2/geomObj/Shape.h | 14 + Bachelor/Prog2/Prakt2/geomObj/Square.cpp | 25 ++ Bachelor/Prog2/Prakt2/geomObj/Square.h | 18 ++ Bachelor/Prog2/Prakt2/geomObj/geomObj.zip | Bin 0 -> 2665 bytes Bachelor/Prog2/Prakt2/geomObj/main.cpp | 39 +++ Bachelor/Prog2/Prakt3/Aufg1/Debug/Table.obj | Bin 0 -> 175362 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/Team.obj | Bin 0 -> 106039 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/main.obj | Bin 0 -> 184733 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.exe | Bin 0 -> 581700 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.ilk | Bin 0 -> 1056100 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pch | Bin 0 -> 190744 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pdb | Bin 0 -> 1434624 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.idb | Bin 0 -> 107520 bytes Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.pdb | Bin 0 -> 143360 bytes Bachelor/Prog2/Prakt3/Aufg1/Table.cpp | 52 ++++ Bachelor/Prog2/Prakt3/Aufg1/Table.h | 21 ++ Bachelor/Prog2/Prakt3/Aufg1/Team.cpp | 116 ++++++++ Bachelor/Prog2/Prakt3/Aufg1/Team.h | 39 +++ Bachelor/Prog2/Prakt3/Aufg1/main.cpp | 50 ++++ Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsp | 116 ++++++++ Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsw | 33 ++ Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dta | Bin 0 -> 353 bytes Bachelor/Prog2/Prakt3/Aufg1/tabletennis.ncb | Bin 0 -> 58368 bytes Bachelor/Prog2/Prakt3/Aufg1/tabletennis.opt | Bin 0 -> 53760 bytes Bachelor/Prog2/Prakt3/Aufg1/tabletennis.plg | 26 ++ Bachelor/Prog2/Prakt3/Aufg1/tabletennis.txt | 11 + Bachelor/Prog2/Prakt3/Aufg2/tools.dta | Bin 0 -> 4803 bytes Bachelor/Prog2/Prakt3/index.htm | 231 ++++++++++++++ .../Prakt3/index_dateien/AuschnittBinaerdatei.gif | Bin 0 -> 3637 bytes Bachelor/Prog2/Prakt4/Max.txt | 67 +++++ Bachelor/Prog2/Prakt4/aufg1/.cdtbuild | 25 ++ Bachelor/Prog2/Prakt4/aufg1/.cdtproject | 18 ++ Bachelor/Prog2/Prakt4/aufg1/.project | 19 ++ Bachelor/Prog2/Prakt4/aufg1/Debug/aufg1 | Bin 0 -> 190158 bytes Bachelor/Prog2/Prakt4/aufg1/Debug/main.d | 10 + Bachelor/Prog2/Prakt4/aufg1/Debug/makefile | 30 ++ Bachelor/Prog2/Prakt4/aufg1/Debug/objects.mk | 13 + Bachelor/Prog2/Prakt4/aufg1/Debug/sources.mk | 16 + Bachelor/Prog2/Prakt4/aufg1/Debug/subdir.mk | 44 +++ Bachelor/Prog2/Prakt4/aufg1/Tree.h | 130 ++++++++ Bachelor/Prog2/Prakt4/aufg1/Treenode.h | 24 ++ Bachelor/Prog2/Prakt4/aufg1/main.cpp | 47 +++ Bachelor/Prog2/Prakt4/aufg1/max.txt | 67 +++++ Bachelor/Prog2/Prakt4/index.htm | 170 +++++++++++ Bachelor/Prog2/Prakt5/Aufg1/.cdtbuild | 25 ++ Bachelor/Prog2/Prakt5/Aufg1/.cdtproject | 18 ++ Bachelor/Prog2/Prakt5/Aufg1/.project | 19 ++ Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsp | 100 +++++++ Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsw | 29 ++ Bachelor/Prog2/Prakt5/Aufg1/Aufg1.ncb | Bin 0 -> 33792 bytes Bachelor/Prog2/Prakt5/Aufg1/Aufg1.opt | Bin 0 -> 48640 bytes Bachelor/Prog2/Prakt5/Aufg1/Aufg1.plg | 44 +++ Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.exe | Bin 0 -> 666845 bytes Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.pch | Bin 0 -> 2015772 bytes Bachelor/Prog2/Prakt5/Aufg1/Debug/Words.txt | 25 ++ Bachelor/Prog2/Prakt5/Aufg1/Debug/main.d | 5 + Bachelor/Prog2/Prakt5/Aufg1/Debug/makefile | 30 ++ Bachelor/Prog2/Prakt5/Aufg1/Debug/objects.mk | 13 + Bachelor/Prog2/Prakt5/Aufg1/Debug/sources.mk | 16 + Bachelor/Prog2/Prakt5/Aufg1/Debug/subdir.mk | 44 +++ Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.idb | Bin 0 -> 74752 bytes Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.pdb | Bin 0 -> 86016 bytes Bachelor/Prog2/Prakt5/Aufg1/Words.txt | 25 ++ Bachelor/Prog2/Prakt5/Aufg1/main.cpp | 101 +++++++ Bachelor/Prog2/Prakt5/Aufg2/uebklaus.htm | 209 +++++++++++++ Bachelor/Prog2/Prakt5/index.htm | 101 +++++++ Bachelor/Prog2/SortedList/Ref.cpp | 23 ++ Bachelor/Prog2/SortedList/list.h | 266 +++++++++++++++++ Bachelor/Prog2/SortedList/listnode.h | 41 +++ Bachelor/Prog2/SortedList/sortedList1.cpp | 80 +++++ Bachelor/Prog2/SortedList2/Compare.h | 20 ++ Bachelor/Prog2/SortedList2/SL_test.cpp | 75 +++++ Bachelor/Prog2/SortedList2/SortedList.h | 63 ++++ Bachelor/Prog2/Stack/Tst_test.cpp | 50 ++++ Bachelor/Prog2/Stack/Tstack1.h | 53 ++++ Bachelor/Prog2/Studenten/StudDat.cpp | 35 +++ Bachelor/Prog2/Studenten/Student.cpp | 49 +++ Bachelor/Prog2/Studenten/Student.h | 26 ++ Bachelor/Prog2/Z-Uebung/Teil1/Teil1.dsp | 108 +++++++ Bachelor/Prog2/Z-Uebung/Teil1/main1.cpp | 61 ++++ Bachelor/Prog2/Z-Uebung/Teil1/shape.cpp | 114 +++++++ Bachelor/Prog2/Z-Uebung/Teil1/shape.h | 120 ++++++++ Bachelor/Prog2/Z-Uebung/Teil2/Teil2.dsp | 108 +++++++ Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp | 115 +++++++ Bachelor/Prog2/Z-Uebung/Teil2/shape.cpp | 114 +++++++ Bachelor/Prog2/Z-Uebung/Teil2/shape.h | 260 ++++++++++++++++ Bachelor/Prog2/Z-Uebung/Teil3/Teil3.dsp | 108 +++++++ Bachelor/Prog2/Z-Uebung/Teil3/main3.cpp | 77 +++++ Bachelor/Prog2/Z-Uebung/Teil3/shape.cpp | 132 ++++++++ Bachelor/Prog2/Z-Uebung/Teil3/shape.h | 258 ++++++++++++++++ Bachelor/Prog2/Z-Uebung/Teil4/Teil4.dsp | 112 +++++++ Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp | 71 +++++ Bachelor/Prog2/Z-Uebung/Teil4/shape.cpp | 116 ++++++++ Bachelor/Prog2/Z-Uebung/Teil4/shape.h | 265 +++++++++++++++++ Bachelor/Prog2/Z-Uebung/Teil4/shapeList.h | 89 ++++++ Bachelor/Prog2/Z-Uebung/Z-Uebung.htm | 330 ++++++++++++++++++++ Bachelor/Prog2/Z-Uebung/Z_Ueb.zip | Bin 0 -> 21843 bytes Bachelor/Prog2/Z-Uebung/Z_Uebung.dsw | 65 ++++ Bachelor/Prog2/map/map.cpp | 65 ++++ Bachelor/Prog2/person-tree/Person.cpp | 31 ++ Bachelor/Prog2/person-tree/Person.h | 27 ++ Bachelor/Prog2/person-tree/Prs_test.cpp | 68 +++++ Bachelor/Prog2/person-tree/Tree.h | 130 ++++++++ Bachelor/Prog2/person-tree/Treenode.h | 24 ++ Bachelor/Prog2/person-tree/main.cpp | 47 +++ Bachelor/Prog2/person-tree/max.txt | 67 +++++ 354 files changed, 20326 insertions(+) create mode 100644 Bachelor/Prog2/20050401.jpg create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/fig09_29.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/pointtest.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circletest.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circletest4.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.h create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylindertest.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/Fig10_05.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/Fig10_06.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/fig10_07.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/Fig10_10.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/Fig10_20.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/fig10_33.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.h create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.h create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_01.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_02.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_03.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_04.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_05.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_06.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_07.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_08.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_09.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_10.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_11.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_12.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_04.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_07.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_08.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_12.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_13.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_14.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_15.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/clientData.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/4_ch14/clientData.h create mode 100644 Bachelor/Prog2/Codebeispiele/5_ch11/Tstack1.h create mode 100644 Bachelor/Prog2/Codebeispiele/5_ch11/fig11_01.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/5_ch11/fig11_03.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/5_ch11/fig11_04.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/fig17_05.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/list.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/listnode.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/fig17_11.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/list.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/listnode.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/stack.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/fig17_12test.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/list.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/listnode.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/stackcomposition.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/fig17_14.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/list.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/listnode.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queue.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queuecomposition.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Tree.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Treenode.h create mode 100644 Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/fig17_19.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_05.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_14.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_15.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_17.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_18.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_19.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_20.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_21.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_22.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_23.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_24.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_25.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_26.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_27.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_28.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_29.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_30.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_31.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_32.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_33.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_34.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_35.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_36.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_37.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_38.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_40.CPP create mode 100644 Bachelor/Prog2/Codebeispiele/7_ch21/fig21_42.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/8_ch13/Fig13_01.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/8_ch13/fig13_02.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/8_ch13/fig13_03.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/8_ch13/fig13_04.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/8_ch13/fig13_05.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/8_ch13/fig13_06.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/8_ch13/fig13_07.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/Student/StudDat.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/Student/Student.cpp create mode 100644 Bachelor/Prog2/Codebeispiele/Student/Student.h create mode 100644 Bachelor/Prog2/Codebeispiele/ex9_21.zip create mode 100644 Bachelor/Prog2/FileIn/Demo.txt create mode 100644 Bachelor/Prog2/FileIn/FileIn.cpp create mode 100644 Bachelor/Prog2/Folien/1_chapter09.ppt create mode 100644 Bachelor/Prog2/Folien/2_chapter10.ppt create mode 100644 Bachelor/Prog2/Folien/3_chapter15.ppt create mode 100644 Bachelor/Prog2/Folien/4_chapter14.ppt create mode 100644 Bachelor/Prog2/Folien/5_chapter11.ppt create mode 100644 Bachelor/Prog2/Folien/6_chapter17.ppt create mode 100644 Bachelor/Prog2/Folien/7_chapter21.ppt create mode 100644 Bachelor/Prog2/Folien/8_chapter13.ppt create mode 100644 Bachelor/Prog2/Folien/chap9_21.zip create mode 100644 Bachelor/Prog2/ListIterator/ListIter.cpp create mode 100644 Bachelor/Prog2/ListIterator/list1.h create mode 100644 Bachelor/Prog2/Prakt1/index.htm create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.ilk create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pch create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pdb create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.idb create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.pdb create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/main.cpp create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.cpp create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.dsp create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.dsw create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.h create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.ncb create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.opt create mode 100644 Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.plg create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/.cdtbuild create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/.cdtproject create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/.project create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.cpp create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.h create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/Coffeemachine.d create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/GeneralDevice.d create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/Heating.d create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/Radio.d create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/SmartHouse create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/main.d create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/makefile create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/objects.mk create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/sources.mk create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Debug/subdir.mk create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.cpp create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.h create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Heating.cpp create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Heating.h create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Radio.cpp create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/Radio.h create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/main.cpp create mode 100644 Bachelor/Prog2/Prakt2/SmartHouse/prg2p2_1.zip create mode 100644 Bachelor/Prog2/Prakt2/geomObj/.cdtbuild create mode 100644 Bachelor/Prog2/Prakt2/geomObj/.cdtproject create mode 100644 Bachelor/Prog2/Prakt2/geomObj/.project create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Circle.cpp create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Circle.h create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/Circle.d create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/Rectangle.d create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/Shape.d create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/Square.d create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/geomObj create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/main.d create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/makefile create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/objects.mk create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/sources.mk create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Debug/subdir.mk create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Rectangle.cpp create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Rectangle.h create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Shape.cpp create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Shape.h create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Square.cpp create mode 100644 Bachelor/Prog2/Prakt2/geomObj/Square.h create mode 100644 Bachelor/Prog2/Prakt2/geomObj/geomObj.zip create mode 100644 Bachelor/Prog2/Prakt2/geomObj/main.cpp create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/Table.obj create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/Team.obj create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/main.obj create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.exe create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.ilk create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pch create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pdb create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.idb create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.pdb create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Table.cpp create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Table.h create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Team.cpp create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/Team.h create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/main.cpp create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsp create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsw create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dta create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/tabletennis.ncb create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/tabletennis.opt create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/tabletennis.plg create mode 100644 Bachelor/Prog2/Prakt3/Aufg1/tabletennis.txt create mode 100644 Bachelor/Prog2/Prakt3/Aufg2/tools.dta create mode 100644 Bachelor/Prog2/Prakt3/index.htm create mode 100644 Bachelor/Prog2/Prakt3/index_dateien/AuschnittBinaerdatei.gif create mode 100644 Bachelor/Prog2/Prakt4/Max.txt create mode 100644 Bachelor/Prog2/Prakt4/aufg1/.cdtbuild create mode 100644 Bachelor/Prog2/Prakt4/aufg1/.cdtproject create mode 100644 Bachelor/Prog2/Prakt4/aufg1/.project create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Debug/aufg1 create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Debug/main.d create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Debug/makefile create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Debug/objects.mk create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Debug/sources.mk create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Debug/subdir.mk create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Tree.h create mode 100644 Bachelor/Prog2/Prakt4/aufg1/Treenode.h create mode 100644 Bachelor/Prog2/Prakt4/aufg1/main.cpp create mode 100644 Bachelor/Prog2/Prakt4/aufg1/max.txt create mode 100644 Bachelor/Prog2/Prakt4/index.htm create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/.cdtbuild create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/.cdtproject create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/.project create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsp create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsw create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Aufg1.ncb create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Aufg1.opt create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Aufg1.plg create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.exe create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.pch create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/Words.txt create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/main.d create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/makefile create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/objects.mk create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/sources.mk create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/subdir.mk create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.idb create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.pdb create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/Words.txt create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/main.cpp create mode 100644 Bachelor/Prog2/Prakt5/Aufg2/uebklaus.htm create mode 100644 Bachelor/Prog2/Prakt5/index.htm create mode 100644 Bachelor/Prog2/SortedList/Ref.cpp create mode 100644 Bachelor/Prog2/SortedList/list.h create mode 100644 Bachelor/Prog2/SortedList/listnode.h create mode 100644 Bachelor/Prog2/SortedList/sortedList1.cpp create mode 100644 Bachelor/Prog2/SortedList2/Compare.h create mode 100644 Bachelor/Prog2/SortedList2/SL_test.cpp create mode 100644 Bachelor/Prog2/SortedList2/SortedList.h create mode 100644 Bachelor/Prog2/Stack/Tst_test.cpp create mode 100644 Bachelor/Prog2/Stack/Tstack1.h create mode 100644 Bachelor/Prog2/Studenten/StudDat.cpp create mode 100644 Bachelor/Prog2/Studenten/Student.cpp create mode 100644 Bachelor/Prog2/Studenten/Student.h create mode 100644 Bachelor/Prog2/Z-Uebung/Teil1/Teil1.dsp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil1/main1.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil1/shape.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil1/shape.h create mode 100644 Bachelor/Prog2/Z-Uebung/Teil2/Teil2.dsp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil2/main2.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil2/shape.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil2/shape.h create mode 100644 Bachelor/Prog2/Z-Uebung/Teil3/Teil3.dsp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil3/main3.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil3/shape.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil3/shape.h create mode 100644 Bachelor/Prog2/Z-Uebung/Teil4/Teil4.dsp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil4/main4.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil4/shape.cpp create mode 100644 Bachelor/Prog2/Z-Uebung/Teil4/shape.h create mode 100644 Bachelor/Prog2/Z-Uebung/Teil4/shapeList.h create mode 100644 Bachelor/Prog2/Z-Uebung/Z-Uebung.htm create mode 100644 Bachelor/Prog2/Z-Uebung/Z_Ueb.zip create mode 100644 Bachelor/Prog2/Z-Uebung/Z_Uebung.dsw create mode 100644 Bachelor/Prog2/map/map.cpp create mode 100644 Bachelor/Prog2/person-tree/Person.cpp create mode 100644 Bachelor/Prog2/person-tree/Person.h create mode 100644 Bachelor/Prog2/person-tree/Prs_test.cpp create mode 100644 Bachelor/Prog2/person-tree/Tree.h create mode 100644 Bachelor/Prog2/person-tree/Treenode.h create mode 100644 Bachelor/Prog2/person-tree/main.cpp create mode 100644 Bachelor/Prog2/person-tree/max.txt (limited to 'Bachelor/Prog2') diff --git a/Bachelor/Prog2/20050401.jpg b/Bachelor/Prog2/20050401.jpg new file mode 100644 index 0000000..762a9dc Binary files /dev/null and b/Bachelor/Prog2/20050401.jpg differ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.cpp new file mode 100644 index 0000000..3f7084f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.cpp @@ -0,0 +1,74 @@ +// Fig. 9.11: circle2.cpp +// Circle2 class member-function definitions. +#include + +using std::cout; + +#include "circle2.h" // Circle2 class definition + +// default constructor +Circle2::Circle2( int xValue, int yValue, double radiusValue ) +{ + x = xValue; + y = yValue; + setRadius( radiusValue ); + +} // end Circle2 constructor + +// set radius +void Circle2::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle2::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle2::getDiameter() const +{ + return 2 * radius; + +} // end function getDiameter + +// calculate and return circumference +double Circle2::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle2::getArea() const +{ + return 3.14159 * radius * radius; + +} // end function getArea + +// output Circle2 object +void Circle2::print() const +{ + cout << "Center = [" << x << ", " << y << ']' + << "; Radius = " << radius; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.h new file mode 100644 index 0000000..0fd592d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.h @@ -0,0 +1,44 @@ +// Fig. 9.10: circle2.h +// Circle2 class contains x-y coordinate pair and radius. +#ifndef CIRCLE2_H +#define CIRCLE2_H + +#include "point.h" // Point class definition + +class Circle2 : public Point { + +public: + + // default constructor + Circle2( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle2 object + +private: + double radius; // Circle2's radius + +}; // end class Circle2 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.cpp new file mode 100644 index 0000000..38261da --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.cpp @@ -0,0 +1,65 @@ +// Fig. 9.5: point.cpp +// Point class member-function definitions. +#include + +using std::cout; + +#include "point.h" // Point class definition + +// default constructor +Point::Point( int xValue, int yValue ) +{ + x = xValue; + y = yValue; + +} // end Point constructor + +// set x in coordinate pair +void Point::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point::getY() const +{ + return y; + +} // end function getY + +// output Point object +void Point::print() const +{ + cout << '[' << x << ", " << y << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.h new file mode 100644 index 0000000..7593775 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.h @@ -0,0 +1,40 @@ +// Fig. 9.4: point.h +// Point class definition represents an x-y coordinate pair. +#ifndef POINT_H +#define POINT_H + +class Point { + +public: + Point( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.cpp new file mode 100644 index 0000000..24a1f67 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.cpp @@ -0,0 +1,74 @@ +// Fig. 9.15: circle3.cpp +// Circle3 class member-function definitions. +#include + +using std::cout; + +#include "circle3.h" // Circle3 class definition + +// default constructor +Circle3::Circle3( int xValue, int yValue, double radiusValue ) +{ + x = xValue; + y = yValue; + setRadius( radiusValue ); + +} // end Circle3 constructor + +// set radius +void Circle3::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle3::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle3::getDiameter() const +{ + return 2 * radius; + +} // end function getDiameter + +// calculate and return circumference +double Circle3::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle3::getArea() const +{ + return 3.14159 * radius * radius; + +} // end function getArea + +// output Circle3 object +void Circle3::print() const +{ + cout << "Center = [" << x << ", " << y << ']' + << "; Radius = " << radius; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.h new file mode 100644 index 0000000..137a2bd --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.h @@ -0,0 +1,44 @@ +// Fig. 9.14: circle3.h +// Circle3 class contains x-y coordinate pair and radius. +#ifndef CIRCLE3_H +#define CIRCLE3_H + +#include "point2.h" // Point2 class definition + +class Circle3 : public Point2 { + +public: + + // default constructor + Circle3( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle3 object + +private: + double radius; // Circle3's radius + +}; // end class Circle3 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp new file mode 100644 index 0000000..6f3a598 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp @@ -0,0 +1,63 @@ +// Fig. 9.16: circletest3.cpp +// Testing class Circle3. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include "circle3.h" // Circle3 class definition + +int main() +{ + Circle3 circle( 37, 43, 2.5 ); // instantiate Circle3 object + + // display point coordinates + cout << "X coordinate is " << circle.getX() + << "\nY coordinate is " << circle.getY() + << "\nRadius is " << circle.getRadius(); + + circle.setX( 2 ); // set new x-coordinate + circle.setY( 2 ); // set new y-coordinate + circle.setRadius( 4.25 ); // set new radius + + // display new point value + cout << "\n\nThe new location and radius of circle are\n"; + circle.print(); + + // display floating-point values with 2 digits of precision + cout << fixed << setprecision( 2 ); + + // display Circle3's diameter + cout << "\nDiameter is " << circle.getDiameter(); + + // display Circle3's circumference + cout << "\nCircumference is " << circle.getCircumference(); + + // display Circle3's area + cout << "\nArea is " << circle.getArea(); + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.cpp new file mode 100644 index 0000000..27b014a --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.cpp @@ -0,0 +1,65 @@ +// Fig. 9.13: point2.cpp +// Point2 class member-function definitions. +#include + +using std::cout; + +#include "point2.h" // Point2 class definition + +// default constructor +Point2::Point2( int xValue, int yValue ) +{ + x = xValue; + y = yValue; + +} // end Point2 constructor + +// set x in coordinate pair +void Point2::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point2::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point2::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point2::getY() const +{ + return y; + +} // end function getY + +// output Point2 object +void Point2::print() const +{ + cout << '[' << x << ", " << y << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.h new file mode 100644 index 0000000..5b81781 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.h @@ -0,0 +1,40 @@ +// Fig. 9.12: point2.h +// Point2 class definition represents an x-y coordinate pair. +#ifndef POINT2_H +#define POINT2_H + +class Point2 { + +public: + Point2( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point2 object + +protected: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point2 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.cpp new file mode 100644 index 0000000..d37278f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.cpp @@ -0,0 +1,88 @@ +// Fig. 9.28: circle5.cpp +// Circle5 class member-function definitions. +#include + +using std::cout; +using std::endl; + +#include "circle5.h" // Circle5 class definition + +// default constructor +Circle5::Circle5( int xValue, int yValue, double radiusValue ) + : Point4( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + + cout << "Circle5 constructor: "; + print(); + cout << endl; + +} // end Circle5 constructor + +// destructor +Circle5::~Circle5() +{ + cout << "Circle5 destructor: "; + print(); + cout << endl; + +} // end Circle5 destructor + +// set radius +void Circle5::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle5::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle5::getDiameter() const +{ + return 2 * getRadius(); + +} // end function getDiameter + +// calculate and return circumference +double Circle5::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle5::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// output Circle5 object +void Circle5::print() const +{ + cout << "Center = "; + Point4::print(); // invoke Point4's print function + cout << "; Radius = " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.h new file mode 100644 index 0000000..e2d8e78 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.h @@ -0,0 +1,45 @@ +// Fig. 9.27: circle5.h +// Circle5 class contains x-y coordinate pair and radius. +#ifndef CIRCLE5_H +#define CIRCLE5_H + +#include "point4.h" // Point4 class definition + +class Circle5 : public Point4 { + +public: + + // default constructor + Circle5( int = 0, int = 0, double = 0.0 ); + + ~Circle5(); // destructor + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle5 object + +private: + double radius; // Circle5's radius + +}; // end class Circle5 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/fig09_29.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/fig09_29.cpp new file mode 100644 index 0000000..634348a --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/fig09_29.cpp @@ -0,0 +1,44 @@ +// Fig. 9.29: fig09_29.cpp +// Display order in which base-class and derived-class +// constructors are called. +#include + +using std::cout; +using std::endl; + +#include "circle5.h" // Circle5 class definition + +int main() +{ + { // begin new scope + + Point4 point( 11, 22 ); + + } // end scope + + cout << endl; + Circle5 circle1( 72, 29, 4.5 ); + + cout << endl; + Circle5 circle2( 5, 5, 10 ); + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.cpp new file mode 100644 index 0000000..8538b6e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.cpp @@ -0,0 +1,77 @@ +// Fig. 9.26: point4.cpp +// Point4 class member-function definitions. +#include + +using std::cout; +using std::endl; + +#include "point4.h" // Point4 class definition + +// default constructor +Point4::Point4( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + cout << "Point4 constructor: "; + print(); + cout << endl; + +} // end Point4 constructor + +// destructor +Point4::~Point4() +{ + cout << "Point4 destructor: "; + print(); + cout << endl; + +} // end Point4 destructor + +// set x in coordinate pair +void Point4::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point4::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point4::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point4::getY() const +{ + return y; + +} // end function getY + +// output Point4 object +void Point4::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.h new file mode 100644 index 0000000..bcb87c3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.h @@ -0,0 +1,41 @@ +// Fig. 9.25: point4.h +// Point4 class definition represents an x-y coordinate pair. +#ifndef POINT4_H +#define POINT4_H + +class Point4 { + +public: + Point4( int = 0, int = 0 ); // default constructor + ~Point4(); // destructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point3 object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point4 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp new file mode 100644 index 0000000..e50e422 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp @@ -0,0 +1,45 @@ +// Fig. 7.24: elevatorSimulation.cpp +// Driver for the simulation. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include "building.h" // Building class definition + +int main() +{ + int duration; // length of simulation in seconds + + cout << "Enter run time: "; + cin >> duration; + cin.ignore(); // ignore return char + + Building building; // create the building + + cout << endl << "*** ELEVATOR SIMULATION BEGINS ***" + << endl << endl; + + building.runSimulation( duration ); // start simulation + + cout << "*** ELEVATOR SIMULATION ENDS ***" << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp new file mode 100644 index 0000000..2c97771 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp @@ -0,0 +1,44 @@ +// Fig. 7.32: bell.cpp +// Member-function definitions for class Bell. +#include + +using std::cout; +using std::endl; + +#include "bell.h" // Bell class definition + +// constructor +Bell::Bell() +{ + cout << "bell created" << endl; + +} // end Bell constructor + +// destructor +Bell::~Bell() +{ + cout << "bell destroyed" << endl; + +} // end ~Bell destructor + +// ring bell +void Bell::ringBell() const +{ + cout << "elevator rings its bell" << endl; + +} // end function ringBell + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h new file mode 100644 index 0000000..7b8a9c3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h @@ -0,0 +1,30 @@ +// Fig. 7.31: bell.h +// Bell class definition. +#ifndef BELL_H +#define BELL_H + +class Bell { + +public: + Bell(); // constructor + ~Bell(); // destructor + void ringBell() const; // ring the bell + +}; // end class Bell + +#endif // BELL_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp new file mode 100644 index 0000000..630cc91 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp @@ -0,0 +1,65 @@ +// Fig. 7.26: building.cpp +// Member-function definitions for class Building. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include "building.h" // Building class definition + +// constructor +Building::Building() + : floor1( Floor::FLOOR1, elevator ), + floor2( Floor::FLOOR2, elevator ), + elevator( floor1, floor2 ), + scheduler( floor1, floor2 ) +{ + cout << "building created" << endl; + +} // end Building constructor + +// destructor +Building::~Building() +{ + cout << "building destroyed" << endl; + +} // end ~Building destructor + +// function to control simulation +void Building::runSimulation( int totalTime ) +{ + int currentTime = 0; + + while ( currentTime < totalTime ) { + clock.tick(); // increment time + currentTime = clock.getTime(); // get new time + cout << "TIME: " << currentTime << endl; + + // process person arrivals for currentTime + scheduler.processTime( currentTime ); + + // process elevator events for currentTime + elevator.processTime( currentTime ); + + // wait for Enter key press, so user can view output + cin.get(); + + } // end while + +} // end function runSimulation + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h new file mode 100644 index 0000000..5d47f07 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h @@ -0,0 +1,42 @@ +// Fig. 7.25: building.h +// Building class definition. +#ifndef BUILDING_H +#define BUILDING_H + +#include "elevator.h" // Elevator class definition +#include "floor.h" // Floor class definition +#include "clock.h" // Clock class definition +#include "scheduler.h" // Scheduler class definition + +class Building { + +public: + Building(); // constructor + ~Building(); // destructor + void runSimulation( int ); // controls simulation + +private: + Floor floor1; // floor1 object + Floor floor2; // floor2 object + Elevator elevator; // elevator object + Clock clock; // clock object + Scheduler scheduler; // scheduler object + +}; // end class Building + +#endif // BUILDING_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp new file mode 100644 index 0000000..2195a4f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp @@ -0,0 +1,52 @@ +// Fig. 9.34: button.cpp +// Member function definitions for class Button. +#include + +using std::cout; +using std::endl; + +#include "button.h" // Button class definition + +// constructor +Button::Button( Elevator &elevatorHandle ) + : elevatorRef( elevatorHandle ), pressed( false ) +{ + cout << "button created" << endl; + +} // end Button constructor + +// destructor +Button::~Button() +{ + cout << "button destroyed" << endl; + +} // end Button destructor + +// press button +void Button::pressButton() +{ + pressed = true; + +} // end function pressButton + +// reset button +void Button::resetButton() +{ + pressed = false; + +} // end function resetButton + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h new file mode 100644 index 0000000..fbc0f94 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h @@ -0,0 +1,41 @@ +// Fig. 9.33: button.h +// Definition for class Button. +#ifndef BUTTON_H +#define BUTTON_H + +class Elevator; // forward declaration + +class Button { + +public: + Button( Elevator & ); // constructor + ~Button(); // destructor + void pressButton(); // sets button on + void resetButton(); // resets button off + +protected: + + // reference to button's elevator + Elevator &elevatorRef; + +private: + bool pressed; // state of button + +}; // end class Button + +#endif // BUTTON_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp new file mode 100644 index 0000000..725a189 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp @@ -0,0 +1,52 @@ +// Fig. 7.28: clock.cpp +// Member-function definitions for class Clock. +#include + +using std::cout; +using std::endl; + +#include "clock.h" // Clock class definition + +// constructor +Clock::Clock() + : time( 0 ) // initialize time to 0 +{ + cout << "clock created" << endl; + +} // end Clock constructor + +// destructor +Clock::~Clock() +{ + cout << "clock destroyed" << endl; + +} // end ~Clock destructor + +// increment time by 1 +void Clock::tick() +{ + time++; + +} // end function tick + +// return current time +int Clock::getTime() const +{ + return time; + +} // end function getTime + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h new file mode 100644 index 0000000..de97814 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h @@ -0,0 +1,34 @@ +// Fig. 7.27: clock.h +// Clock class definition. +#ifndef CLOCK_H +#define CLOCK_H + +class Clock { + +public: + Clock(); // constructor + ~Clock(); // destructor + void tick(); // increment clock by one second + int getTime() const; // returns clock's current time + +private: + int time; // clock's time + +}; // end class Clock + +#endif // CLOCK_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp new file mode 100644 index 0000000..7adbe37 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp @@ -0,0 +1,81 @@ +// Fig. 7.36: door.cpp +// Member-function definitions for class Door. +#include + +using std::cout; +using std::endl; + +#include "door.h" // Door class definition +#include "person.h" // Person class definition +#include "floor.h" // Floor class definition +#include "elevator.h" // Elevator class definition + +// constructor +Door::Door() + : open( false ) // initialize open to false +{ + cout << "door created" << endl; + +} // end Door constructor + +// destructor +Door::~Door() +{ + cout << "door destroyed" << endl; + +} // end ~Door destructor + +// open the door +void Door::openDoor( Person * const passengerPtr, + Person * const nextPassengerPtr, Floor ¤tFloor, + Elevator &elevator ) +{ + if ( !open ) { // if door is not open, open door + open = true; + + cout << "elevator opens its door on floor " + << currentFloor.getNumber() << endl; + + // if passenger is in elevator, tell person to leave + if ( passengerPtr != 0 ) { + passengerPtr->exitElevator( currentFloor, elevator ); + delete passengerPtr; // passenger leaves simulation + + } // end if + + // if passenger waiting to enter elevator, + // tell passenger to enter + if ( nextPassengerPtr != 0 ) + nextPassengerPtr->enterElevator( + elevator, currentFloor ); + + } // end outer if + +} // end function openDoor + +// close the door +void Door::closeDoor( const Floor ¤tFloor ) +{ + if ( open ) { // if door is open, close door + open = false; + cout << "elevator closes its door on floor " + << currentFloor.getNumber() << endl; + + } // end if + +} // end function closeDoor + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h new file mode 100644 index 0000000..05c7b3e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h @@ -0,0 +1,40 @@ +// Fig. 7.35: door.h +// Door class definition. +#ifndef DOOR_H +#define DOOR_H + +class Person; // forward declaration +class Floor; // forward declaration +class Elevator; // forward declaration + +class Door { + +public: + Door(); // constructor + ~Door(); // destructor + + void openDoor( Person * const, // opens door + Person * const, Floor &, Elevator & ); + void closeDoor( const Floor & ); // closes door + +private: + bool open; // open or closed + +}; + +#endif // DOOR_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp new file mode 100644 index 0000000..26e01f4 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp @@ -0,0 +1,231 @@ +// Fig. 7.42: elevator.cpp +// Member-function definitions for class Elevator. +#include + +using std::cout; +using std::endl; + +#include "elevator.h" // Elevator class definition +#include "person.h" // Person class definition +#include "floor.h" // Floor class definition + +// static constants that represent time required to travel +// between floors and directions of the elevator +const int Elevator::ELEVATOR_TRAVEL_TIME = 5; +const int Elevator::UP = 0; +const int Elevator::DOWN = 1; + +// constructor +Elevator::Elevator( Floor &firstFloor, Floor &secondFloor ) + : elevatorButton( *this ), + currentBuildingClockTime( 0 ), + moving( false ), + direction( UP ), + currentFloor( Floor::FLOOR1 ), + arrivalTime( 0 ), + floor1NeedsService( false ), + floor2NeedsService( false ), + floor1Ref( firstFloor ), + floor2Ref( secondFloor ), + passengerPtr( 0 ) +{ + cout << "elevator created" << endl; + +} // end Elevator constructor + +// destructor +Elevator::~Elevator() +{ + delete passengerPtr; + cout << "elevator destroyed" << endl; + +} // end ~Elevator destructor + +// give time to elevator +void Elevator::processTime( int time ) +{ + currentBuildingClockTime = time; + + if ( moving ) // elevator is moving + processPossibleArrival(); + + else // elevator is not moving + processPossibleDeparture(); + + if ( !moving ) + cout << "elevator at rest on floor " + << currentFloor << endl; + +} // end function processTime + +// when elevator is moving, determine if it should stop +void Elevator::processPossibleArrival() +{ + // if elevator arrives at destination floor + if ( currentBuildingClockTime == arrivalTime ) { + + currentFloor = // update current floor + ( currentFloor == Floor::FLOOR1 ? + Floor::FLOOR2 : Floor::FLOOR1 ); + + direction = // update direction + ( currentFloor == Floor::FLOOR1 ? UP : DOWN ); + + cout << "elevator arrives on floor " + << currentFloor << endl; + + // process arrival at currentFloor + arriveAtFloor( currentFloor == Floor::FLOOR1 ? + floor1Ref : floor2Ref ); + + return; + + } // end if + + // elevator still moving + cout << "elevator moving " + << ( direction == UP ? "up" : "down" ) << endl; + +} // end function processPossibleArrival + +// determine whether elevator should move +void Elevator::processPossibleDeparture() +{ + // this floor needs service? + bool currentFloorNeedsService = + currentFloor == Floor::FLOOR1 ? + floor1NeedsService : floor2NeedsService; + + // other floor needs service? + bool otherFloorNeedsService = + currentFloor == Floor::FLOOR1 ? + floor2NeedsService : floor1NeedsService; + + // service this floor (if needed) + if ( currentFloorNeedsService ) { + arriveAtFloor( currentFloor == Floor::FLOOR1 ? + floor1Ref : floor2Ref ); + + return; + } + + // service other floor (if needed) + if ( otherFloorNeedsService ) + prepareToLeave( true ); + +} // end function processPossibleDeparture + +// arrive at a particular floor +void Elevator::arriveAtFloor( Floor& arrivalFloor ) +{ + moving = false; // reset state + + cout << "elevator resets its button" << endl; + elevatorButton.resetButton(); + + bell.ringBell(); + + // notify floor that elevator has arrived + Person *floorPersonPtr = arrivalFloor.elevatorArrived(); + + door.openDoor( + passengerPtr, floorPersonPtr, arrivalFloor, *this ); + + // this floor needs service? + bool currentFloorNeedsService = + currentFloor == Floor::FLOOR1 ? + floor1NeedsService : floor2NeedsService; + + // other floor needs service? + bool otherFloorNeedsService = + currentFloor == Floor::FLOOR1 ? + floor2NeedsService : floor1NeedsService; + + // if this floor does not need service + // prepare to leave for the other floor + if ( !currentFloorNeedsService ) + prepareToLeave( otherFloorNeedsService ); + + else // otherwise, reset service flag + currentFloor == Floor::FLOOR1 ? + floor1NeedsService = false: floor2NeedsService = false; + +} // end function arriveAtFloor + +// request service from elevator +void Elevator::summonElevator( int floor ) +{ + // set appropriate servicing flag + floor == Floor::FLOOR1 ? + floor1NeedsService = true : floor2NeedsService = true; + +} // end function summonElevator + +// accept a passenger +void Elevator::passengerEnters( Person * const personPtr ) +{ + // board passenger + passengerPtr = personPtr; + + cout << "person " << passengerPtr->getID() + << " enters elevator from floor " + << currentFloor << endl; + +} // end function passengerEnters + +// notify elevator that passenger is exiting +void Elevator::passengerExits() +{ + passengerPtr = 0; + +} // end function passengerExits + +// prepare to leave a floor +void Elevator::prepareToLeave( bool leaving ) +{ + // get reference to current floor + Floor &thisFloor = + currentFloor == Floor::FLOOR1 ? floor1Ref : floor2Ref; + + // notify floor that elevator may be leaving + thisFloor.elevatorLeaving(); + + door.closeDoor( thisFloor ); + + if ( leaving ) // leave, if necessary + move(); + +} // end function prepareToLeave + +// go to other floor +void Elevator::move() +{ + moving = true; // change state + + // schedule arrival time + arrivalTime = currentBuildingClockTime + + ELEVATOR_TRAVEL_TIME; + + cout << "elevator begins moving " + << ( direction == DOWN ? "down " : "up " ) + << "to floor " + << ( direction == DOWN ? '1' : '2' ) + << " (arrives at time " << arrivalTime << ')' + << endl; + +} // end function move + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h new file mode 100644 index 0000000..ed69376 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h @@ -0,0 +1,75 @@ +// Fig. 7.41: elevator.h +// Elevator class definition. +#ifndef ELEVATOR_H +#define ELEVATOR_H + +#include "elevatorButton.h" +#include "door.h" +#include "bell.h" + +class Floor; // forward declaration +class Person; // forward declaration + +class Elevator { + +public: + Elevator( Floor &, Floor & ); // constructor + ~Elevator(); // destructor + void summonElevator( int ); // request to service floor + void prepareToLeave( bool ); // prepare to leave + void processTime( int ); // give time to elevator + void passengerEnters( Person * const ); // board a passenger + void passengerExits(); // exit a passenger + + // public object accessible to client code with + // access to Elevator object + ElevatorButton elevatorButton; + +private: + + // utility functions + void processPossibleArrival(); + void processPossibleDeparture(); + void arriveAtFloor( Floor & ); + void move(); + + // static constants that represent time required to travel + // between floors and directions of the elevator + static const int ELEVATOR_TRAVEL_TIME; + static const int UP; + static const int DOWN; + + // data members + int currentBuildingClockTime; // current time + bool moving; // elevator state + int direction; // current direction + int currentFloor; // current location + int arrivalTime; // time to arrive at a floor + bool floor1NeedsService; // floor1 service flag + bool floor2NeedsService; // floor2 service flag + + Floor &floor1Ref; // reference to floor1 + Floor &floor2Ref; // reference to floor2 + Person *passengerPtr; // pointer to passenger + + Door door; // door object + Bell bell; // bell object + +}; // end class Elevator + +#endif // ELEVATOR_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp new file mode 100644 index 0000000..c7b7117 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp @@ -0,0 +1,49 @@ +// Fig. 9.36: elevatorButton.cpp: +// Member-function definitions for class ElevatorButton. +#include + +using std::cout; +using std::endl; + +#include "elevatorButton.h" // ElevatorButton class definition +#include "elevator.h" // Elevator class definition + +// constructor +ElevatorButton::ElevatorButton( Elevator &elevatorHandle ) + : Button( elevatorHandle ) +{ + cout << "elevator button created" << endl; + +} // end ElevatorButton constructor + +// destructor +ElevatorButton::~ElevatorButton() +{ + cout << "elevator button destroyed" << endl; + +} // end ~ElevatorButton destructor + +// press button and signal elevator to prepare to leave floor +void ElevatorButton::pressButton() +{ + Button::pressButton(); + cout << "elevator button tells elevator to prepare to leave" + << endl; + elevatorRef.prepareToLeave( true ); + +} // end function pressButton + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h new file mode 100644 index 0000000..4567799 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h @@ -0,0 +1,32 @@ +// Fig. 9.35: elevatorButton.h +// ElevatorButton class definition. +#ifndef ELEVATORBUTTON_H +#define ELEVATORBUTTON_H + +#include "button.h" // Button class definition + +class ElevatorButton : public Button { + +public: + ElevatorButton( Elevator & ); // constructor + ~ElevatorButton(); // destructor + void pressButton(); // press the button + +}; // end class ElevatorButton + +#endif // ELEVATORBUTTON_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp new file mode 100644 index 0000000..c24564b --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp @@ -0,0 +1,98 @@ +// Fig. 7.44: floor.cpp +// Member-function definitions for class Floor. +#include + +using std::cout; +using std::endl; + +#include "floor.h" // Floor class definition +#include "person.h" // Person class definition +#include "elevator.h" // Elevator class definition +#include "door.h" // Door class definition + +// static constants that represent the floor numbers +const int Floor::FLOOR1 = 1; +const int Floor::FLOOR2 = 2; + +// constructor +Floor::Floor(int number, Elevator &elevatorHandle ) + : floorButton( number, elevatorHandle ), + floorNumber( number ), + elevatorRef( elevatorHandle ), + occupantPtr ( 0 ), + light( floorNumber ) +{ + cout << "floor " << floorNumber << " created" << endl; + +} // end Floor constructor + +// destructor +Floor::~Floor() +{ + delete occupantPtr; + cout << "floor " << floorNumber << " destroyed" << endl; + +} // end ~Floor destructor + +// determine whether floor is occupied +bool Floor::isOccupied() const +{ + return ( occupantPtr != 0 ); + +} // end function isOccupied + +// return this floor's number +int Floor::getNumber() const +{ + return floorNumber; + +} // end function getNumber + +// person arrives on floor +void Floor::personArrives( Person * const personPtr ) +{ + occupantPtr = personPtr; + +} // end function personArrives + +// notify floor that elevator has arrived +Person *Floor::elevatorArrived() +{ + cout << "floor " << floorNumber + << " resets its button" << endl; + + floorButton.resetButton(); + light.turnOn(); + + return occupantPtr; + +} // end function elevatorArrived + +// tell floor that elevator is leaving +void Floor::elevatorLeaving() +{ + light.turnOff(); + +} // end function elevatorLeaving + +// notifies floor that person is leaving +void Floor::personBoardingElevator() +{ + occupantPtr = 0; // person no longer on floor + +} // end function personBoardingElevator + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h new file mode 100644 index 0000000..5ded23e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h @@ -0,0 +1,63 @@ +// Fig. 7.43: floor.h +// Floor class definition. +#ifndef FLOOR_H +#define FLOOR_H + +#include "floorButton.h" +#include "light.h" + +class Elevator; // forward declaration +class Person; // forward declaration + +class Floor { + +public: + Floor( int, Elevator & ); // constructor + ~Floor(); // destructor + bool isOccupied() const; // return true if floor occupied + int getNumber() const; // return floor's number + + // pass a handle to new person coming on floor + void personArrives( Person * const ); + + // notify floor that elevator has arrived + Person *elevatorArrived(); + + // notify floor that elevator is leaving + void elevatorLeaving(); + + // notify floor that person is leaving floor + void personBoardingElevator(); + + // static constants representing floor numbers + static const int FLOOR1; + static const int FLOOR2; + + // public FloorButton object accessible to + // any client code with access to a Floor + FloorButton floorButton; + +private: + const int floorNumber; // the floor's number + Elevator &elevatorRef; // reference to elevator + Person *occupantPtr; // pointer to person on floor + Light light; // light object + +}; // end class Floor + +#endif // FLOOR_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp new file mode 100644 index 0000000..0370b4e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp @@ -0,0 +1,54 @@ +// Fig. 9.38: floorButton.cpp +// Member-function definitions for class FloorButton. +#include + +using std::cout; +using std::endl; + +#include "floorButton.h" +#include "elevator.h" + +// constructor +FloorButton::FloorButton( int floor, Elevator &elevatorHandle ) + : Button( elevatorHandle ), + floorNumber( floor ) +{ + cout << "floor " << floorNumber << " button created" + << endl; + +} // end FloorButton constructor + +// destructor +FloorButton::~FloorButton() +{ + cout << "floor " << floorNumber << " button destroyed" + << endl; + +} // end ~FloorButton destructor + +// press the button +void FloorButton::pressButton() +{ + Button::pressButton(); + cout << "floor " << floorNumber + << " button summons elevator" << endl; + + // call elevator to this floor + elevatorRef.summonElevator( floorNumber ); + +} // end function pressButton + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h new file mode 100644 index 0000000..a0525f7 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h @@ -0,0 +1,35 @@ +// Fig. 9.37: floorButton.h +// FloorButton class definition. +#ifndef FLOORBUTTON_H +#define FLOORBUTTON_H + +#include "button.h" // Button class definition + +class FloorButton : public Button { + +public: + FloorButton( int, Elevator & ); // constructor + ~FloorButton(); // destructor + void pressButton(); // press the button + +private: + const int floorNumber; // button's floor number + +}; // end class FloorButton + +#endif // FLOORBUTTON_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp new file mode 100644 index 0000000..54f3204 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp @@ -0,0 +1,64 @@ +// Fig. 7.34: light.cpp +// Member-function definitions for class Light. +#include + +using std::cout; +using std::endl; + +#include "light.h" // Light class definition + +// constructor +Light::Light( int number ) + : on( false ), + floorNumber( number ) +{ + cout << "floor " << floorNumber << " light created" << endl; + +} // end Light constructor + +// destuctor +Light::~Light() +{ + cout << "floor " << floorNumber + << " light destroyed" << endl; + +} // end ~Light destructor + +// turn light on +void Light::turnOn() +{ + if ( !on ) { // if light not on, turn it on + on = true; + cout << "floor " << floorNumber + << " light turns on" << endl; + + } // end if + +} // end function turnOn + +// turn light off +void Light::turnOff() +{ + if ( on ) { // if light is on, turn it off + on = false; + cout << "floor " << floorNumber + << " light turns off" << endl; + + } // end if + +} // end function turnOff + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h new file mode 100644 index 0000000..69c559c --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h @@ -0,0 +1,35 @@ +// Fig. 7.33: light.h +// Light class definition. +#ifndef LIGHT_H +#define LIGHT_H + +class Light { + +public: + Light( int ); // constructor + ~Light(); // destructor + void turnOn(); // turns light on + void turnOff(); // turns light off + +private: + bool on; // true if on; false if off + const int floorNumber; // floor number that contains light + +}; // end class Light + +#endif // LIGHT_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp new file mode 100644 index 0000000..a3cfeb7 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp @@ -0,0 +1,91 @@ +// Fig. 7.46: person.cpp +// Member-function definitions for class Person. +#include + +using std::cout; +using std::endl; + +#include "person.h" // Person class definition +#include "floor.h" // Floor class definition +#include "elevator.h" // Elevator class definition + +// initialize static member personCount +int Person::personCount = 0; + +// constructor +Person::Person( int destFloor ) + : ID( ++personCount ), + destinationFloor( destFloor ) +{ + // empty body + +} // end Person constructor + +// destructor +Person::~Person() +{ + cout << "(person " << ID << " destructor invoked)" << endl; + +} // end ~Person destructor + +// return person's ID number +int Person::getID() const +{ + return ID; + +} // end function getID + +// person walks onto a floor +void Person::stepOntoFloor( Floor& floor ) +{ + // notify floor person is coming + cout << "person " << ID << " steps onto floor " + << floor.getNumber() << endl; + floor.personArrives( this ); + + // press button on floor + cout << "person " << ID + << " presses floor button on floor " + << floor.getNumber() << endl; + floor.floorButton.pressButton(); + +} // end function stepOntoFloor + +// person enters elevator +void Person::enterElevator( Elevator &elevator, Floor &floor ) +{ + floor.personBoardingElevator(); // person leaves floor + + elevator.passengerEnters( this ); // person enters elevator + + // press button on elevator + cout << "person " << ID + << " presses elevator button" << endl; + elevator.elevatorButton.pressButton(); + +} // end function enterElevator + +// person exits elevator +void Person::exitElevator( + const Floor &floor, Elevator &elevator ) const +{ + cout << "person " << ID << " exits elevator on floor " + << floor.getNumber() << endl; + elevator.passengerExits(); + +} // end function exitElevator + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h new file mode 100644 index 0000000..64906a5 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h @@ -0,0 +1,42 @@ +// Fig. 7.45: person.h +// Person class definition. +#ifndef PERSON_H +#define PERSON_H + +class Floor; // forward declaration +class Elevator; // forward declaration + +class Person { + +public: + Person( int ); // constructor + ~Person(); // destructor + int getID() const; // returns person's ID + + void stepOntoFloor( Floor & ); + void enterElevator( Elevator &, Floor & ); + void exitElevator( const Floor &, Elevator & ) const; + +private: + static int personCount; // total number of people + const int ID; // person's unique ID # + const int destinationFloor; // destination floor # + +}; // end class Person + +#endif // PERSON_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp new file mode 100644 index 0000000..ac9110c --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp @@ -0,0 +1,133 @@ +// Fig. 7.30: scheduler.cpp +// Member-function definitions for class Scheduler. +#include + +using std::cout; +using std::endl; + +#include +#include + +#include "scheduler.h" // Scheduler class definition +#include "floor.h" // Floor class definition +#include "person.h" // Person class definition + +// constructor +Scheduler::Scheduler( Floor &firstFloor, Floor &secondFloor ) + : currentClockTime( 0 ), + floor1Ref( firstFloor ), + floor2Ref( secondFloor ) +{ + srand( time( 0 ) ); // seed random number generator + cout << "scheduler created" << endl; + + // schedule first arrivals for floor 1 and floor 2 + scheduleTime( floor1Ref ); + scheduleTime( floor2Ref ); + +} // end Scheduler constructor + +// destructor +Scheduler::~Scheduler() +{ + cout << "scheduler destroyed" << endl; + +} // end Scheduler destructor + +// schedule arrival on a floor +void Scheduler::scheduleTime( const Floor &floor ) +{ + int floorNumber = floor.getNumber(); + int arrivalTime = currentClockTime + ( 5 + rand() % 16 ); + + floorNumber == Floor::FLOOR1 ? + floor1ArrivalTime = arrivalTime : + floor2ArrivalTime = arrivalTime; + + cout << "(scheduler schedules next person for floor " + << floorNumber << " at time " << arrivalTime << ')' + << endl; + +} // end function scheduleTime + +// reschedule arrival on a floor +void Scheduler::delayTime( const Floor &floor ) +{ + int floorNumber = floor.getNumber(); + + int arrivalTime = ( floorNumber == Floor::FLOOR1 ) ? + ++floor1ArrivalTime : ++floor2ArrivalTime; + + cout << "(scheduler delays next person for floor " + << floorNumber << " until time " << arrivalTime << ')' + << endl; + +} // end function delayTime + +// give time to scheduler +void Scheduler::processTime( int time ) +{ + currentClockTime = time; // record time + + // handle arrivals on floor 1 + handleArrivals( floor1Ref, currentClockTime ); + + // handle arrivals on floor 2 + handleArrivals( floor2Ref, currentClockTime ); + +} // end function processTime + +// create new person and place it on specified floor +void Scheduler::createNewPerson( Floor &floor ) +{ + int destinationFloor = + floor.getNumber() == Floor::FLOOR1 ? + Floor::FLOOR2 : Floor::FLOOR1; + + // create new person + Person *newPersonPtr = new Person( destinationFloor ); + + cout << "scheduler creates person " + << newPersonPtr->getID() << endl; + + // place person on proper floor + newPersonPtr->stepOntoFloor( floor ); + + scheduleTime( floor ); // schedule next arrival + +} // end function createNewPerson + +// handle arrivals for a specified floor +void Scheduler::handleArrivals( Floor &floor, int time ) +{ + int floorNumber = floor.getNumber(); + + int arrivalTime = ( floorNumber == Floor::FLOOR1 ) ? + floor1ArrivalTime : floor2ArrivalTime; + + if ( arrivalTime == time ) { + + if ( floor.isOccupied() ) // if floor occupied, + delayTime( floor ); // delay arrival + + else // otherwise, + createNewPerson( floor ); // create new person + + } // end outer if + +} // end function handleArrivals + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h new file mode 100644 index 0000000..6bb084c --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h @@ -0,0 +1,53 @@ +// Fig. 7.29: scheduler.h +// Scheduler class definition. +#ifndef SCHEDULER_H +#define SCHEDULER_H + +class Floor; // forward declaration + +class Scheduler { + +public: + Scheduler( Floor &, Floor & ); // constructor + ~Scheduler(); // destructor + void processTime( int ); // set scheduler's time + +private: + // schedule arrival to a floor + void scheduleTime( const Floor & ); + + // delay arrival to a floor + void delayTime( const Floor & ); + + // create new person; place on floor + void createNewPerson( Floor & ); + + // handle person arrival on a floor + void handleArrivals( Floor &, int ); + + int currentClockTime; + + Floor &floor1Ref; + Floor &floor2Ref; + + int floor1ArrivalTime; + int floor2ArrivalTime; + +}; // end class Scheduler + +#endif // SCHEDULER_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.cpp new file mode 100644 index 0000000..38261da --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.cpp @@ -0,0 +1,65 @@ +// Fig. 9.5: point.cpp +// Point class member-function definitions. +#include + +using std::cout; + +#include "point.h" // Point class definition + +// default constructor +Point::Point( int xValue, int yValue ) +{ + x = xValue; + y = yValue; + +} // end Point constructor + +// set x in coordinate pair +void Point::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point::getY() const +{ + return y; + +} // end function getY + +// output Point object +void Point::print() const +{ + cout << '[' << x << ", " << y << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.h new file mode 100644 index 0000000..7593775 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.h @@ -0,0 +1,40 @@ +// Fig. 9.4: point.h +// Point class definition represents an x-y coordinate pair. +#ifndef POINT_H +#define POINT_H + +class Point { + +public: + Point( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/pointtest.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/pointtest.cpp new file mode 100644 index 0000000..3ca57bf --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/pointtest.cpp @@ -0,0 +1,43 @@ +// Fig. 9.6: pointtest.cpp +// Testing class Point. +#include + +using std::cout; +using std::endl; + +#include "point.h" // Point class definition + +int main() +{ + Point point( 72, 115 ); // instantiate Point object + + // display point coordinates + cout << "X coordinate is " << point.getX() + << "\nY coordinate is " << point.getY(); + + point.setX( 10 ); // set x-coordinate + point.setY( 10 ); // set y-coordinate + + // display new point value + cout << "\n\nThe new location of point is "; + point.print(); + cout << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.cpp new file mode 100644 index 0000000..0a32f7d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.cpp @@ -0,0 +1,102 @@ +// Fig. 9.8: circle.cpp +// Circle class member-function definitions. +#include + +using std::cout; + +#include "circle.h" // Circle class definition + +// default constructor +Circle::Circle( int xValue, int yValue, double radiusValue ) +{ + x = xValue; + y = yValue; + setRadius( radiusValue ); + +} // end Circle constructor + +// set x in coordinate pair +void Circle::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Circle::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Circle::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Circle::getY() const +{ + return y; + +} // end function getY + +// set radius +void Circle::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle::getDiameter() const +{ + return 2 * radius; + +} // end function getDiameter + +// calculate and return circumference +double Circle::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle::getArea() const +{ + return 3.14159 * radius * radius; + +} // end function getArea + +// output Circle object +void Circle::print() const +{ + cout << "Center = [" << x << ", " << y << ']' + << "; Radius = " << radius; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.h new file mode 100644 index 0000000..4ee5c3e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.h @@ -0,0 +1,50 @@ +// Fig. 9.7: circle.h +// Circle class contains x-y coordinate pair and radius. +#ifndef CIRCLE_H +#define CIRCLE_H + +class Circle { + +public: + + // default constructor + Circle( int = 0, int = 0, double = 0.0 ); + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle object + +private: + int x; // x-coordinate of Circle's center + int y; // y-coordinate of Circle's center + double radius; // Circle's radius + +}; // end class Circle + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circletest.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circletest.cpp new file mode 100644 index 0000000..f71c455 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circletest.cpp @@ -0,0 +1,63 @@ +// Fig. 9.9: circletest.cpp +// Testing class Circle. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include "circle.h" // Circle class definition + +int main() +{ + Circle circle( 37, 43, 2.5 ); // instantiate Circle object + + // display point coordinates + cout << "X coordinate is " << circle.getX() + << "\nY coordinate is " << circle.getY() + << "\nRadius is " << circle.getRadius(); + + circle.setX( 2 ); // set new x-coordinate + circle.setY( 2 ); // set new y-coordinate + circle.setRadius( 4.25 ); // set new radius + + // display new point value + cout << "\n\nThe new location and radius of circle are\n"; + circle.print(); + + // display floating-point values with 2 digits of precision + cout << fixed << setprecision( 2 ); + + // display Circle's diameter + cout << "\nDiameter is " << circle.getDiameter(); + + // display Circle's circumference + cout << "\nCircumference is " << circle.getCircumference(); + + // display Circle's area + cout << "\nArea is " << circle.getArea(); + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.cpp new file mode 100644 index 0000000..3e043c3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.cpp @@ -0,0 +1,74 @@ +// Fig. 9.20: circle4.cpp +// Circle4 class member-function definitions. +#include + +using std::cout; + +#include "circle4.h" // Circle4 class definition + +// default constructor +Circle4::Circle4( int xValue, int yValue, double radiusValue ) + : Point3( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + +} // end Circle4 constructor + +// set radius +void Circle4::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle4::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle4::getDiameter() const +{ + return 2 * getRadius(); + +} // end function getDiameter + +// calculate and return circumference +double Circle4::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle4::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// output Circle4 object +void Circle4::print() const +{ + cout << "Center = "; + Point3::print(); // invoke Point3's print function + cout << "; Radius = " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.h new file mode 100644 index 0000000..46f0f58 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.h @@ -0,0 +1,44 @@ +// Fig. 9.19: circle4.h +// Circle4 class contains x-y coordinate pair and radius. +#ifndef CIRCLE4_H +#define CIRCLE4_H + +#include "point3.h" // Point3 class definition + +class Circle4 : public Point3 { + +public: + + // default constructor + Circle4( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle4 object + +private: + double radius; // Circle4's radius + +}; // end class Circle4 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circletest4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circletest4.cpp new file mode 100644 index 0000000..c82f30f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circletest4.cpp @@ -0,0 +1,63 @@ +// Fig. 9.21: circletest4.cpp +// Testing class Circle4. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include "circle4.h" // Circle4 class definition + +int main() +{ + Circle4 circle( 37, 43, 2.5 ); // instantiate Circle4 object + + // display point coordinates + cout << "X coordinate is " << circle.getX() + << "\nY coordinate is " << circle.getY() + << "\nRadius is " << circle.getRadius(); + + circle.setX( 2 ); // set new x-coordinate + circle.setY( 2 ); // set new y-coordinate + circle.setRadius( 4.25 ); // set new radius + + // display new circle value + cout << "\n\nThe new location and radius of circle are\n"; + circle.print(); + + // display floating-point values with 2 digits of precision + cout << fixed << setprecision( 2 ); + + // display Circle4's diameter + cout << "\nDiameter is " << circle.getDiameter(); + + // display Circle4's circumference + cout << "\nCircumference is " << circle.getCircumference(); + + // display Circle4's area + cout << "\nArea is " << circle.getArea(); + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.cpp new file mode 100644 index 0000000..ac4f642 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.cpp @@ -0,0 +1,65 @@ +// Fig. 9.18: point3.cpp +// Point3 class member-function definitions. +#include + +using std::cout; + +#include "point3.h" // Point3 class definition + +// default constructor +Point3::Point3( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + // empty body + +} // end Point3 constructor + +// set x in coordinate pair +void Point3::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point3::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point3::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point3::getY() const +{ + return y; + +} // end function getY + +// output Point3 object +void Point3::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.h new file mode 100644 index 0000000..028f105 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.h @@ -0,0 +1,40 @@ +// Fig. 9.17: point3.h +// Point3 class definition represents an x-y coordinate pair. +#ifndef POINT3_H +#define POINT3_H + +class Point3 { + +public: + Point3( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point3 object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point3 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.cpp new file mode 100644 index 0000000..3e043c3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.cpp @@ -0,0 +1,74 @@ +// Fig. 9.20: circle4.cpp +// Circle4 class member-function definitions. +#include + +using std::cout; + +#include "circle4.h" // Circle4 class definition + +// default constructor +Circle4::Circle4( int xValue, int yValue, double radiusValue ) + : Point3( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + +} // end Circle4 constructor + +// set radius +void Circle4::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle4::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle4::getDiameter() const +{ + return 2 * getRadius(); + +} // end function getDiameter + +// calculate and return circumference +double Circle4::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle4::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// output Circle4 object +void Circle4::print() const +{ + cout << "Center = "; + Point3::print(); // invoke Point3's print function + cout << "; Radius = " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.h new file mode 100644 index 0000000..46f0f58 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.h @@ -0,0 +1,44 @@ +// Fig. 9.19: circle4.h +// Circle4 class contains x-y coordinate pair and radius. +#ifndef CIRCLE4_H +#define CIRCLE4_H + +#include "point3.h" // Point3 class definition + +class Circle4 : public Point3 { + +public: + + // default constructor + Circle4( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle4 object + +private: + double radius; // Circle4's radius + +}; // end class Circle4 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.cpp new file mode 100644 index 0000000..d0047db --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.cpp @@ -0,0 +1,68 @@ +// Fig. 9.23: cylinder.cpp +// Cylinder class inherits from class Circle4. +#include + +using std::cout; + +#include "cylinder.h" // Cylinder class definition + +// default constructor +Cylinder::Cylinder( int xValue, int yValue, double radiusValue, + double heightValue ) + : Circle4( xValue, yValue, radiusValue ) +{ + setHeight( heightValue ); + +} // end Cylinder constructor + +// set Cylinder's height +void Cylinder::setHeight( double heightValue ) +{ + height = ( heightValue < 0.0 ? 0.0 : heightValue ); + +} // end function setHeight + +// get Cylinder's height +double Cylinder::getHeight() const +{ + return height; + +} // end function getHeight + +// redefine Circle4 function getArea to calculate Cylinder area +double Cylinder::getArea() const +{ + return 2 * Circle4::getArea() + + getCircumference() * getHeight(); + +} // end function getArea + +// calculate Cylinder volume +double Cylinder::getVolume() const +{ + return Circle4::getArea() * getHeight(); + +} // end function getVolume + +// output Cylinder object +void Cylinder::print() const +{ + Circle4::print(); + cout << "; Height = " << getHeight(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.h new file mode 100644 index 0000000..461feb8 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.h @@ -0,0 +1,42 @@ +// Fig. 9.22: cylinder.h +// Cylinder class inherits from class Circle4. +#ifndef CYLINDER_H +#define CYLINDER_H + +#include "circle4.h" // Circle4 class definition + +class Cylinder : public Circle4 { + +public: + + // default constructor + Cylinder( int = 0, int = 0, double = 0.0, double = 0.0 ); + + void setHeight( double ); // set Cylinder's height + double getHeight() const; // return Cylinder's height + + double getArea() const; // return Cylinder's area + double getVolume() const; // return Cylinder's volume + void print() const; // output Cylinder + +private: + double height; // Cylinder's height + +}; // end class Cylinder + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylindertest.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylindertest.cpp new file mode 100644 index 0000000..8fb49b9 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylindertest.cpp @@ -0,0 +1,70 @@ +// Fig. 9.24: cylindertest.cpp +// Testing class Cylinder. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include "cylinder.h" // Cylinder class definition + +int main() +{ + // instantiate Cylinder object + Cylinder cylinder( 12, 23, 2.5, 5.7 ); + + // display point coordinates + cout << "X coordinate is " << cylinder.getX() + << "\nY coordinate is " << cylinder.getY() + << "\nRadius is " << cylinder.getRadius() + << "\nHeight is " << cylinder.getHeight(); + + cylinder.setX( 2 ); // set new x-coordinate + cylinder.setY( 2 ); // set new y-coordinate + cylinder.setRadius( 4.25 ); // set new radius + cylinder.setHeight( 10 ); // set new height + + // display new cylinder value + cout << "\n\nThe new location and radius of circle are\n"; + cylinder.print(); + + // display floating-point values with 2 digits of precision + cout << fixed << setprecision( 2 ); + + // display cylinder's diameter + cout << "\n\nDiameter is " << cylinder.getDiameter(); + + // display cylinder's circumference + cout << "\nCircumference is " + << cylinder.getCircumference(); + + // display cylinder's area + cout << "\nArea is " << cylinder.getArea(); + + // display cylinder's volume + cout << "\nVolume is " << cylinder.getVolume(); + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.cpp new file mode 100644 index 0000000..70af44a --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.cpp @@ -0,0 +1,65 @@ +// Fig. 9.18: point3.cpp +// Point3 class member-function definitions. +#include + +using std::cout; + +#include "point3.h" // Point3 class definition + +// default constructor +Point3::Point3( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + // empty body + +} // end Point3 constructor + +// set x in coordinate pair +void Point3::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point3::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point3::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point3::getY() const +{ + return y; + +} // end function getY + +// output Point3 object +void Point3::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.h new file mode 100644 index 0000000..028f105 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.h @@ -0,0 +1,40 @@ +// Fig. 9.17: point3.h +// Point3 class definition represents an x-y coordinate pair. +#ifndef POINT3_H +#define POINT3_H + +class Point3 { + +public: + Point3( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point3 object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point3 + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/Fig10_05.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/Fig10_05.cpp new file mode 100644 index 0000000..c04f750 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/Fig10_05.cpp @@ -0,0 +1,75 @@ +// Fig. 10.5: fig10_05.cpp +// Aiming base-class and derived-class pointers at base-class +// and derived-class objects, respectively. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include "point.h" // Point class definition +#include "circle.h" // Circle class definition + +int main() +{ + Point point( 30, 50 ); + Point *pointPtr = 0; // base-class pointer + + Circle circle( 120, 89, 2.7 ); + Circle *circlePtr = 0; // derived-class pointer + + // set floating-point numeric formatting + cout << fixed << setprecision( 2 ); + + // output objects point and circle + cout << "Print point and circle objects:" + << "\nPoint: "; + point.print(); // invokes Point's print + cout << "\nCircle: "; + circle.print(); // invokes Circle's print + + // aim base-class pointer at base-class object and print + pointPtr = &point; + cout << "\n\nCalling print with base-class pointer to " + << "\nbase-class object invokes base-class print " + << "function:\n"; + pointPtr->print(); // invokes Point's print + + // aim derived-class pointer at derived-class object + // and print + circlePtr = &circle; + cout << "\n\nCalling print with derived-class pointer to " + << "\nderived-class object invokes derived-class " + << "print function:\n"; + circlePtr->print(); // invokes Circle's print + + // aim base-class pointer at derived-class object and print + pointPtr = &circle; + cout << "\n\nCalling print with base-class pointer to " + << "derived-class object\ninvokes base-class print " + << "function on that derived-class object\n"; + pointPtr->print(); // invokes Point's print + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.cpp new file mode 100644 index 0000000..91b708d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.cpp @@ -0,0 +1,74 @@ +// Fig. 10.4: circle.cpp +// Circle class member-function definitions. +#include + +using std::cout; + +#include "circle.h" // Circle class definition + +// default constructor +Circle::Circle( int xValue, int yValue, double radiusValue ) + : Point( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + +} // end Circle constructor + +// set radius +void Circle::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle::getDiameter() const +{ + return 2 * getRadius(); + +} // end function getDiameter + +// calculate and return circumference +double Circle::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// output Circle object +void Circle::print() const +{ + cout << "center = "; + Point::print(); // invoke Point's print function + cout << "; radius = " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.h new file mode 100644 index 0000000..42ec256 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/circle.h @@ -0,0 +1,44 @@ +// Fig. 10.3: circle.h +// Circle class contains x-y coordinate pair and radius. +#ifndef CIRCLE_H +#define CIRCLE_H + +#include "point.h" // Point class definition + +class Circle : public Point { + +public: + + // default constructor + Circle( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle object + +private: + double radius; // Circle's radius + +}; // end class Circle + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.cpp new file mode 100644 index 0000000..43a6b14 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.cpp @@ -0,0 +1,65 @@ +// Fig. 10.2: point.cpp +// Point class member-function definitions. +#include + +using std::cout; + +#include "point.h" // Point class definition + +// default constructor +Point::Point( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + // empty body + +} // end Point constructor + +// set x in coordinate pair +void Point::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point::getY() const +{ + return y; + +} // end function getY + +// output Point object +void Point::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.h new file mode 100644 index 0000000..6a2874e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_01_05/point.h @@ -0,0 +1,40 @@ +// Fig. 10.1: point.h +// Point class definition represents an x-y coordinate pair. +#ifndef POINT_H +#define POINT_H + +class Point { + +public: + Point( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/Fig10_06.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/Fig10_06.cpp new file mode 100644 index 0000000..8c3c122 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/Fig10_06.cpp @@ -0,0 +1,31 @@ +// Fig. 10.6: fig10_06.cpp +// Aiming a derived-class pointer at a base-class object. +#include "point.h" // Point class definition +#include "circle.h" // Circle class definition + +int main() +{ + Point point( 30, 50 ); + Circle *circlePtr = 0; + + // aim derived-class pointer at base-class object + circlePtr = &point; // Error: a Point is not a Circle + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.cpp new file mode 100644 index 0000000..2f3325e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.cpp @@ -0,0 +1,74 @@ +// Fig. 10.4: circle.cpp +// Circle class member-function definitions. +#include + +using std::cout; + +#include "circle.h" // Circle class definition + +// default constructor +Circle::Circle( int xValue, int yValue, double radiusValue ) + : Point( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + +} // end Circle constructor + +// set radius +void Circle::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle::getDiameter() const +{ + return getRadius() * 2; + +} // end function getDiameter + +// calculate and return circumference +double Circle::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// output Circle object +void Circle::print() const +{ + cout << "Center = "; + Point::print(); // invoke Point's print function + cout << "; Radius = " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.h new file mode 100644 index 0000000..fc22e5b --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/circle.h @@ -0,0 +1,44 @@ +// Fig. 10.3: circle.h +// Circle4 class contains x-y coordinate pair and radius. +#ifndef CIRCLE_H +#define CIRCLE_H + +#include "point.h" // Point class definition + +class Circle : public Point { + +public: + + // default constructor + Circle( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle object + +private: + double radius; // Circle's radius + +}; // end class Circle + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.cpp new file mode 100644 index 0000000..43a6b14 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.cpp @@ -0,0 +1,65 @@ +// Fig. 10.2: point.cpp +// Point class member-function definitions. +#include + +using std::cout; + +#include "point.h" // Point class definition + +// default constructor +Point::Point( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + // empty body + +} // end Point constructor + +// set x in coordinate pair +void Point::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point::getY() const +{ + return y; + +} // end function getY + +// output Point object +void Point::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.h new file mode 100644 index 0000000..6a2874e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_06/point.h @@ -0,0 +1,40 @@ +// Fig. 10.1: point.h +// Point class definition represents an x-y coordinate pair. +#ifndef POINT_H +#define POINT_H + +class Point { + +public: + Point( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.cpp new file mode 100644 index 0000000..582d5d9 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.cpp @@ -0,0 +1,74 @@ +// Fig. 10.4: circle.cpp +// Circle class member-function definitions. +#include + +using std::cout; + +#include "circle.h" // Circle class definition + +// default constructor +Circle::Circle( int xValue, int yValue, double radiusValue ) + : Point( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + +} // end Circle constructor + +// set radius +void Circle::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle::getDiameter() const +{ + return getRadius() * 2; + +} // end function getDiameter + +// calculate and return circumference +double Circle::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// output Circle object +void Circle::print() const +{ + cout << "Center = "; + Point::print(); // invoke Point's print function + cout << "; Radius = " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.h new file mode 100644 index 0000000..fc22e5b --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/circle.h @@ -0,0 +1,44 @@ +// Fig. 10.3: circle.h +// Circle4 class contains x-y coordinate pair and radius. +#ifndef CIRCLE_H +#define CIRCLE_H + +#include "point.h" // Point class definition + +class Circle : public Point { + +public: + + // default constructor + Circle( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + void print() const; // output Circle object + +private: + double radius; // Circle's radius + +}; // end class Circle + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/fig10_07.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/fig10_07.cpp new file mode 100644 index 0000000..184ed32 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/fig10_07.cpp @@ -0,0 +1,48 @@ +// Fig. 10.7: fig10_07.cpp +// Attempting to invoke derived-class-only member functions +// through a base-class pointer. +#include "point.h" // Point class definition +#include "circle.h" // Circle class definition + +int main() +{ + Point *pointPtr = 0; + Circle circle( 120, 89, 2.7 ); + + // aim base-class pointer at derived-class object + pointPtr = &circle; + + // invoke base-class member functions on derived-class + // object through base-class pointer + int x = pointPtr->getX(); + int y = pointPtr->getY(); + pointPtr->setX( 10 ); + pointPtr->setY( 10 ); + pointPtr->print(); + + // attempt to invoke derived-class-only member functions + // on derived-class object through base-class pointer + double radius = pointPtr->getRadius(); + pointPtr->setRadius( 33.33 ); + double diameter = pointPtr->getDiameter(); + double circumference = pointPtr->getCircumference(); + double area = pointPtr->getArea(); + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.cpp new file mode 100644 index 0000000..43a6b14 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.cpp @@ -0,0 +1,65 @@ +// Fig. 10.2: point.cpp +// Point class member-function definitions. +#include + +using std::cout; + +#include "point.h" // Point class definition + +// default constructor +Point::Point( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + // empty body + +} // end Point constructor + +// set x in coordinate pair +void Point::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point::getY() const +{ + return y; + +} // end function getY + +// output Point object +void Point::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.h new file mode 100644 index 0000000..6a2874e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_07/point.h @@ -0,0 +1,40 @@ +// Fig. 10.1: point.h +// Point class definition represents an x-y coordinate pair. +#ifndef POINT_H +#define POINT_H + +class Point { + +public: + Point( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + void print() const; // output Point object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/Fig10_10.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/Fig10_10.cpp new file mode 100644 index 0000000..be43be3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/Fig10_10.cpp @@ -0,0 +1,80 @@ +// Fig. 10.10: fig10_10.cpp +// Introducing polymorphism, virtual functions and dynamic +// binding. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include "point.h" // Point class definition +#include "circle.h" // Circle class definition + +int main() +{ + Point point( 30, 50 ); + Point *pointPtr = 0; + + Circle circle( 120, 89, 2.7 ); + Circle *circlePtr = 0; + + // set floating-point numeric formatting + cout << fixed << setprecision( 2 ); + + // output objects point and circle using static binding + cout << "Invoking print function on point and circle " + << "\nobjects with static binding " + << "\n\nPoint: "; + point.print(); // static binding + cout << "\nCircle: "; + circle.print(); // static binding + + // output objects point and circle using dynamic binding + cout << "\n\nInvoking print function on point and circle " + << "\nobjects with dynamic binding"; + + // aim base-class pointer at base-class object and print + pointPtr = &point; + cout << "\n\nCalling virtual function print with base-class" + << "\npointer to base-class object" + << "\ninvokes base-class print function:\n"; + pointPtr->print(); + + // aim derived-class pointer at derived-class + // object and print + circlePtr = &circle; + cout << "\n\nCalling virtual function print with " + << "\nderived-class pointer to derived-class object " + << "\ninvokes derived-class print function:\n"; + circlePtr->print(); + + // aim base-class pointer at derived-class object and print + pointPtr = &circle; + cout << "\n\nCalling virtual function print with base-class" + << "\npointer to derived-class object " + << "\ninvokes derived-class print function:\n"; + pointPtr->print(); // polymorphism: invokes circle's print + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.cpp new file mode 100644 index 0000000..550b3e2 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.cpp @@ -0,0 +1,74 @@ +// Fig. 10.11: circle.cpp +// Circle class member-function definitions. +#include + +using std::cout; + +#include "circle.h" // Circle class definition + +// default constructor +Circle::Circle( int xValue, int yValue, double radiusValue ) + : Point( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + +} // end Circle constructor + +// set radius +void Circle::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle::getDiameter() const +{ + return getRadius() * 2; + +} // end function getDiameter + +// calculate and return circumference +double Circle::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// calculate and return area +double Circle::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// output Circle object +void Circle::print() const +{ + cout << "Center = "; + Point::print(); // invoke Point's print function + cout << "; Radius = " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.h new file mode 100644 index 0000000..138a4b8 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/circle.h @@ -0,0 +1,44 @@ +// Fig. 10.10: circle.h +// Circle class contains x-y coordinate pair and radius. +#ifndef CIRCLE_H +#define CIRCLE_H + +#include "point.h" // Point class definition + +class Circle : public Point { + +public: + + // default constructor + Circle( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + double getArea() const; // return area + + virtual void print() const; // output Circle object + +private: + double radius; // Circle's radius + +}; // end class Circle + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.cpp new file mode 100644 index 0000000..43a6b14 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.cpp @@ -0,0 +1,65 @@ +// Fig. 10.2: point.cpp +// Point class member-function definitions. +#include + +using std::cout; + +#include "point.h" // Point class definition + +// default constructor +Point::Point( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + // empty body + +} // end Point constructor + +// set x in coordinate pair +void Point::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point::getY() const +{ + return y; + +} // end function getY + +// output Point object +void Point::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.h new file mode 100644 index 0000000..5cd7bd6 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_08_12/point.h @@ -0,0 +1,40 @@ +// Fig. 10.8: point.h +// Point class definition represents an x-y coordinate pair. +#ifndef POINT_H +#define POINT_H + +class Point { + +public: + Point( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + virtual void print() const; // output Point object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/Fig10_20.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/Fig10_20.cpp new file mode 100644 index 0000000..2ce0553 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/Fig10_20.cpp @@ -0,0 +1,120 @@ +// Fig. 10.20: fig10_20.cpp +// Driver for shape, point, circle, cylinder hierarchy. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include + +using std::vector; + +#include "shape.h" // Shape class definition +#include "point.h" // Point class definition +#include "circle.h" // Circle class definition +#include "cylinder.h" // Cylinder class definition + +void virtualViaPointer( const Shape * ); +void virtualViaReference( const Shape & ); + +int main() +{ + // set floating-point number format + cout << fixed << setprecision( 2 ); + + Point point( 7, 11 ); // create a Point + Circle circle( 22, 8, 3.5 ); // create a Circle + Cylinder cylinder( 10, 10, 3.3, 10 ); // create a Cylinder + + cout << point.getName() << ": "; // static binding + point.print(); // static binding + cout << '\n'; + + cout << circle.getName() << ": "; // static binding + circle.print(); // static binding + cout << '\n'; + + cout << cylinder.getName() << ": "; // static binding + cylinder.print(); // static binding + cout << "\n\n"; + + // create vector of three base-class pointers + vector< Shape * > shapeVector( 3 ); + + // aim shapeVector[0] at derived-class Point object + shapeVector[ 0 ] = &point; + + // aim shapeVector[1] at derived-class Circle object + shapeVector[ 1 ] = &circle; + + // aim shapeVector[2] at derived-class Cylinder object + shapeVector[ 2 ] = &cylinder; + + // loop through shapeVector and call virtualViaPointer + // to print the shape name, attributes, area and volume + // of each object using dynamic binding + cout << "\nVirtual function calls made off " + << "base-class pointers:\n\n"; + + for ( int i = 0; i < shapeVector.size(); i++ ) + virtualViaPointer( shapeVector[ i ] ); + + // loop through shapeVector and call virtualViaReference + // to print the shape name, attributes, area and volume + // of each object using dynamic binding + cout << "\nVirtual function calls made off " + << "base-class references:\n\n"; + + for ( int j = 0; j < shapeVector.size(); j++ ) + virtualViaReference( *shapeVector[ j ] ); + + return 0; + +} // end main + +// make virtual function calls off a base-class pointer +// using dynamic binding +void virtualViaPointer( const Shape *baseClassPtr ) +{ + cout << baseClassPtr->getName() << ": "; + + baseClassPtr->print(); + + cout << "\narea is " << baseClassPtr->getArea() + << "\nvolume is " << baseClassPtr->getVolume() + << "\n\n"; + +} // end function virtualViaPointer + +// make virtual function calls off a base-class reference +// using dynamic binding +void virtualViaReference( const Shape &baseClassRef ) +{ + cout << baseClassRef.getName() << ": "; + + baseClassRef.print(); + + cout << "\narea is " << baseClassRef.getArea() + << "\nvolume is " << baseClassRef.getVolume() << "\n\n"; + +} // end function virtualViaReference + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.cpp new file mode 100644 index 0000000..b8f6f59 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.cpp @@ -0,0 +1,81 @@ +// Fig. 10.17: circle.cpp +// Circle class member-function definitions. +#include + +using std::cout; + +#include "circle.h" // Circle class definition + +// default constructor +Circle::Circle( int xValue, int yValue, double radiusValue ) + : Point( xValue, yValue ) // call base-class constructor +{ + setRadius( radiusValue ); + +} // end Circle constructor + +// set radius +void Circle::setRadius( double radiusValue ) +{ + radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); + +} // end function setRadius + +// return radius +double Circle::getRadius() const +{ + return radius; + +} // end function getRadius + +// calculate and return diameter +double Circle::getDiameter() const +{ + return 2 * getRadius(); + +} // end function getDiameter + +// calculate and return circumference +double Circle::getCircumference() const +{ + return 3.14159 * getDiameter(); + +} // end function getCircumference + +// override virtual function getArea: return area of Circle +double Circle::getArea() const +{ + return 3.14159 * getRadius() * getRadius(); + +} // end function getArea + +// override virutual function getName: return name of Circle +string Circle::getName() const +{ + return "Circle"; + +} // end function getName + +// override virtual function print: output Circle object +void Circle::print() const +{ + cout << "center is "; + Point::print(); // invoke Point's print function + cout << "; radius is " << getRadius(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.h new file mode 100644 index 0000000..6d6877c --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/circle.h @@ -0,0 +1,47 @@ +// Fig. 10.16: circle.h +// Circle class contains x-y coordinate pair and radius. +#ifndef CIRCLE_H +#define CIRCLE_H + +#include "point.h" // Point class definition + +class Circle : public Point { + +public: + + // default constructor + Circle( int = 0, int = 0, double = 0.0 ); + + void setRadius( double ); // set radius + double getRadius() const; // return radius + + double getDiameter() const; // return diameter + double getCircumference() const; // return circumference + virtual double getArea() const; // return area + + // return name of shape (i.e., "Circle") + virtual string getName() const; + + virtual void print() const; // output Circle object + +private: + double radius; // Circle's radius + +}; // end class Circle + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.cpp new file mode 100644 index 0000000..7c51113 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.cpp @@ -0,0 +1,75 @@ +// Fig. 10.19: cylinder.cpp +// Cylinder class inherits from class Circle. +#include + +using std::cout; + +#include "cylinder.h" // Cylinder class definition + +// default constructor +Cylinder::Cylinder( int xValue, int yValue, double radiusValue, + double heightValue ) + : Circle( xValue, yValue, radiusValue ) +{ + setHeight( heightValue ); + +} // end Cylinder constructor + +// set Cylinder's height +void Cylinder::setHeight( double heightValue ) +{ + height = ( heightValue < 0.0 ? 0.0 : heightValue ); + +} // end function setHeight + +// get Cylinder's height +double Cylinder::getHeight() const +{ + return height; + +} // end function getHeight + +// override virtual function getArea: return Cylinder area +double Cylinder::getArea() const +{ + return 2 * Circle::getArea() + // code reuse + getCircumference() * getHeight(); + +} // end function getArea + +// override virtual function getVolume: return Cylinder volume +double Cylinder::getVolume() const +{ + return Circle::getArea() * getHeight(); // code reuse + +} // end function getVolume + +// override virtual function getName: return name of Cylinder +string Cylinder::getName() const +{ + return "Cylinder"; + +} // end function getName + +// override virtual function print: output Cylinder object +void Cylinder::print() const +{ + Circle::print(); // code reuse + cout << "; height is " << getHeight(); + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.h new file mode 100644 index 0000000..f20d624 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/cylinder.h @@ -0,0 +1,46 @@ +// Fig. 10.18: cylinder.h +// Cylinder class inherits from class Circle. +#ifndef CYLINDER_H +#define CYLINDER_H + +#include "circle.h" // Circle class definition + +class Cylinder : public Circle { + +public: + + // default constructor + Cylinder( int = 0, int = 0, double = 0.0, double = 0.0 ); + + void setHeight( double ); // set Cylinder's height + double getHeight() const; // return Cylinder's height + + virtual double getArea() const; // return Cylinder's area + virtual double getVolume() const; // return Cylinder's volume + + // return name of shape (i.e., "Cylinder" ) + virtual string getName() const; + + virtual void print() const; // output Cylinder + +private: + double height; // Cylinder's height + +}; // end class Cylinder + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.cpp new file mode 100644 index 0000000..3f63c81 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.cpp @@ -0,0 +1,72 @@ +// Fig. 10.15: point.cpp +// Point class member-function definitions. +#include + +using std::cout; + +#include "point.h" // Point class definition + +// default constructor +Point::Point( int xValue, int yValue ) + : x( xValue ), y( yValue ) +{ + // empty body + +} // end Point constructor + +// set x in coordinate pair +void Point::setX( int xValue ) +{ + x = xValue; // no need for validation + +} // end function setX + +// return x from coordinate pair +int Point::getX() const +{ + return x; + +} // end function getX + +// set y in coordinate pair +void Point::setY( int yValue ) +{ + y = yValue; // no need for validation + +} // end function setY + +// return y from coordinate pair +int Point::getY() const +{ + return y; + +} // end function getY + +// override pure virtual function getName: return name of Point +string Point::getName() const +{ + return "Point"; + +} // end function getName + +// override pure virtual function print: output Point object +void Point::print() const +{ + cout << '[' << getX() << ", " << getY() << ']'; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.h new file mode 100644 index 0000000..264b37b --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/point.h @@ -0,0 +1,45 @@ +// Fig. 10.14: point.h +// Point class definition represents an x-y coordinate pair. +#ifndef POINT_H +#define POINT_H + +#include "shape.h" // Shape class definition + +class Point : public Shape { + +public: + Point( int = 0, int = 0 ); // default constructor + + void setX( int ); // set x in coordinate pair + int getX() const; // return x from coordinate pair + + void setY( int ); // set y in coordinate pair + int getY() const; // return y from coordinate pair + + // return name of shape (i.e., "Point" ) + virtual string getName() const; + + virtual void print() const; // output Point object + +private: + int x; // x part of coordinate pair + int y; // y part of coordinate pair + +}; // end class Point + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.cpp new file mode 100644 index 0000000..125ea79 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.cpp @@ -0,0 +1,36 @@ +// Fig. 10.13: shape.cpp +// Shape class member-function definitions. +#include + +using std::cout; + +#include "shape.h" // Shape class definition + +// return area of shape; 0.0 by default +double Shape::getArea() const +{ + return 0.0; + +} // end function getArea + +// return volume of shape; 0.0 by default +double Shape::getVolume() const +{ + return 0.0; + +} // end function getVolume + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.h new file mode 100644 index 0000000..0c929a5 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_13_20/shape.h @@ -0,0 +1,41 @@ +// Fig. 10.12: shape.h +// Shape abstract-base-class definition. +#ifndef SHAPE_H +#define SHAPE_H + +#include // C++ standard string class + +using std::string; + +class Shape { + +public: + + // virtual function that returns shape area + virtual double getArea() const; + + // virtual function that returns shape volume + virtual double getVolume() const; + + // pure virtual functions; overridden in derived classes + virtual string getName() const = 0; // return shape name + virtual void print() const = 0; // output shape + +}; // end class Shape + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.cpp new file mode 100644 index 0000000..2052d48 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.cpp @@ -0,0 +1,65 @@ +// Fig. 10.32: baseplus.cpp +// BasePlusCommissionEmployee member-function definitions. +#include + +using std::cout; + +#include "baseplus.h" + +// constructor for class BasePlusCommissionEmployee +BasePlusCommissionEmployee::BasePlusCommissionEmployee( + const string &first, const string &last, + const string &socialSecurityNumber, + double baseSalaryAmount, + double grossSalesAmount, + double rate ) + : CommissionEmployee( first, last, socialSecurityNumber, + grossSalesAmount, rate ) +{ + setBaseSalary( baseSalaryAmount ); + +} // end BasePlusCommissionEmployee constructor + +// set base-salaried commission worker's wage +void BasePlusCommissionEmployee::setBaseSalary( double salary ) +{ + baseSalary = salary < 0.0 ? 0.0 : salary; + +} // end function setBaseSalary + +// return base-salaried commission worker's base salary +double BasePlusCommissionEmployee::getBaseSalary() const +{ + return baseSalary; + +} // end function getBaseSalary + +// return base-salaried commission worker's earnings +double BasePlusCommissionEmployee::earnings() const +{ + return getBaseSalary() + CommissionEmployee::earnings(); + +} // end function earnings + +// print base-salaried commission worker's name +void BasePlusCommissionEmployee::print() const +{ + cout << "\nbase-salaried commission worker: "; + Employee::print(); // code reuse + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.h new file mode 100644 index 0000000..d049914 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/baseplus.h @@ -0,0 +1,40 @@ +// Fig. 10.31: baseplus.h +// BasePlusCommissionEmployee class derived from Employee. +#ifndef BASEPLUS_H +#define BASEPLUS_H + +#include "commission.h" // Employee class definition + +class BasePlusCommissionEmployee : public CommissionEmployee { + +public: + BasePlusCommissionEmployee( const string &, const string &, + const string &, double = 0.0, double = 0.0, double = 0.0 ); + + void setBaseSalary( double ); + double getBaseSalary() const; + + virtual double earnings() const; + virtual void print() const; + +private: + double baseSalary; // base salary per week + +}; // end class BasePlusCommissionEmployee + +#endif // BASEPLUS_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.cpp new file mode 100644 index 0000000..2d05932 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.cpp @@ -0,0 +1,76 @@ +// Fig. 10.30: commission.cpp +// CommissionEmployee class member-function definitions. +#include + +using std::cout; + +#include "commission.h" // Commission class + +// CommissionEmployee constructor +CommissionEmployee::CommissionEmployee( const string &first, + const string &last, const string &socialSecurityNumber, + double grossWeeklySales, double percent ) + : Employee( first, last, socialSecurityNumber ) +{ + setGrossSales( grossWeeklySales ); + setCommissionRate( percent ); + +} // end CommissionEmployee constructor + +// return commission worker's rate +double CommissionEmployee::getCommissionRate() const +{ + return commissionRate; + +} // end function getCommissionRate + +// return commission worker's gross sales amount +double CommissionEmployee::getGrossSales() const +{ + return grossSales; + +} // end function getGrossSales + +// set commission worker's weekly base salary +void CommissionEmployee::setGrossSales( double sales ) +{ + grossSales = sales < 0.0 ? 0.0 : sales; + +} // end function setGrossSales + +// set commission worker's commission +void CommissionEmployee::setCommissionRate( double rate ) +{ + commissionRate = ( rate > 0.0 && rate < 1.0 ) ? rate : 0.0; + +} // end function setCommissionRate + +// calculate commission worker's earnings +double CommissionEmployee::earnings() const +{ + return getCommissionRate() * getGrossSales(); + +} // end function earnings + +// print commission worker's name +void CommissionEmployee::print() const +{ + cout << "\ncommission employee: "; + Employee::print(); // code reuse + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.h new file mode 100644 index 0000000..423bd03 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/commission.h @@ -0,0 +1,44 @@ +// Fig. 10.29: commission.h +// CommissionEmployee class derived from Employee. +#ifndef COMMISSION_H +#define COMMISSION_H + +#include "employee.h" // Employee class definition + +class CommissionEmployee : public Employee { + +public: + CommissionEmployee( const string &, const string &, + const string &, double = 0.0, double = 0.0 ); + + void setCommissionRate( double ); + double getCommissionRate() const; + + void setGrossSales( double ); + double getGrossSales() const; + + virtual double earnings() const; + virtual void print() const; + +private: + double grossSales; // gross weekly sales + double commissionRate; // commission percentage + +}; // end class CommissionEmployee + +#endif // COMMISSION_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.cpp new file mode 100644 index 0000000..151aa58 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.cpp @@ -0,0 +1,86 @@ +// Fig. 10.24: employee.cpp +// Abstract-base-class Employee member-function definitions. +// Note: No definitions are given for pure virtual functions. +#include + +using std::cout; +using std::endl; + +#include "employee.h" // Employee class definition + +// constructor +Employee::Employee( const string &first, const string &last, + const string &SSN ) + : firstName( first ), + lastName( last ), + socialSecurityNumber( SSN ) +{ + // empty body + +} // end Employee constructor + +// return first name +string Employee::getFirstName() const +{ + return firstName; + +} // end function getFirstName + +// return last name +string Employee::getLastName() const +{ + return lastName; + +} // end function getLastName + +// return social security number +string Employee::getSocialSecurityNumber() const +{ + return socialSecurityNumber; + +} // end function getSocialSecurityNumber + +// set first name +void Employee::setFirstName( const string &first ) +{ + firstName = first; + +} // end function setFirstName + +// set last name +void Employee::setLastName( const string &last ) +{ + lastName = last; + +} // end function setLastName + +// set social security number +void Employee::setSocialSecurityNumber( const string &number ) +{ + socialSecurityNumber = number; // should validate + +} // end function setSocialSecurityNumber + +// print Employee's information +void Employee::print() const +{ + cout << getFirstName() << ' ' << getLastName() + << "\nsocial security number: " + << getSocialSecurityNumber() << endl; + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.h new file mode 100644 index 0000000..50ab131 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/employee.h @@ -0,0 +1,50 @@ +// Fig. 10.23: employee.h +// Employee abstract base class. +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +#include // C++ standard string class + +using std::string; + +class Employee { + +public: + Employee( const string &, const string &, const string & ); + + void setFirstName( const string & ); + string getFirstName() const; + + void setLastName( const string & ); + string getLastName() const; + + void setSocialSecurityNumber( const string & ); + string getSocialSecurityNumber() const; + + // pure virtual function makes Employee abstract base class + virtual double earnings() const = 0; // pure virtual + virtual void print() const; // virtual + +private: + string firstName; + string lastName; + string socialSecurityNumber; + +}; // end class Employee + +#endif // EMPLOYEE_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/fig10_33.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/fig10_33.cpp new file mode 100644 index 0000000..c8e9761 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/fig10_33.cpp @@ -0,0 +1,100 @@ +// Fig. 10.33: fig10_33.cpp +// Driver for Employee hierarchy. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include + +using std::vector; + +#include + +#include "employee.h" // Employee base class +#include "salaried.h" // SalariedEmployee class +#include "commission.h" // CommissionEmployee class +#include "baseplus.h" // BasePlusCommissionEmployee class +#include "hourly.h" // HourlyEmployee class + +int main() +{ + // set floating-point output formatting + cout << fixed << setprecision( 2 ); + + // create vector employees + vector < Employee * > employees( 4 ); + + // initialize vector with Employees + employees[ 0 ] = new SalariedEmployee( "John", "Smith", + "111-11-1111", 800.00 ); + employees[ 1 ] = new CommissionEmployee( "Sue", "Jones", + "222-22-2222", 10000, .06 ); + employees[ 2 ] = new BasePlusCommissionEmployee( "Bob", + "Lewis", "333-33-3333", 300, 5000, .04 ); + employees[ 3 ] = new HourlyEmployee( "Karen", "Price", + "444-44-4444", 16.75, 40 ); + + // generically process each element in vector employees + for ( int i = 0; i < employees.size(); i++ ) { + + // output employee information + employees[ i ]->print(); + + // downcast pointer + BasePlusCommissionEmployee *commissionPtr = + dynamic_cast < BasePlusCommissionEmployee * > + ( employees[ i ] ); + + // determine whether element points to base-salaried + // commission worker + if ( commissionPtr != 0 ) { + cout << "old base salary: $" + << commissionPtr->getBaseSalary() << endl; + commissionPtr->setBaseSalary( + 1.10 * commissionPtr->getBaseSalary() ); + cout << "new base salary with 10% increase is: $" + << commissionPtr->getBaseSalary() << endl; + + } // end if + + cout << "earned $" << employees[ i ]->earnings() << endl; + + } // end for + + // release memory held by vector employees + for ( int j = 0; j < employees.size(); j++ ) { + + // output class name + cout << "\ndeleting object of " + << typeid( *employees[ j ] ).name(); + + delete employees[ j ]; + + } // end for + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.cpp new file mode 100644 index 0000000..1a517e1 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.cpp @@ -0,0 +1,80 @@ +// Fig. 10.28: hourly.cpp +// HourlyEmployee class member-function definitions. +#include + +using std::cout; + +#include "hourly.h" + +// constructor for class HourlyEmployee +HourlyEmployee::HourlyEmployee( const string &first, + const string &last, const string &socialSecurityNumber, + double hourlyWage, double hoursWorked ) + : Employee( first, last, socialSecurityNumber ) +{ + setWage( hourlyWage ); + setHours( hoursWorked ); + +} // end HourlyEmployee constructor + +// set hourly worker's wage +void HourlyEmployee::setWage( double wageAmount ) +{ + wage = wageAmount < 0.0 ? 0.0 : wageAmount; + +} // end function setWage + +// set hourly worker's hours worked +void HourlyEmployee::setHours( double hoursWorked ) +{ + hours = ( hoursWorked >= 0.0 && hoursWorked <= 168.0 ) ? + hoursWorked : 0.0; + +} // end function setHours + +// return hours worked +double HourlyEmployee::getHours() const +{ + return hours; + +} // end function getHours + +// return wage +double HourlyEmployee::getWage() const +{ + return wage; + +} // end function getWage + +// get hourly worker's pay +double HourlyEmployee::earnings() const +{ + if ( hours <= 40 ) // no overtime + return wage * hours; + else // overtime is paid at wage * 1.5 + return 40 * wage + ( hours - 40 ) * wage * 1.5; + +} // end function earnings + +// print hourly worker's information +void HourlyEmployee::print() const +{ + cout << "\nhourly employee: "; + Employee::print(); // code reuse + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.h new file mode 100644 index 0000000..a74d4ce --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/hourly.h @@ -0,0 +1,44 @@ +// Fig. 10.27: hourly.h +// HourlyEmployee class definition. +#ifndef HOURLY_H +#define HOURLY_H + +#include "employee.h" // Employee class definition + +class HourlyEmployee : public Employee { + +public: + HourlyEmployee( const string &, const string &, + const string &, double = 0.0, double = 0.0); + + void setWage( double ); + double getWage() const; + + void setHours( double ); + double getHours() const; + + virtual double earnings() const; + virtual void print() const; + +private: + double wage; // wage per hour + double hours; // hours worked for week + +}; // end class HourlyEmployee + +#endif // HOURLY_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.cpp b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.cpp new file mode 100644 index 0000000..3b9ed98 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.cpp @@ -0,0 +1,61 @@ +// Fig. 10.26: salaried.cpp +// SalariedEmployee class member-function definitions. +#include + +using std::cout; + +#include "salaried.h" // SalariedEmployee class definition + +// SalariedEmployee constructor +SalariedEmployee::SalariedEmployee( const string &first, + const string &last, const string &socialSecurityNumber, + double salary ) + : Employee( first, last, socialSecurityNumber ) +{ + setWeeklySalary( salary ); + +} // end SalariedEmployee constructor + +// set salaried worker's salary +void SalariedEmployee::setWeeklySalary( double salary ) +{ + weeklySalary = salary < 0.0 ? 0.0 : salary; + +} // end function setWeeklySalary + +// calculate salaried worker's pay +double SalariedEmployee::earnings() const +{ + return getWeeklySalary(); + +} // end function earnings + +// return salaried worker's salary +double SalariedEmployee::getWeeklySalary() const +{ + return weeklySalary; + +} // end function getWeeklySalary + +// print salaried worker's name +void SalariedEmployee::print() const +{ + cout << "\nsalaried employee: "; + Employee::print(); // code reuse + +} // end function print + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.h b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.h new file mode 100644 index 0000000..80b2595 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/2_ch10/fig10_23_33/salaried.h @@ -0,0 +1,40 @@ +// Fig. 10.25: salaried.h +// SalariedEmployee class derived from Employee. +#ifndef SALARIED_H +#define SALARIED_H + +#include "employee.h" // Employee class definition + +class SalariedEmployee : public Employee { + +public: + SalariedEmployee( const string &, const string &, + const string &, double = 0.0 ); + + void setWeeklySalary( double ); + double getWeeklySalary() const; + + virtual double earnings() const; + virtual void print() const; // "salaried employee: " + +private: + double weeklySalary; + +}; // end class SalariedEmployee + +#endif // SALARIED_H + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_01.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_01.CPP new file mode 100644 index 0000000..2c69128 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_01.CPP @@ -0,0 +1,68 @@ +// Fig. 16.1: fig16_01.cpp +// Demonstrating string assignment and concatenation. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string string1( "cat" ); + string string2; + string string3; + + string2 = string1; // assign string1 to string2 + string3.assign( string1 ); // assign string1 to string3 + cout << "string1: " << string1 << "\nstring2: " << string2 + << "\nstring3: " << string3 << "\n\n"; + + // modify string2 and string3 + string2[ 0 ] = string3[ 2 ] = 'r'; + + cout << "After modification of string2 and string3:\n" + << "string1: " << string1 << "\nstring2: " << string2 + << "\nstring3: "; + + // demonstrating member function at + for ( int i = 0; i < string3.length(); i++ ) + cout << string3.at( i ); + + // declare string4 and string5 + string string4( string1 + "apult" ); + string string5; + + // overloaded += + string3 += "pet"; // create "carpet" + string1.append( "acomb" ); // create "catacomb" + + // append subscript locations 4 through end of string1 to + // create string "comb" (string5 was initially empty) + string5.append( string1, 4, string1.length() ); + + cout << "\n\nAfter concatenation:\nstring1: " << string1 + << "\nstring2: " << string2 << "\nstring3: " + << string3 << "\nstring4: " << string4 + << "\nstring5: " << string5 << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_02.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_02.CPP new file mode 100644 index 0000000..37fa669 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_02.CPP @@ -0,0 +1,97 @@ +// Fig. 16.2: fig16_02.cpp +// Demonstrating string comparison capabilities. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string string1( "Testing the comparison functions." ); + string string2( "Hello" ); + string string3( "stinger" ); + string string4( string2 ); + + cout << "string1: " << string1 << "\nstring2: " << string2 + << "\nstring3: " << string3 << "\nstring4: " << string4 + << "\n\n"; + + // comparing string1 and string4 + if ( string1 == string4 ) + cout << "string1 == string4\n"; + else { // string1 != string4 + if ( string1 > string4 ) + cout << "string1 > string4\n"; + else // string1 < string4 + cout << "string1 < string4\n"; + } + + // comparing string1 and string2 + int result = string1.compare( string2 ); + + if ( result == 0 ) + cout << "string1.compare( string2 ) == 0\n"; + else // result != 0 + if ( result > 0 ) + cout << "string1.compare( string2 ) > 0\n"; + else // result < 0 + cout << "string1.compare( string2 ) < 0\n"; + + // comparing string1 (elements 2-5) and string3 (elements 0-5) + result = string1.compare( 2, 5, string3, 0, 5 ); + + if ( result == 0 ) + cout << "string1.compare( 2, 5, string3, 0, 5 ) == 0\n"; + else // result != 0 + if ( result > 0 ) + cout << "string1.compare( 2, 5, string3, 0, 5 ) > 0\n"; + else // result < 0 + cout << "string1.compare( 2, 5, string3, 0, 5 ) < 0\n"; + + // comparing string2 and string4 + result = string4.compare( 0, string2.length(), string2 ); + + if ( result == 0 ) + cout << "string4.compare( 0, string2.length(), " + << "string2 ) == 0" << endl; + else // result != 0 + if ( result > 0 ) + cout << "string4.compare( 0, string2.length(), " + << "string2 ) > 0" << endl; + else // result < 0 + cout << "string4.compare( 0, string2.length(), " + << "string2 ) < 0" << endl; + + // comparing string2 and string4 + result = string2.compare( 0, 3, string4 ); + + if ( result == 0 ) + cout << "string2.compare( 0, 3, string4 ) == 0" << endl; + else // result != 0 + if ( result > 0 ) + cout << "string2.compare( 0, 3, string4 ) > 0" << endl; + else // result < 0 + cout << "string2.compare( 0, 3, string4 ) < 0" << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_03.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_03.CPP new file mode 100644 index 0000000..40fd024 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_03.CPP @@ -0,0 +1,38 @@ +// Fig. 16.3: fig16_03.cpp +// Demonstrating string member function substr. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string string1( "The airplane landed on time." ); + + // retrieve substring "plane" which + // begins at subscript 7 and consists of 5 elements + cout << string1.substr( 7, 5 ) << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ + diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_04.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_04.CPP new file mode 100644 index 0000000..0747743 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_04.CPP @@ -0,0 +1,43 @@ +// Fig. 16.4: fig16_04.cpp +// Using the swap function to swap two strings. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string first( "one" ); + string second( "two" ); + + // output strings + cout << "Before swap:\n first: " << first + << "\nsecond: " << second; + + first.swap( second ); // swap strings + + cout << "\n\nAfter swap:\n first: " << first + << "\nsecond: " << second << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_05.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_05.CPP new file mode 100644 index 0000000..6fc20c4 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_05.CPP @@ -0,0 +1,75 @@ +// Fig. 16.5: fig16_05.cpp +// Demonstrating member functions related to size and capacity. +#include + +using std::cout; +using std::endl; +using std::cin; +using std::boolalpha; + +#include + +using std::string; + +void printStatistics( const string & ); + +int main() +{ + string string1; + + cout << "Statistics before input:\n" << boolalpha; + printStatistics( string1 ); + + // read in "tomato" + cout << "\n\nEnter a string: "; + cin >> string1; // delimited by whitespace + cout << "The string entered was: " << string1; + + cout << "\nStatistics after input:\n"; + printStatistics( string1 ); + + // read in "soup" + cin >> string1; // delimited by whitespace + cout << "\n\nThe remaining string is: " << string1 << endl; + printStatistics( string1 ); + + // append 46 characters to string1 + string1 += "1234567890abcdefghijklmnopqrstuvwxyz1234567890"; + cout << "\n\nstring1 is now: " << string1 << endl; + printStatistics( string1 ); + + // add 10 elements to string1 + string1.resize( string1.length() + 10 ); + cout << "\n\nStats after resizing by (length + 10):\n"; + printStatistics( string1 ); + + cout << endl; + return 0; + +} // end main + +// display string statistics +void printStatistics( const string &stringRef ) +{ + cout << "capacity: " << stringRef.capacity() + << "\nmax size: " << stringRef.max_size() + << "\nsize: " << stringRef.size() + << "\nlength: " << stringRef.length() + << "\nempty: " << stringRef.empty(); + +} // end printStatistics + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_06.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_06.CPP new file mode 100644 index 0000000..10a73aa --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_06.CPP @@ -0,0 +1,71 @@ +// Fig. 16.6: fig16_06.cpp +// Demonstrating the string find member functions. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string string1( "noon is 12 p.m." ); + int location; + + // find "is" at location 5 + cout << "Original string:\n" << string1 + << "\n\n(find) \"is\" was found at: " + << string1.find( "is" ) + << "\n(rfind) \"is\" was found at: " + << string1.rfind( "is" ); + + // find 'o' at location 1 + location = string1.find_first_of( "misop" ); + + cout << "\n\n(find_first_of) found '" << string1[ location ] + << "' from the group \"misop\" at: " + << location; + + // find 'm' at location 13 + location = string1.find_last_of( "misop" ); + cout << "\n\n(find_last_of) found '" << string1[ location ] + << "' from the group \"misop\" at: " + << location; + + // find '1' at location 8 + location = string1.find_first_not_of( "noi spm" ); + cout << "\n\n(find_first_not_of) '" << string1[ location ] + << "' is not contained in \"noi spm\" and was found at:" + << location; + + // find '.' at location 12 + location = string1.find_first_not_of( "12noi spm" ); + cout << "\n\n(find_first_not_of) '" << string1[ location ] + << "' is not contained in \"12noi spm\" and was " + << "found at:" << location << endl; + + // search for characters not in string1 + location = string1.find_first_not_of( "noon is 12 p.m." ); + cout << "\nfind_first_not_of(\"noon is 12 p.m.\")" + << " returned: " << location << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_07.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_07.CPP new file mode 100644 index 0000000..c09a04f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_07.CPP @@ -0,0 +1,69 @@ +// Fig. 16.7: fig16_07.cpp +// Demonstrating string member functions erase and replace. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + // compiler concatenates all parts into one string + string string1( "The values in any left subtree" + "\nare less than the value in the" + "\nparent node and the values in" + "\nany right subtree are greater" + "\nthan the value in the parent node" ); + + cout << "Original string:\n" << string1 << endl << endl; + + // remove all characters from (and including) location 62 + // through the end of string1 + string1.erase( 62 ); + + // output new string + cout << "Original string after erase:\n" << string1 + << "\n\nAfter first replacement:\n"; + + // replace all spaces with period + int position = string1.find( " " ); + + while ( position != string::npos ) { + string1.replace( position, 1, "." ); + position = string1.find( " ", position + 1 ); + } // end while + + cout << string1 << "\n\nAfter second replacement:\n"; + + // replace all periods with two semicolons + // NOTE: this will overwrite characters + position = string1.find( "." ); + + while ( position != string::npos ) { + string1.replace( position, 2, "xxxxx;;yyy", 5, 2 ); + position = string1.find( ".", position + 1 ); + } // end while + + cout << string1 << endl; + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ + diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_08.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_08.CPP new file mode 100644 index 0000000..98bc3d9 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_08.CPP @@ -0,0 +1,50 @@ +// Fig. 16.8: fig16_08.cpp +// Demonstrating class string insert member functions. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string string1( "beginning end" ); + string string2( "middle " ); + string string3( "12345678" ); + string string4( "xx" ); + + cout << "Initial strings:\nstring1: " << string1 + << "\nstring2: " << string2 << "\nstring3: " << string3 + << "\nstring4: " << string4 << "\n\n"; + + // insert "middle" at location 10 in string1 + string1.insert( 10, string2 ); + + // insert "xx" at location 3 in string3 + string3.insert( 3, string4, 0, string::npos ); + + cout << "Strings after insert:\nstring1: " << string1 + << "\nstring2: " << string2 << "\nstring3: " << string3 + << "\nstring4: " << string4 << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_09.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_09.CPP new file mode 100644 index 0000000..d94ff92 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_09.CPP @@ -0,0 +1,57 @@ +// Fig. 16.9: fig16_09.cpp +// Converting to C-style strings. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string string1( "STRINGS" ); + const char *ptr1 = 0; + int length = string1.length(); + char *ptr2 = new char[ length + 1 ]; // including null + + // copy characters from string1 into allocated memory + string1.copy( ptr2, length, 0 ); + ptr2[ length ] = '\0'; // add null terminator + + // output + cout << "string s is " << string1 + << "\nstring1 converted to a C-Style string is " + << string1.c_str() << "\nptr1 is "; + + // Assign to pointer ptr1 the const char * returned by + // function data(). NOTE: this is a potentially dangerous + // assignment. If string1 is modified, pointer ptr1 can + // become invalid. + ptr1 = string1.data(); + + // output each character using pointer + for ( int i = 0; i < length; i++ ) + cout << *( ptr1 + i ); // use pointer arithmetic + + cout << "\nptr2 is " << ptr2 << endl; + delete [] ptr2; + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_10.CPP b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_10.CPP new file mode 100644 index 0000000..c65136e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/FIG15_10.CPP @@ -0,0 +1,44 @@ +// Fig. 16.10: fig16_10.cpp +// Using an iterator to output a string. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string string1( "Testing iterators" ); + string::const_iterator iterator1 = string1.begin(); + + cout << "string1 = " << string1 + << "\n(Using iterator iterator1) string1 is: "; + + // iterate through string + while ( iterator1 != string1.end() ) { + cout << *iterator1; // dereference iterator to get char + ++iterator1; // advance iterator to next char + } // end while + + cout << endl; + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_11.cpp b/Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_11.cpp new file mode 100644 index 0000000..1b55f71 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_11.cpp @@ -0,0 +1,59 @@ +// Fig. 16.11: fig16_11.cpp +// Using a dynamically allocated ostringstream object. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +#include + +using std::ostringstream; + +int main() +{ + ostringstream outputString; // create ostringstream instance + + string string1( "Output of several data types " ); + string string2( "to an ostringstream object:" ); + string string3( "\n double: " ); + string string4( "\n int: " ); + string string5( "\naddress of int: " ); + + double double1 = 123.4567; + int integer = 22; + + // output strings, double and int to outputString + outputString << string1 << string2 << string3 << double1 + << string4 << integer << string5 << &integer; + + // call str to output contents + cout << "outputString contains:\n" << outputString.str(); + + // add additional characters and call str to output string + outputString << "\nmore characters added"; + cout << "\n\nafter additional stream insertions,\n" + << "outputString contains:\n" << outputString.str() + << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_12.cpp b/Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_12.cpp new file mode 100644 index 0000000..93bb65b --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/3_ch15/Fig15_12.cpp @@ -0,0 +1,65 @@ +// Fig. 16.12: fig16_12.cpp +// Demonstrating input from an istringstream object. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +#include + +using std::istringstream; + +int main() +{ + string input( "Input test 123 4.7 A" ); + istringstream inputString( input ); + string string1; + string string2; + int integer; + double double1; + char character; + + inputString >> string1 >> string2 >> integer >> double1 + >> character; + + cout << "The following items were extracted\n" + << "from the istringstream object:" + << "\nstring: " << string1 + << "\nstring: " << string2 + << "\n int: " << integer + << "\ndouble: " << double1 + << "\n char: " << character; + + // attempt to read from empty stream + long value; + + inputString >> value; + + // test stream results + if ( inputString.good() ) + cout << "\n\nlong value is: " << value << endl; + else + cout << "\n\ninputString is empty" << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_04.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_04.cpp new file mode 100644 index 0000000..f132e11 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_04.cpp @@ -0,0 +1,61 @@ +// Fig. 14.4: fig14_04.cpp +// Create a sequential file. +#include + +using std::cout; +using std::cin; +using std::ios; +using std::cerr; +using std::endl; + +#include + +using std::ofstream; + +#include // exit prototype + +int main() +{ + // ofstream constructor opens file + ofstream outClientFile( "clients.dat", ios::out ); + + // exit program if unable to create file + if ( !outClientFile ) { // overloaded ! operator + cerr << "File could not be opened" << endl; + exit( 1 ); + + } // end if + + cout << "Enter the account, name, and balance." << endl + << "Enter end-of-file to end input.\n? "; + + int account; + char name[ 30 ]; + double balance; + + // read account, name and balance from cin, then place in file + while ( cin >> account >> name >> balance ) { + outClientFile << account << ' ' << name << ' ' << balance + << endl; + cout << "? "; + + } // end while + + return 0; // ofstream destructor closes file + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_07.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_07.cpp new file mode 100644 index 0000000..7067985 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_07.cpp @@ -0,0 +1,78 @@ +// Fig. 14.7: fig14_07.cpp +// Reading and printing a sequential file. +#include + +using std::cout; +using std::cin; +using std::ios; +using std::cerr; +using std::endl; +using std::left; +using std::right; +using std::fixed; +using std::showpoint; + +#include + +using std::ifstream; + +#include + +using std::setw; +using std::setprecision; + +#include // exit prototype + +void outputLine( int, const char * const, double ); + +int main() +{ + // ifstream constructor opens the file + ifstream inClientFile( "clients.dat", ios::in ); + + // exit program if ifstream could not open file + if ( !inClientFile ) { + cerr << "File could not be opened" << endl; + exit( 1 ); + + } // end if + + int account; + char name[ 30 ]; + double balance; + + cout << left << setw( 10 ) << "Account" << setw( 13 ) + << "Name" << "Balance" << endl << fixed << showpoint; + + // display each record in file + while ( inClientFile >> account >> name >> balance ) + outputLine( account, name, balance ); + + return 0; // ifstream destructor closes the file + +} // end main + +// display single record from file +void outputLine( int account, const char * const name, + double balance ) +{ + cout << left << setw( 10 ) << account << setw( 13 ) << name + << setw( 7 ) << setprecision( 2 ) << right << balance + << endl; + +} // end function outputLine + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_08.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_08.cpp new file mode 100644 index 0000000..ec49dee --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_08.cpp @@ -0,0 +1,163 @@ +// Fig. 14.8: fig14_08.cpp +// Credit inquiry program. +#include + +using std::cout; +using std::cin; +using std::ios; +using std::cerr; +using std::endl; +using std::fixed; +using std::showpoint; +using std::left; +using std::right; + +#include + +using std::ifstream; + +#include + +using std::setw; +using std::setprecision; + +#include + +enum RequestType { ZERO_BALANCE = 1, CREDIT_BALANCE, + DEBIT_BALANCE, END }; +int getRequest(); +bool shouldDisplay( int, double ); +void outputLine( int, const char * const, double ); + +int main() +{ + // ifstream constructor opens the file + ifstream inClientFile( "clients.dat", ios::in ); + + // exit program if ifstream could not open file + if ( !inClientFile ) { + cerr << "File could not be opened" << endl; + exit( 1 ); + + } // end if + + int request; + int account; + char name[ 30 ]; + double balance; + + // get user's request (e.g., zero, credit or debit balance) + request = getRequest(); + + // process user's request + while ( request != END ) { + + switch ( request ) { + + case ZERO_BALANCE: + cout << "\nAccounts with zero balances:\n"; + break; + + case CREDIT_BALANCE: + cout << "\nAccounts with credit balances:\n"; + break; + + case DEBIT_BALANCE: + cout << "\nAccounts with debit balances:\n"; + break; + + } // end switch + + // read account, name and balance from file + inClientFile >> account >> name >> balance; + + // display file contents (until eof) + while ( !inClientFile.eof() ) { + + // display record + if ( shouldDisplay( request, balance ) ) + outputLine( account, name, balance ); + + // read account, name and balance from file + inClientFile >> account >> name >> balance; + + } // end inner while + + inClientFile.clear(); // reset eof for next input + inClientFile.seekg( 0 ); // move to beginning of file + request = getRequest(); // get additional request from user + + } // end outer while + + cout << "End of run." << endl; + + return 0; // ifstream destructor closes the file + +} // end main + +// obtain request from user +int getRequest() +{ + int request; + + // display request options + cout << "Enter request" << endl + << " 1 - List accounts with zero balances" << endl + << " 2 - List accounts with credit balances" << endl + << " 3 - List accounts with debit balances" << endl + << " 4 - End of run" << fixed << showpoint; + + // input user request + do { + cout << "\n? "; + cin >> request; + + } while( request < ZERO_BALANCE && request > END ); + + return request; + +} // end function getRequest + +// determine whether to display given record +bool shouldDisplay( int type, double balance ) +{ + // determine whether to display credit balances + if ( type == CREDIT_BALANCE && balance < 0 ) + return true; + + // determine whether to display debit balances + if ( type == DEBIT_BALANCE && balance > 0 ) + return true; + + // determine whether to display zero balances + if ( type == ZERO_BALANCE && balance == 0 ) + return true; + + return false; + +} // end function shouldDisplay + +// display single record from file +void outputLine( int account, const char * const name, + double balance ) +{ + cout << left << setw( 10 ) << account << setw( 13 ) << name + << setw( 7 ) << setprecision( 2 ) << right << balance + << endl; + +} // end function outputLine + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_12.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_12.cpp new file mode 100644 index 0000000..48ba334 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_12.cpp @@ -0,0 +1,53 @@ +// Fig. 14.12: fig14_12.cpp +// Creating a randomly accessed file. +#include + +using std::cerr; +using std::endl; +using std::ios; + +#include + +using std::ofstream; + +#include +#include "clientData.h" // ClientData class definition + +int main() +{ + ofstream outCredit( "credit.dat", ios::binary ); + + // exit program if ofstream could not open file + if ( !outCredit ) { + cerr << "File could not be opened." << endl; + exit( 1 ); + + } // end if + + // create ClientData with no information + ClientData blankClient; + + // output 100 blank records to file + for ( int i = 0; i < 100; i++ ) + outCredit.write( + reinterpret_cast< const char * >( &blankClient ), + sizeof( ClientData ) ); + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_13.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_13.cpp new file mode 100644 index 0000000..fefa264 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_13.cpp @@ -0,0 +1,94 @@ +// Fig. 14.13: fig14_13.cpp +// Writing to a random access file. +#include + +using std::cerr; +using std::endl; +using std::cout; +using std::cin; +using std::ios; + +#include + +using std::setw; + +#include + +using std::ofstream; + +#include +#include "clientData.h" // ClientData class definition + +int main() +{ + int accountNumber; + char lastName[ 15 ]; + char firstName[ 10 ]; + double balance; + + ofstream outCredit( "credit.dat", ios::binary ); + + // exit program if ofstream cannot open file + if ( !outCredit ) { + cerr << "File could not be opened." << endl; + exit( 1 ); + + } // end if + + cout << "Enter account number " + << "(1 to 100, 0 to end input)\n? "; + + // require user to specify account number + ClientData client; + cin >> accountNumber; + client.setAccountNumber( accountNumber ); + + // user enters information, which is copied into file + while ( client.getAccountNumber() > 0 && + client.getAccountNumber() <= 100 ) { + + // user enters last name, first name and balance + cout << "Enter lastname, firstname, balance\n? "; + cin >> setw( 15 ) >> lastName; + cin >> setw( 10 ) >> firstName; + cin >> balance; + + // set record lastName, firstName and balance values + client.setLastName( lastName ); + client.setFirstName( firstName ); + client.setBalance( balance ); + + // seek position in file of user-specified record + outCredit.seekp( ( client.getAccountNumber() - 1 ) * + sizeof( ClientData ) ); + + // write user-specified information in file + outCredit.write( + reinterpret_cast< const char * >( &client ), + sizeof( ClientData ) ); + + // enable user to specify another account number + cout << "Enter account number\n? "; + cin >> accountNumber; + client.setAccountNumber( accountNumber ); + + } // end while + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_14.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_14.cpp new file mode 100644 index 0000000..6a9728e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_14.cpp @@ -0,0 +1,91 @@ +// Fig. 14.14: fig14_14.cpp +// Reading a random access file. +#include + +using std::cout; +using std::endl; +using std::ios; +using std::cerr; +using std::left; +using std::right; +using std::fixed; +using std::showpoint; + +#include + +using std::setprecision; +using std::setw; + +#include + +using std::ifstream; +using std::ostream; + +#include +#include "clientData.h" // ClientData class definition + +void outputLine( ostream&, const ClientData & ); + +int main() +{ + ifstream inCredit( "credit.dat", ios::in ); + + // exit program if ifstream cannot open file + if ( !inCredit ) { + cerr << "File could not be opened." << endl; + exit( 1 ); + + } // end if + + cout << left << setw( 10 ) << "Account" << setw( 16 ) + << "Last Name" << setw( 11 ) << "First Name" << left + << setw( 10 ) << right << "Balance" << endl; + + ClientData client; // create record + + // read first record from file + inCredit.read( reinterpret_cast< char * >( &client ), + sizeof( ClientData ) ); + + // read all records from file + while ( inCredit && !inCredit.eof() ) { + + // display record + if ( client.getAccountNumber() != 0 ) + outputLine( cout, client ); + + // read next from file + inCredit.read( reinterpret_cast< char * >( &client ), + sizeof( ClientData ) ); + + } // end while + + return 0; + +} // end main + +// display single record +void outputLine( ostream &output, const ClientData &record ) +{ + output << left << setw( 10 ) << record.getAccountNumber() + << setw( 16 ) << record.getLastName().data() + << setw( 11 ) << record.getFirstName().data() + << setw( 10 ) << setprecision( 2 ) << right << fixed + << showpoint << record.getBalance() << endl; + +} // end outputLine + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_15.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_15.cpp new file mode 100644 index 0000000..da2ef2e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/Fig14_15.cpp @@ -0,0 +1,331 @@ +// Fig. 14.15: fig14_15.cpp +// This program reads a random access file sequentially, updates +// data previously written to the file, creates data to be placed +// in the file, and deletes data previously in the file. +#include + +using std::cout; +using std::cerr; +using std::cin; +using std::endl; +using std::ios; +using std::left; +using std::right; +using std::fixed; +using std::showpoint; + +#include + +using std::ofstream; +using std::ostream; +using std::fstream; + +#include + +using std::setw; +using std::setprecision; + +#include +#include "clientData.h" // ClientData class definition + +int enterChoice(); +void printRecord( fstream& ); +void updateRecord( fstream& ); +void newRecord( fstream& ); +void deleteRecord( fstream& ); +void outputLine( ostream&, const ClientData & ); +int getAccount( const char * const ); + +enum Choices { PRINT = 1, UPDATE, NEW, DELETE, END }; + +int main() +{ + // open file for reading and writing + fstream inOutCredit( "credit.dat", ios::in | ios::out ); + + // exit program if fstream cannot open file + if ( !inOutCredit ) { + cerr << "File could not be opened." << endl; + exit ( 1 ); + + } // end if + + int choice; + + // enable user to specify action + while ( ( choice = enterChoice() ) != END ) { + + switch ( choice ) { + + // create text file from record file + case PRINT: + printRecord( inOutCredit ); + break; + + // update record + case UPDATE: + updateRecord( inOutCredit ); + break; + + // create record + case NEW: + newRecord( inOutCredit ); + break; + + // delete existing record + case DELETE: + deleteRecord( inOutCredit ); + break; + + // display error if user does not select valid choice + default: + cerr << "Incorrect choice" << endl; + break; + + } // end switch + + inOutCredit.clear(); // reset end-of-file indicator + + } // end while + + return 0; + +} // end main + +// enable user to input menu choice +int enterChoice() +{ + // display available options + cout << "\nEnter your choice" << endl + << "1 - store a formatted text file of accounts" << endl + << " called \"print.txt\" for printing" << endl + << "2 - update an account" << endl + << "3 - add a new account" << endl + << "4 - delete an account" << endl + << "5 - end program\n? "; + + int menuChoice; + cin >> menuChoice; // receive choice from user + + return menuChoice; + +} // end function enterChoice + +// create formatted text file for printing +void printRecord( fstream &readFromFile ) +{ + // create text file + ofstream outPrintFile( "print.txt", ios::out ); + + // exit program if ofstream cannot create file + if ( !outPrintFile ) { + cerr << "File could not be created." << endl; + exit( 1 ); + + } // end if + + outPrintFile << left << setw( 10 ) << "Account" << setw( 16 ) + << "Last Name" << setw( 11 ) << "First Name" << right + << setw( 10 ) << "Balance" << endl; + + // set file-position pointer to beginning of record file + readFromFile.seekg( 0 ); + + // read first record from record file + ClientData client; + readFromFile.read( reinterpret_cast< char * >( &client ), + sizeof( ClientData ) ); + + // copy all records from record file into text file + while ( !readFromFile.eof() ) { + + // write single record to text file + if ( client.getAccountNumber() != 0 ) + outputLine( outPrintFile, client ); + + // read next record from record file + readFromFile.read( reinterpret_cast< char * >( &client ), + sizeof( ClientData ) ); + + } // end while + +} // end function printRecord + +// update balance in record +void updateRecord( fstream &updateFile ) +{ + // obtain number of account to update + int accountNumber = getAccount( "Enter account to update" ); + + // move file-position pointer to correct record in file + updateFile.seekg( + ( accountNumber - 1 ) * sizeof( ClientData ) ); + + // read first record from file + ClientData client; + updateFile.read( reinterpret_cast< char * >( &client ), + sizeof( ClientData ) ); + + // update record + if ( client.getAccountNumber() != 0 ) { + outputLine( cout, client ); + + // request user to specify transaction + cout << "\nEnter charge (+) or payment (-): "; + double transaction; // charge or payment + cin >> transaction; + + // update record balance + double oldBalance = client.getBalance(); + client.setBalance( oldBalance + transaction ); + outputLine( cout, client ); + + // move file-position pointer to correct record in file + updateFile.seekp( + ( accountNumber - 1 ) * sizeof( ClientData ) ); + + // write updated record over old record in file + updateFile.write( + reinterpret_cast< const char * >( &client ), + sizeof( ClientData ) ); + + } // end if + + // display error if account does not exist + else + cerr << "Account #" << accountNumber + << " has no information." << endl; + +} // end function updateRecord + +// create and insert record +void newRecord( fstream &insertInFile ) +{ + // obtain number of account to create + int accountNumber = getAccount( "Enter new account number" ); + + // move file-position pointer to correct record in file + insertInFile.seekg( + ( accountNumber - 1 ) * sizeof( ClientData ) ); + + // read record from file + ClientData client; + insertInFile.read( reinterpret_cast< char * >( &client ), + sizeof( ClientData ) ); + + // create record, if record does not previously exist + if ( client.getAccountNumber() == 0 ) { + + char lastName[ 15 ]; + char firstName[ 10 ]; + double balance; + + // user enters last name, first name and balance + cout << "Enter lastname, firstname, balance\n? "; + cin >> setw( 15 ) >> lastName; + cin >> setw( 10 ) >> firstName; + cin >> balance; + + // use values to populate account values + client.setLastName( lastName ); + client.setFirstName( firstName ); + client.setBalance( balance ); + client.setAccountNumber( accountNumber ); + + // move file-position pointer to correct record in file + insertInFile.seekp( ( accountNumber - 1 ) * + sizeof( ClientData ) ); + + // insert record in file + insertInFile.write( + reinterpret_cast< const char * >( &client ), + sizeof( ClientData ) ); + + } // end if + + // display error if account previously exists + else + cerr << "Account #" << accountNumber + << " already contains information." << endl; + +} // end function newRecord + +// delete an existing record +void deleteRecord( fstream &deleteFromFile ) +{ + // obtain number of account to delete + int accountNumber = getAccount( "Enter account to delete" ); + + // move file-position pointer to correct record in file + deleteFromFile.seekg( + ( accountNumber - 1 ) * sizeof( ClientData ) ); + + // read record from file + ClientData client; + deleteFromFile.read( reinterpret_cast< char * >( &client ), + sizeof( ClientData ) ); + + // delete record, if record exists in file + if ( client.getAccountNumber() != 0 ) { + ClientData blankClient; + + // move file-position pointer to correct record in file + deleteFromFile.seekp( ( accountNumber - 1 ) * + sizeof( ClientData ) ); + + // replace existing record with blank record + deleteFromFile.write( + reinterpret_cast< const char * >( &blankClient ), + sizeof( ClientData ) ); + + cout << "Account #" << accountNumber << " deleted.\n"; + + } // end if + + // display error if record does not exist + else + cerr << "Account #" << accountNumber << " is empty.\n"; + +} // end deleteRecord + +// display single record +void outputLine( ostream &output, const ClientData &record ) +{ + output << left << setw( 10 ) << record.getAccountNumber() + << setw( 16 ) << record.getLastName().data() + << setw( 11 ) << record.getFirstName().data() + << setw( 10 ) << setprecision( 2 ) << right << fixed + << showpoint << record.getBalance() << endl; + +} // end function outputLine + +// obtain account-number value from user +int getAccount( const char * const prompt ) +{ + int accountNumber; + + // obtain account-number value + do { + cout << prompt << " (1 - 100): "; + cin >> accountNumber; + + } while ( accountNumber < 1 || accountNumber > 100 ); + + return accountNumber; + +} // end function getAccount + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/clientData.cpp b/Bachelor/Prog2/Codebeispiele/4_ch14/clientData.cpp new file mode 100644 index 0000000..3885357 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/clientData.cpp @@ -0,0 +1,105 @@ +// Fig. 14.11: ClientData.cpp +// Class ClientData stores customer's credit information. +#include + +using std::string; + +#include +#include "clientData.h" + +// default ClientData constructor +ClientData::ClientData( int accountNumberValue, + string lastNameValue, string firstNameValue, + double balanceValue ) +{ + setAccountNumber( accountNumberValue ); + setLastName( lastNameValue ); + setFirstName( firstNameValue ); + setBalance( balanceValue ); + +} // end ClientData constructor + +// get account-number value +int ClientData::getAccountNumber() const +{ + return accountNumber; + +} // end function getAccountNumber + +// set account-number value +void ClientData::setAccountNumber( int accountNumberValue ) +{ + accountNumber = accountNumberValue; + +} // end function setAccountNumber + +// get last-name value +string ClientData::getLastName() const +{ + return lastName; + +} // end function getLastName + +// set last-name value +void ClientData::setLastName( string lastNameString ) +{ + // copy at most 15 characters from string to lastName + const char *lastNameValue = lastNameString.data(); + int length = strlen( lastNameValue ); + length = ( length < 15 ? length : 14 ); + strncpy( lastName, lastNameValue, length ); + + // append null character to lastName + lastName[ length ] = '\0'; + +} // end function setLastName + +// get first-name value +string ClientData::getFirstName() const +{ + return firstName; + +} // end function getFirstName + +// set first-name value +void ClientData::setFirstName( string firstNameString ) +{ + // copy at most 10 characters from string to firstName + const char *firstNameValue = firstNameString.data(); + int length = strlen( firstNameValue ); + length = ( length < 10 ? length : 9 ); + strncpy( firstName, firstNameValue, length ); + + // append new-line character to firstName + firstName[ length ] = '\0'; + +} // end function setFirstName + +// get balance value +double ClientData::getBalance() const +{ + return balance; + +} // end function getBalance + +// set balance value +void ClientData::setBalance( double balanceValue ) +{ + balance = balanceValue; + +} // end function setBalance + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/4_ch14/clientData.h b/Bachelor/Prog2/Codebeispiele/4_ch14/clientData.h new file mode 100644 index 0000000..37afb23 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/4_ch14/clientData.h @@ -0,0 +1,56 @@ +// Fig. 14.10: clientData.h +// Class ClientData definition used in Fig. 14.12–Fig. 14.15. +#ifndef CLIENTDATA_H +#define CLIENTDATA_H + +#include + +using std::string; + +class ClientData { + +public: + + // default ClientData constructor + ClientData( int = 0, string = "", string = "", double = 0.0 ); + + // accessor functions for accountNumber + void setAccountNumber( int ); + int getAccountNumber() const; + + // accessor functions for lastName + void setLastName( string ); + string getLastName() const; + + // accessor functions for firstName + void setFirstName( string ); + string getFirstName() const; + + // accessor functions for balance + void setBalance( double ); + double getBalance() const; + +private: + int accountNumber; + char lastName[ 15 ]; + char firstName[ 10 ]; + double balance; + +}; // end class ClientData + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/5_ch11/Tstack1.h b/Bachelor/Prog2/Codebeispiele/5_ch11/Tstack1.h new file mode 100644 index 0000000..d689030 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/5_ch11/Tstack1.h @@ -0,0 +1,98 @@ +// Fig. 11.2: tstack1.h +// Stack class template. +#ifndef TSTACK1_H +#define TSTACK1_H + +template< class T > +class Stack { + +public: + Stack( int = 10 ); // default constructor (stack size 10) + + // destructor + ~Stack() + { + delete [] stackPtr; + + } // end ~Stack destructor + + bool push( const T& ); // push an element onto the stack + bool pop( T& ); // pop an element off the stack + + // determine whether Stack is empty + bool isEmpty() const + { + return top == -1; + + } // end function isEmpty + + // determine whether Stack is full + bool isFull() const + { + return top == size - 1; + + } // end function isFull + +private: + int size; // # of elements in the stack + int top; // location of the top element + T *stackPtr; // pointer to the stack + +}; // end class Stack + +// constructor +template< class T > +Stack< T >::Stack( int s ) +{ + size = s > 0 ? s : 10; + top = -1; // Stack initially empty + stackPtr = new T[ size ]; // allocate memory for elements + +} // end Stack constructor + +// push element onto stack; +// if successful, return true; otherwise, return false +template< class T > +bool Stack< T >::push( const T &pushValue ) +{ + if ( !isFull() ) { + stackPtr[ ++top ] = pushValue; // place item on Stack + return true; // push successful + + } // end if + + return false; // push unsuccessful + +} // end function push + +// pop element off stack; +// if successful, return true; otherwise, return false +template< class T > +bool Stack< T >::pop( T &popValue ) +{ + if ( !isEmpty() ) { + popValue = stackPtr[ top-- ]; // remove item from Stack + return true; // pop successful + + } // end if + + return false; // pop unsuccessful + +} // end function pop + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_01.cpp b/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_01.cpp new file mode 100644 index 0000000..549cc6b --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_01.cpp @@ -0,0 +1,59 @@ +// Fig 11.1: fig11_01.cpp +// Using template functions. +#include + +using std::cout; +using std::endl; + +// function template printArray definition +template< class T > +void printArray( const T *array, const int count ) +{ + for ( int i = 0; i < count; i++ ) + cout << array[ i ] << " "; + + cout << endl; + +} // end function printArray + +int main() +{ + const int aCount = 5, bCount = 7, cCount = 6; + + int a[ aCount ] = { 1, 2, 3, 4, 5 }; + double b[ bCount ] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 }; + char c[ cCount ] = "HELLO"; // 6th position for null + + cout << "Array a contains:" << endl; + + // call integer function-template specialization + printArray( a, aCount ); + + cout << "Array b contains:" << endl; + + // call double function-template specialization + printArray( b, bCount ); + + cout << "Array c contains:" << endl; + + // call character function-template specialization + printArray( c, cCount ); + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_03.cpp b/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_03.cpp new file mode 100644 index 0000000..725cbe1 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_03.cpp @@ -0,0 +1,67 @@ +// Fig. 11.3: fig11_03.cpp +// Stack class template test program. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include "tstack1.h" // Stack class template definition + +int main() +{ + Stack< double > doubleStack( 5 ); + double doubleValue = 1.1; + + cout << "Pushing elements onto doubleStack\n"; + + while ( doubleStack.push( doubleValue ) ) { + cout << doubleValue << ' '; + doubleValue += 1.1; + + } // end while + + cout << "\nStack is full. Cannot push " << doubleValue + << "\n\nPopping elements from doubleStack\n"; + + while ( doubleStack.pop( doubleValue ) ) + cout << doubleValue << ' '; + + cout << "\nStack is empty. Cannot pop\n"; + + Stack< int > intStack; + int intValue = 1; + cout << "\nPushing elements onto intStack\n"; + + while ( intStack.push( intValue ) ) { + cout << intValue << ' '; + ++intValue; + + } // end while + + cout << "\nStack is full. Cannot push " << intValue + << "\n\nPopping elements from intStack\n"; + + while ( intStack.pop( intValue ) ) + cout << intValue << ' '; + + cout << "\nStack is empty. Cannot pop\n"; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_04.cpp b/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_04.cpp new file mode 100644 index 0000000..852c4c4 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/5_ch11/fig11_04.cpp @@ -0,0 +1,63 @@ +// Fig. 11.4: fig11_04.cpp +// Stack class template test program. Function main uses a +// function template to manipulate objects of type Stack< T >. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include "tstack1.h" // Stack class template definition + +// function template to manipulate Stack< T > +template< class T > +void testStack( + Stack< T > &theStack, // reference to Stack< T > + T value, // initial value to push + T increment, // increment for subsequent values + const char *stackName ) // name of the Stack < T > object +{ + cout << "\nPushing elements onto " << stackName << '\n'; + + while ( theStack.push( value ) ) { + cout << value << ' '; + value += increment; + + } // end while + + cout << "\nStack is full. Cannot push " << value + << "\n\nPopping elements from " << stackName << '\n'; + + while ( theStack.pop( value ) ) + cout << value << ' '; + + cout << "\nStack is empty. Cannot pop\n"; + +} // end function testStack + +int main() +{ + Stack< double > doubleStack( 5 ); + Stack< int > intStack; + + testStack( doubleStack, 1.1, 1.1, "doubleStack" ); + testStack( intStack, 1, 1, "intStack" ); + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/fig17_05.cpp b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/fig17_05.cpp new file mode 100644 index 0000000..4ca0d87 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/fig17_05.cpp @@ -0,0 +1,105 @@ +// Fig. 17.5: fig17_05.cpp +// List class test program. +#include + +using std::cin; +using std::endl; + +#include + +using std::string; + +#include "list.h" // List class definition + +// function to test a List +template< class T > +void testList( List< T > &listObject, const string &typeName ) +{ + cout << "Testing a List of " << typeName << " values\n"; + + instructions(); // display instructions + + int choice; + T value; + + do { + cout << "? "; + cin >> choice; + + switch ( choice ) { + case 1: + cout << "Enter " << typeName << ": "; + cin >> value; + listObject.insertAtFront( value ); + listObject.print(); + break; + + case 2: + cout << "Enter " << typeName << ": "; + cin >> value; + listObject.insertAtBack( value ); + listObject.print(); + break; + + case 3: + if ( listObject.removeFromFront( value ) ) + cout << value << " removed from list\n"; + + listObject.print(); + break; + + case 4: + if ( listObject.removeFromBack( value ) ) + cout << value << " removed from list\n"; + + listObject.print(); + break; + + } // end switch + + } while ( choice != 5 ); // end do/while + + cout << "End list test\n\n"; + +} // end function testList + +// display program instructions to user +void instructions() +{ + cout << "Enter one of the following:\n" + << " 1 to insert at beginning of list\n" + << " 2 to insert at end of list\n" + << " 3 to delete from beginning of list\n" + << " 4 to delete from end of list\n" + << " 5 to end list processing\n"; + +} // end function instructions + +int main() +{ + // test List of int values + List< int > integerList; + testList( integerList, "integer" ); + + // test List of double values + List< double > doubleList; + testList( doubleList, "double" ); + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/list.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/list.h new file mode 100644 index 0000000..bf97eb2 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/list.h @@ -0,0 +1,216 @@ +// Fig. 17.4: list.h +// Template List class definition. +#ifndef LIST_H +#define LIST_H + +#include + +using std::cout; + +#include +#include "listnode.h" // ListNode class definition + +template< class NODETYPE > +class List { + +public: + List(); // constructor + ~List(); // destructor + void insertAtFront( const NODETYPE & ); + void insertAtBack( const NODETYPE & ); + bool removeFromFront( NODETYPE & ); + bool removeFromBack( NODETYPE & ); + bool isEmpty() const; + void print() const; + +private: + ListNode< NODETYPE > *firstPtr; // pointer to first node + ListNode< NODETYPE > *lastPtr; // pointer to last node + + // utility function to allocate new node + ListNode< NODETYPE > *getNewNode( const NODETYPE & ); + +}; // end class List + +// default constructor +template< class NODETYPE > +List< NODETYPE >::List() + : firstPtr( 0 ), + lastPtr( 0 ) +{ + // empty body + +} // end List constructor + +// destructor +template< class NODETYPE > +List< NODETYPE >::~List() +{ + if ( !isEmpty() ) { // List is not empty + cout << "Destroying nodes ...\n"; + + ListNode< NODETYPE > *currentPtr = firstPtr; + ListNode< NODETYPE > *tempPtr; + + while ( currentPtr != 0 ) { // delete remaining nodes + tempPtr = currentPtr; + cout << tempPtr->data << '\n'; + currentPtr = currentPtr->nextPtr; + delete tempPtr; + + } // end while + + } // end if + + cout << "All nodes destroyed\n\n"; + +} // end List destructor + +// insert node at front of list +template< class NODETYPE > +void List< NODETYPE >::insertAtFront( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + newPtr->nextPtr = firstPtr; + firstPtr = newPtr; + + } // end else + +} // end function insertAtFront + +// insert node at back of list +template< class NODETYPE > +void List< NODETYPE >::insertAtBack( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + lastPtr->nextPtr = newPtr; + lastPtr = newPtr; + + } // end else + +} // end function insertAtBack + +// delete node from front of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromFront( NODETYPE &value ) +{ + if ( isEmpty() ) // List is empty + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = firstPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else + firstPtr = firstPtr->nextPtr; + + value = tempPtr->data; // data being removed + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function removeFromFront + +// delete node from back of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromBack( NODETYPE &value ) +{ + if ( isEmpty() ) + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = lastPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else { + ListNode< NODETYPE > *currentPtr = firstPtr; + + // locate second-to-last element + while ( currentPtr->nextPtr != lastPtr ) + currentPtr = currentPtr->nextPtr; + + lastPtr = currentPtr; + currentPtr->nextPtr = 0; + + } // end else + + value = tempPtr->data; + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function removeFromBack + +// is List empty? +template< class NODETYPE > +bool List< NODETYPE >::isEmpty() const +{ + return firstPtr == 0; + +} // end function isEmpty + +// return pointer to newly allocated node +template< class NODETYPE > +ListNode< NODETYPE > *List< NODETYPE >::getNewNode( + const NODETYPE &value ) +{ + return new ListNode< NODETYPE >( value ); + +} // end function getNewNode + +// display contents of List +template< class NODETYPE > +void List< NODETYPE >::print() const +{ + if ( isEmpty() ) { + cout << "The list is empty\n\n"; + return; + + } // end if + + ListNode< NODETYPE > *currentPtr = firstPtr; + + cout << "The list is: "; + + while ( currentPtr != 0 ) { + cout << currentPtr->data << ' '; + currentPtr = currentPtr->nextPtr; + + } // end while + + cout << "\n\n"; + +} // end function print + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/listnode.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/listnode.h new file mode 100644 index 0000000..325d5f1 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_03_05/listnode.h @@ -0,0 +1,56 @@ +// Fig. 17.3: listnode.h +// Template ListNode class definition. +#ifndef LISTNODE_H +#define LISTNODE_H + +// forward declaration of class List +template< class NODETYPE > class List; + +template< class NODETYPE > +class ListNode { + friend class List< NODETYPE >; // make List a friend + +public: + ListNode( const NODETYPE & ); // constructor + NODETYPE getData() const; // return data in node + +private: + NODETYPE data; // data + ListNode< NODETYPE > *nextPtr; // next node in list + +}; // end class ListNode + +// constructor +template< class NODETYPE > +ListNode< NODETYPE >::ListNode( const NODETYPE &info ) + : data( info ), + nextPtr( 0 ) +{ + // empty body + +} // end ListNode constructor + +// return copy of data in node +template< class NODETYPE > +NODETYPE ListNode< NODETYPE >::getData() const +{ + return data; + +} // end function getData + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/fig17_11.cpp b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/fig17_11.cpp new file mode 100644 index 0000000..0571059 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/fig17_11.cpp @@ -0,0 +1,72 @@ +// Fig. 17.11: fig17_11.cpp +// Template Stack class test program. +#include + +using std::endl; + +#include "stack.h" // Stack class definition + +int main() +{ + Stack< int > intStack; // create Stack of ints + + cout << "processing an integer Stack" << endl; + + // push integers onto intStack + for ( int i = 0; i < 4; i++ ) { + intStack.push( i ); + intStack.printStack(); + + } // end for + + // pop integers from intStack + int popInteger; + + while ( !intStack.isStackEmpty() ) { + intStack.pop( popInteger ); + cout << popInteger << " popped from stack" << endl; + intStack.printStack(); + + } // end while + + Stack< double > doubleStack; // create Stack of doubles + double value = 1.1; + + cout << "processing a double Stack" << endl; + + // push floating-point values onto doubleStack + for ( int j = 0; j < 4; j++ ) { + doubleStack.push( value ); + doubleStack.printStack(); + value += 1.1; + + } // end for + + // pop floating-point values from doubleStack + double popDouble; + + while ( !doubleStack.isStackEmpty() ) { + doubleStack.pop( popDouble ); + cout << popDouble << " popped from stack" << endl; + doubleStack.printStack(); + + } // end while + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/list.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/list.h new file mode 100644 index 0000000..c6d2219 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/list.h @@ -0,0 +1,216 @@ +// Fig. 15.4: list.h +// Template List class definition. +#ifndef LIST_H +#define LIST_H + +#include + +using std::cout; + +#include +#include "listnode.h" // ListNode class definition + +template< class NODETYPE > +class List { + +public: + List(); // constructor + ~List(); // destructor + void insertAtFront( const NODETYPE & ); + void insertAtBack( const NODETYPE & ); + bool removeFromFront( NODETYPE & ); + bool removeFromBack( NODETYPE & ); + bool isEmpty() const; + void print() const; + +private: + ListNode< NODETYPE > *firstPtr; // pointer to first node + ListNode< NODETYPE > *lastPtr; // pointer to last node + + // utility function to allocate new node + ListNode< NODETYPE > *getNewNode( const NODETYPE & ); + +}; // end class List + +// default constructor +template< class NODETYPE > +List< NODETYPE >::List() + : firstPtr( 0 ), + lastPtr( 0 ) +{ + // empty body + +} // end List constructor + +// destructor +template< class NODETYPE > +List< NODETYPE >::~List() +{ + if ( !isEmpty() ) { // List is not empty + cout << "Destroying nodes ...\n"; + + ListNode< NODETYPE > *currentPtr = firstPtr; + ListNode< NODETYPE > *tempPtr; + + while ( currentPtr != 0 ) { // delete remaining nodes + tempPtr = currentPtr; + cout << tempPtr->data << '\n'; + currentPtr = currentPtr->nextPtr; + delete tempPtr; + + } // end while + + } // end if + + cout << "All nodes destroyed\n\n"; + +} // end ~List destructor + +// insert node at front of list +template< class NODETYPE > +void List< NODETYPE >::insertAtFront( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + newPtr->nextPtr = firstPtr; + firstPtr = newPtr; + + } // end else + +} // end function insertAtFront + +// insert node at back of list +template< class NODETYPE > +void List< NODETYPE >::insertAtBack( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + lastPtr->nextPtr = newPtr; + lastPtr = newPtr; + + } // end else + +} // end function insertAtBack + +// delete node from front of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromFront( NODETYPE &value ) +{ + if ( isEmpty() ) // List is empty + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = firstPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else + firstPtr = firstPtr->nextPtr; + + value = tempPtr->data; // data being removed + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function deleteFromFront + +// delete node from back of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromBack( NODETYPE &value ) +{ + if ( isEmpty() ) + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = lastPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else { + ListNode< NODETYPE > *currentPtr = firstPtr; + + // locate second-to-last element + while ( currentPtr->nextPtr != lastPtr ) + currentPtr = currentPtr->nextPtr; + + lastPtr = currentPtr; + currentPtr->nextPtr = 0; + + } // end else + + value = tempPtr->data; + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function deleteFromBack + +// is List empty? +template< class NODETYPE > +bool List< NODETYPE >::isEmpty() const +{ + return firstPtr == 0; + +} // end function isEmpty + +// return pointer to newly allocated node +template< class NODETYPE > +ListNode< NODETYPE > *List< NODETYPE >::getNewNode( + const NODETYPE &value ) +{ + return new ListNode< NODETYPE >( value ); + +} // end function getNewNode + +// display contents of List +template< class NODETYPE > +void List< NODETYPE >::print() const +{ + if ( isEmpty() ) { + cout << "The list is empty\n\n"; + return; + + } // end if + + ListNode< NODETYPE > *currentPtr = firstPtr; + + cout << "The list is: "; + + while ( currentPtr != 0 ) { + cout << currentPtr->data << ' '; + currentPtr = currentPtr->nextPtr; + + } // end while + + cout << "\n\n"; + +} // end function print + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/listnode.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/listnode.h new file mode 100644 index 0000000..7980786 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/listnode.h @@ -0,0 +1,56 @@ +// Fig. 15.3: listnode.h +// Template ListNode class definition. +#ifndef LISTNODE_H +#define LISTNODE_H + +// forward declaration of class List +template< class NODETYPE > class List; + +template< class NODETYPE > +class ListNode { + friend class List< NODETYPE >; // make List a friend + +public: + ListNode( const NODETYPE & ); // constructor + NODETYPE getData() const; // return data in node + +private: + NODETYPE data; // data + ListNode< NODETYPE > *nextPtr; // next node in list + +}; // end class ListNode + +// constructor +template< class NODETYPE > +ListNode< NODETYPE >::ListNode( const NODETYPE &info ) + : data( info ), + nextPtr( 0 ) +{ + // empty body + +} // end ListNode constructor + +// return copy of data in node +template< class NODETYPE > +NODETYPE ListNode< NODETYPE >::getData() const +{ + return data; + +} // end function getData + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/stack.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/stack.h new file mode 100644 index 0000000..bc883ea --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_10_11/stack.h @@ -0,0 +1,57 @@ +// Fig. 17.10: stack.h +// Template Stack class definition derived from class List. +#ifndef STACK_H +#define STACK_H + +#include "list.h" // List class definition + +template< class STACKTYPE > +class Stack : private List< STACKTYPE > { + +public: + // push calls List function insertAtFront + void push( const STACKTYPE &data ) + { + insertAtFront( data ); + + } // end function push + + // pop calls List function removeFromFront + bool pop( STACKTYPE &data ) + { + return removeFromFront( data ); + + } // end function pop + + // isStackEmpty calls List function isEmpty + bool isStackEmpty() const + { + return isEmpty(); + + } // end function isStackEmpty + + // printStack calls List function print + void printStack() const + { + print(); + + } // end function print + +}; // end class Stack + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/fig17_12test.cpp b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/fig17_12test.cpp new file mode 100644 index 0000000..3adb315 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/fig17_12test.cpp @@ -0,0 +1,69 @@ +// Fig. 17.11: fig17_11.cpp +// Template Stack class test program. +#include + +using std::endl; + +#include "stackcomposition.h" // Stack class definition + +int main() +{ + Stack< int > intStack; // create Stack of ints + int popInteger; + + cout << "processing an integer Stack" << endl; + + // push integers onto intStack + for ( int i = 0; i < 4; i++ ) { + intStack.push( i ); + intStack.printStack(); + + } // end for + + // pop integers from intStack + while ( !intStack.isStackEmpty() ) { + intStack.pop( popInteger ); + cout << popInteger << " popped from stack" << endl; + intStack.printStack(); + + } // end while + + Stack< double > doubleStack; // create Stack of doubles + double value = 1.1, popdouble; + + cout << "processing a double Stack" << endl; + + // push floating-point values onto doubleStack + for ( int j = 0; j< 4; j++ ) { + doubleStack.push( value ); + doubleStack.printStack(); + value += 1.1; + + } // end for + + // pop floating-point values from doubleStack + while ( !doubleStack.isStackEmpty() ) { + doubleStack.pop( popdouble ); + cout << popdouble << " popped from stack" << endl; + doubleStack.printStack(); + + } // end while + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/list.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/list.h new file mode 100644 index 0000000..c6d2219 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/list.h @@ -0,0 +1,216 @@ +// Fig. 15.4: list.h +// Template List class definition. +#ifndef LIST_H +#define LIST_H + +#include + +using std::cout; + +#include +#include "listnode.h" // ListNode class definition + +template< class NODETYPE > +class List { + +public: + List(); // constructor + ~List(); // destructor + void insertAtFront( const NODETYPE & ); + void insertAtBack( const NODETYPE & ); + bool removeFromFront( NODETYPE & ); + bool removeFromBack( NODETYPE & ); + bool isEmpty() const; + void print() const; + +private: + ListNode< NODETYPE > *firstPtr; // pointer to first node + ListNode< NODETYPE > *lastPtr; // pointer to last node + + // utility function to allocate new node + ListNode< NODETYPE > *getNewNode( const NODETYPE & ); + +}; // end class List + +// default constructor +template< class NODETYPE > +List< NODETYPE >::List() + : firstPtr( 0 ), + lastPtr( 0 ) +{ + // empty body + +} // end List constructor + +// destructor +template< class NODETYPE > +List< NODETYPE >::~List() +{ + if ( !isEmpty() ) { // List is not empty + cout << "Destroying nodes ...\n"; + + ListNode< NODETYPE > *currentPtr = firstPtr; + ListNode< NODETYPE > *tempPtr; + + while ( currentPtr != 0 ) { // delete remaining nodes + tempPtr = currentPtr; + cout << tempPtr->data << '\n'; + currentPtr = currentPtr->nextPtr; + delete tempPtr; + + } // end while + + } // end if + + cout << "All nodes destroyed\n\n"; + +} // end ~List destructor + +// insert node at front of list +template< class NODETYPE > +void List< NODETYPE >::insertAtFront( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + newPtr->nextPtr = firstPtr; + firstPtr = newPtr; + + } // end else + +} // end function insertAtFront + +// insert node at back of list +template< class NODETYPE > +void List< NODETYPE >::insertAtBack( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + lastPtr->nextPtr = newPtr; + lastPtr = newPtr; + + } // end else + +} // end function insertAtBack + +// delete node from front of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromFront( NODETYPE &value ) +{ + if ( isEmpty() ) // List is empty + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = firstPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else + firstPtr = firstPtr->nextPtr; + + value = tempPtr->data; // data being removed + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function deleteFromFront + +// delete node from back of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromBack( NODETYPE &value ) +{ + if ( isEmpty() ) + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = lastPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else { + ListNode< NODETYPE > *currentPtr = firstPtr; + + // locate second-to-last element + while ( currentPtr->nextPtr != lastPtr ) + currentPtr = currentPtr->nextPtr; + + lastPtr = currentPtr; + currentPtr->nextPtr = 0; + + } // end else + + value = tempPtr->data; + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function deleteFromBack + +// is List empty? +template< class NODETYPE > +bool List< NODETYPE >::isEmpty() const +{ + return firstPtr == 0; + +} // end function isEmpty + +// return pointer to newly allocated node +template< class NODETYPE > +ListNode< NODETYPE > *List< NODETYPE >::getNewNode( + const NODETYPE &value ) +{ + return new ListNode< NODETYPE >( value ); + +} // end function getNewNode + +// display contents of List +template< class NODETYPE > +void List< NODETYPE >::print() const +{ + if ( isEmpty() ) { + cout << "The list is empty\n\n"; + return; + + } // end if + + ListNode< NODETYPE > *currentPtr = firstPtr; + + cout << "The list is: "; + + while ( currentPtr != 0 ) { + cout << currentPtr->data << ' '; + currentPtr = currentPtr->nextPtr; + + } // end while + + cout << "\n\n"; + +} // end function print + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/listnode.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/listnode.h new file mode 100644 index 0000000..7980786 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/listnode.h @@ -0,0 +1,56 @@ +// Fig. 15.3: listnode.h +// Template ListNode class definition. +#ifndef LISTNODE_H +#define LISTNODE_H + +// forward declaration of class List +template< class NODETYPE > class List; + +template< class NODETYPE > +class ListNode { + friend class List< NODETYPE >; // make List a friend + +public: + ListNode( const NODETYPE & ); // constructor + NODETYPE getData() const; // return data in node + +private: + NODETYPE data; // data + ListNode< NODETYPE > *nextPtr; // next node in list + +}; // end class ListNode + +// constructor +template< class NODETYPE > +ListNode< NODETYPE >::ListNode( const NODETYPE &info ) + : data( info ), + nextPtr( 0 ) +{ + // empty body + +} // end ListNode constructor + +// return copy of data in node +template< class NODETYPE > +NODETYPE ListNode< NODETYPE >::getData() const +{ + return data; + +} // end function getData + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/stackcomposition.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/stackcomposition.h new file mode 100644 index 0000000..2a603d7 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_12/stackcomposition.h @@ -0,0 +1,62 @@ +// Fig. 17.12: stackcomposition.h +// Template Stack class definition with composed List object. +#ifndef STACKCOMPOSITION +#define STACKCOMPOSITION + +#include "list.h" // List class definition + +template< class STACKTYPE > +class Stack { + +public: + // no constructor; List constructor does initialization + + // push calls stackList object's insertAtFront function + void push( const STACKTYPE &data ) + { + stackList.insertAtFront( data ); + + } // end function push + + // pop calls stackList object's removeFromFront function + bool pop( STACKTYPE &data ) + { + return stackList.removeFromFront( data ); + + } // end function pop + + // isStackEmpty calls stackList object's isEmpty function + bool isStackEmpty() const + { + return stackList.isEmpty(); + + } // end function isStackEmpty + + // printStack calls stackList object's print function + void printStack() const + { + stackList.print(); + + } // end function printStack + +private: + List< STACKTYPE > stackList; // composed List object + +}; // end class Stack + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/fig17_14.cpp b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/fig17_14.cpp new file mode 100644 index 0000000..a5c24d5 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/fig17_14.cpp @@ -0,0 +1,72 @@ +// Fig. 17.14: fig17_14.cpp +// Template Queue class test program. +#include + +using std::endl; + +#include "queue.h" // Queue class definition + +int main() +{ + Queue< int > intQueue; // create Queue of ints + + cout << "processing an integer Queue" << endl; + + // enqueue integers onto intQueue + for ( int i = 0; i < 4; i++ ) { + intQueue.enqueue( i ); + intQueue.printQueue(); + + } // end for + + // dequeue integers from intQueue + int dequeueInteger; + + while ( !intQueue.isQueueEmpty() ) { + intQueue.dequeue( dequeueInteger ); + cout << dequeueInteger << " dequeued" << endl; + intQueue.printQueue(); + + } // end while + + Queue< double > doubleQueue; // create Queue of doubles + double value = 1.1; + + cout << "processing a double Queue" << endl; + + // enqueue floating-point values onto doubleQueue + for ( int j = 0; j< 4; j++ ) { + doubleQueue.enqueue( value ); + doubleQueue.printQueue(); + value += 1.1; + + } // end for + + // dequeue floating-point values from doubleQueue + double dequeueDouble; + + while ( !doubleQueue.isQueueEmpty() ) { + doubleQueue.dequeue( dequeueDouble ); + cout << dequeueDouble << " dequeued" << endl; + doubleQueue.printQueue(); + + } // end while + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/list.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/list.h new file mode 100644 index 0000000..c6d2219 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/list.h @@ -0,0 +1,216 @@ +// Fig. 15.4: list.h +// Template List class definition. +#ifndef LIST_H +#define LIST_H + +#include + +using std::cout; + +#include +#include "listnode.h" // ListNode class definition + +template< class NODETYPE > +class List { + +public: + List(); // constructor + ~List(); // destructor + void insertAtFront( const NODETYPE & ); + void insertAtBack( const NODETYPE & ); + bool removeFromFront( NODETYPE & ); + bool removeFromBack( NODETYPE & ); + bool isEmpty() const; + void print() const; + +private: + ListNode< NODETYPE > *firstPtr; // pointer to first node + ListNode< NODETYPE > *lastPtr; // pointer to last node + + // utility function to allocate new node + ListNode< NODETYPE > *getNewNode( const NODETYPE & ); + +}; // end class List + +// default constructor +template< class NODETYPE > +List< NODETYPE >::List() + : firstPtr( 0 ), + lastPtr( 0 ) +{ + // empty body + +} // end List constructor + +// destructor +template< class NODETYPE > +List< NODETYPE >::~List() +{ + if ( !isEmpty() ) { // List is not empty + cout << "Destroying nodes ...\n"; + + ListNode< NODETYPE > *currentPtr = firstPtr; + ListNode< NODETYPE > *tempPtr; + + while ( currentPtr != 0 ) { // delete remaining nodes + tempPtr = currentPtr; + cout << tempPtr->data << '\n'; + currentPtr = currentPtr->nextPtr; + delete tempPtr; + + } // end while + + } // end if + + cout << "All nodes destroyed\n\n"; + +} // end ~List destructor + +// insert node at front of list +template< class NODETYPE > +void List< NODETYPE >::insertAtFront( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + newPtr->nextPtr = firstPtr; + firstPtr = newPtr; + + } // end else + +} // end function insertAtFront + +// insert node at back of list +template< class NODETYPE > +void List< NODETYPE >::insertAtBack( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = getNewNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + lastPtr->nextPtr = newPtr; + lastPtr = newPtr; + + } // end else + +} // end function insertAtBack + +// delete node from front of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromFront( NODETYPE &value ) +{ + if ( isEmpty() ) // List is empty + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = firstPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else + firstPtr = firstPtr->nextPtr; + + value = tempPtr->data; // data being removed + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function deleteFromFront + +// delete node from back of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromBack( NODETYPE &value ) +{ + if ( isEmpty() ) + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = lastPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else { + ListNode< NODETYPE > *currentPtr = firstPtr; + + // locate second-to-last element + while ( currentPtr->nextPtr != lastPtr ) + currentPtr = currentPtr->nextPtr; + + lastPtr = currentPtr; + currentPtr->nextPtr = 0; + + } // end else + + value = tempPtr->data; + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function deleteFromBack + +// is List empty? +template< class NODETYPE > +bool List< NODETYPE >::isEmpty() const +{ + return firstPtr == 0; + +} // end function isEmpty + +// return pointer to newly allocated node +template< class NODETYPE > +ListNode< NODETYPE > *List< NODETYPE >::getNewNode( + const NODETYPE &value ) +{ + return new ListNode< NODETYPE >( value ); + +} // end function getNewNode + +// display contents of List +template< class NODETYPE > +void List< NODETYPE >::print() const +{ + if ( isEmpty() ) { + cout << "The list is empty\n\n"; + return; + + } // end if + + ListNode< NODETYPE > *currentPtr = firstPtr; + + cout << "The list is: "; + + while ( currentPtr != 0 ) { + cout << currentPtr->data << ' '; + currentPtr = currentPtr->nextPtr; + + } // end while + + cout << "\n\n"; + +} // end function print + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/listnode.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/listnode.h new file mode 100644 index 0000000..7980786 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/listnode.h @@ -0,0 +1,56 @@ +// Fig. 15.3: listnode.h +// Template ListNode class definition. +#ifndef LISTNODE_H +#define LISTNODE_H + +// forward declaration of class List +template< class NODETYPE > class List; + +template< class NODETYPE > +class ListNode { + friend class List< NODETYPE >; // make List a friend + +public: + ListNode( const NODETYPE & ); // constructor + NODETYPE getData() const; // return data in node + +private: + NODETYPE data; // data + ListNode< NODETYPE > *nextPtr; // next node in list + +}; // end class ListNode + +// constructor +template< class NODETYPE > +ListNode< NODETYPE >::ListNode( const NODETYPE &info ) + : data( info ), + nextPtr( 0 ) +{ + // empty body + +} // end ListNode constructor + +// return copy of data in node +template< class NODETYPE > +NODETYPE ListNode< NODETYPE >::getData() const +{ + return data; + +} // end function getData + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queue.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queue.h new file mode 100644 index 0000000..84054c9 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queue.h @@ -0,0 +1,57 @@ +// Fig. 17.13: queue.h +// Template Queue class definition derived from class List. +#ifndef QUEUE_H +#define QUEUE_H + +#include "list.h" // List class definition + +template< class QUEUETYPE > +class Queue: private List< QUEUETYPE > { + +public: + // enqueue calls List function insertAtBack + void enqueue( const QUEUETYPE &data ) + { + insertAtBack( data ); + + } // end function enqueue + + // dequeue calls List function removeFromFront + bool dequeue( QUEUETYPE &data ) + { + return removeFromFront( data ); + + } // end function dequeue + + // isQueueEmpty calls List function isEmpty + bool isQueueEmpty() const + { + return isEmpty(); + + } // end function isQueueEmpty + + // printQueue calls List function print + void printQueue() const + { + print(); + + } // end function printQueue + +}; // end class Queue + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queuecomposition.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queuecomposition.h new file mode 100644 index 0000000..01c2ad4 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_13_14/queuecomposition.h @@ -0,0 +1,59 @@ +// Definition of Queue class composed of List object +#ifndef QUEUE_C +#define QUEUE_C + +#include "list.h" + +template< class QUEUETYPE > +class Queue { + +public: + // enqueue calls queueList object's insertAtBack function + void enqueue( const QUEUETYPE &data ) + { + queueList.insertAtBack( data ); + + } // end function enqueue + + // dequeue calls queueList object's removeFromFront function + bool dequeue( QUEUETYPE &data ) + { + return queueList.removeFromFront( data ); + + } // end function dequeue + + // isQueueEmpty calls queueList object's isEmpty function + bool isQueueEmpty() const + { + return queueList.isEmpty(); + + } // end function isQueueEmpty + + // printQueue calls queueList object's print function + void printQueue() const + { + queueList.print(); + + } // end function printQueue + +private: + List< QUEUETYPE > queueList; // composed List object + +}; // end class Queue + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Tree.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Tree.h new file mode 100644 index 0000000..d44276c --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Tree.h @@ -0,0 +1,159 @@ +// Fig. 17.18: tree.h +// Template Tree class definition. +#ifndef TREE_H +#define TREE_H + +#include + +using std::endl; + +#include +#include "treenode.h" + +template< class NODETYPE > +class Tree { + +public: + Tree(); + void insertNode( const NODETYPE & ); + void preOrderTraversal() const; + void inOrderTraversal() const; + void postOrderTraversal() const; + +private: + TreeNode< NODETYPE > *rootPtr; + + // utility functions + void insertNodeHelper( + TreeNode< NODETYPE > **, const NODETYPE & ); + void preOrderHelper( TreeNode< NODETYPE > * ) const; + void inOrderHelper( TreeNode< NODETYPE > * ) const; + void postOrderHelper( TreeNode< NODETYPE > * ) const; + +}; // end class Tree + +// constructor +template< class NODETYPE > +Tree< NODETYPE >::Tree() +{ + rootPtr = 0; + +} // end Tree constructor + +// insert node in Tree +template< class NODETYPE > +void Tree< NODETYPE >::insertNode( const NODETYPE &value ) +{ + insertNodeHelper( &rootPtr, value ); + +} // end function insertNode + +// utility function called by insertNode; receives a pointer +// to a pointer so that the function can modify pointer's value +template< class NODETYPE > +void Tree< NODETYPE >::insertNodeHelper( + TreeNode< NODETYPE > **ptr, const NODETYPE &value ) +{ + // subtree is empty; create new TreeNode containing value + if ( *ptr == 0 ) + *ptr = new TreeNode< NODETYPE >( value ); + + else // subtree is not empty + + // data to insert is less than data in current node + if ( value < ( *ptr )->data ) + insertNodeHelper( &( ( *ptr )->leftPtr ), value ); + + else + + // data to insert is greater than data in current node + if ( value > ( *ptr )->data ) + insertNodeHelper( &( ( *ptr )->rightPtr ), value ); + + else // duplicate data value ignored + cout << value << " dup" << endl; + +} // end function insertNodeHelper + +// begin preorder traversal of Tree +template< class NODETYPE > +void Tree< NODETYPE >::preOrderTraversal() const +{ + preOrderHelper( rootPtr ); + +} // end function preOrderTraversal + +// utility function to perform preorder traversal of Tree +template< class NODETYPE > +void Tree< NODETYPE >::preOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + if ( ptr != 0 ) { + cout << ptr->data << ' '; // process node + preOrderHelper( ptr->leftPtr ); // go to left subtree + preOrderHelper( ptr->rightPtr ); // go to right subtree + + } // end if + +} // end function preOrderHelper + +// begin inorder traversal of Tree +template< class NODETYPE > +void Tree< NODETYPE >::inOrderTraversal() const +{ + inOrderHelper( rootPtr ); + +} // end function inOrderTraversal + +// utility function to perform inorder traversal of Tree +template< class NODETYPE > +void Tree< NODETYPE >::inOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + if ( ptr != 0 ) { + inOrderHelper( ptr->leftPtr ); // go to left subtree + cout << ptr->data << ' '; // process node + inOrderHelper( ptr->rightPtr ); // go to right subtree + + } // end if + +} // end function inOrderHelper + +// begin postorder traversal of Tree +template< class NODETYPE > +void Tree< NODETYPE >::postOrderTraversal() const +{ + postOrderHelper( rootPtr ); + +} // end function postOrderTraversal + +// utility function to perform postorder traversal of Tree +template< class NODETYPE > +void Tree< NODETYPE >::postOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + if ( ptr != 0 ) { + postOrderHelper( ptr->leftPtr ); // go to left subtree + postOrderHelper( ptr->rightPtr ); // go to right subtree + cout << ptr->data << ' '; // process node + + } // end if + +} // end function postOrderHelper + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Treenode.h b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Treenode.h new file mode 100644 index 0000000..a79cee9 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/Treenode.h @@ -0,0 +1,54 @@ +// Fig. 17.17: treenode.h +// Template TreeNode class definition. +#ifndef TREENODE_H +#define TREENODE_H + +// forward declaration of class Tree +template< class NODETYPE > class Tree; + +template< class NODETYPE > +class TreeNode { + friend class Tree< NODETYPE >; + +public: + + // constructor + TreeNode( const NODETYPE &d ) + : leftPtr( 0 ), + data( d ), + rightPtr( 0 ) + { + // empty body + + } // end TreeNode constructor + + // return copy of node's data + NODETYPE getData() const + { + return data; + + } // end getData function + +private: + TreeNode< NODETYPE > *leftPtr; // pointer to left subtree + NODETYPE data; + TreeNode< NODETYPE > *rightPtr; // pointer to right subtree + +}; // end class TreeNode + +#endif + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/fig17_19.cpp b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/fig17_19.cpp new file mode 100644 index 0000000..3fb8def --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/6_ch17/fig17_17_19/fig17_19.cpp @@ -0,0 +1,76 @@ +// Fig. 17.19: fig17_19.cpp +// Tree class test program. +#include + +using std::cout; +using std::cin; +using std::fixed; + +#include +using std::setprecision; + +#include "tree.h" // Tree class definition + +int main() +{ + Tree< int > intTree; // create Tree of int values + int intValue; + + cout << "Enter 10 integer values:\n"; + + for( int i = 0; i < 10; i++ ) { + cin >> intValue; + intTree.insertNode( intValue ); + + } // end for + + cout << "\nPreorder traversal\n"; + intTree.preOrderTraversal(); + + cout << "\nInorder traversal\n"; + intTree.inOrderTraversal(); + + cout << "\nPostorder traversal\n"; + intTree.postOrderTraversal(); + + Tree< double > doubleTree; // create Tree of double values + double doubleValue; + + cout << fixed << setprecision( 1 ) + << "\n\n\nEnter 10 double values:\n"; + + for ( int j = 0; j < 10; j++ ) { + cin >> doubleValue; + doubleTree.insertNode( doubleValue ); + + } // end for + + cout << "\nPreorder traversal\n"; + doubleTree.preOrderTraversal(); + + cout << "\nInorder traversal\n"; + doubleTree.inOrderTraversal(); + + cout << "\nPostorder traversal\n"; + doubleTree.postOrderTraversal(); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_05.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_05.CPP new file mode 100644 index 0000000..0fe4205 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_05.CPP @@ -0,0 +1,46 @@ +// Fig. 21.5: fig21_05.cpp +// Demonstrating input and output with iterators. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include // ostream_iterator and istream_iterator + +int main() +{ + cout << "Enter two integers: "; + + // create istream_iterator for reading int values from cin + std::istream_iterator< int > inputInt( cin ); + + int number1 = *inputInt; // read int from standard input + ++inputInt; // move iterator to next input value + int number2 = *inputInt; // read int from standard input + + // create ostream_iterator for writing int values to cout + std::ostream_iterator< int > outputInt( cout ); + + cout << "The sum is: "; + *outputInt = number1 + number2; // output result to cout + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_14.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_14.CPP new file mode 100644 index 0000000..8a42288 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_14.CPP @@ -0,0 +1,85 @@ +// Fig. 21.14: fig21_14.cpp +// Demonstrating standard library vector class template. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include // vector class-template definition + +// prototype for function template printVector +template < class T > +void printVector( const std::vector< T > &integers2 ); + +int main() +{ + const int SIZE = 6; + int array[ SIZE ] = { 1, 2, 3, 4, 5, 6 }; + + std::vector< int > integers; + + cout << "The initial size of integers is: " + << integers.size() + << "\nThe initial capacity of integers is: " + << integers.capacity(); + + // function push_back is in every sequence collection + integers.push_back( 2 ); + integers.push_back( 3 ); + integers.push_back( 4 ); + + cout << "\nThe size of integers is: " << integers.size() + << "\nThe capacity of integers is: " + << integers.capacity(); + + cout << "\n\nOutput array using pointer notation: "; + + for ( int *ptr = array; ptr != array + SIZE; ++ptr ) + cout << *ptr << ' '; + + cout << "\nOutput vector using iterator notation: "; + printVector( integers ); + + cout << "\nReversed contents of vector integers: "; + + std::vector< int >::reverse_iterator reverseIterator; + + for ( reverseIterator = integers.rbegin(); + reverseIterator!= integers.rend(); + ++reverseIterator ) + cout << *reverseIterator << ' '; + + cout << endl; + + return 0; + +} // end main + +// function template for outputting vector elements +template < class T > +void printVector( const std::vector< T > &integers2 ) +{ + std::vector< T >::const_iterator constIterator; + + for ( constIterator = integers2.begin(); + constIterator != integers2.end(); + constIterator++ ) + cout << *constIterator << ' '; + +} // end function printVector + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_15.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_15.CPP new file mode 100644 index 0000000..bb74911 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_15.CPP @@ -0,0 +1,86 @@ +// Fig. 21.15: fig21_15.cpp +// Testing Standard Library vector class template +// element-manipulation functions. +#include + +using std::cout; +using std::endl; + +#include // vector class-template definition +#include // copy algorithm + +int main() +{ + const int SIZE = 6; + int array[ SIZE ] = { 1, 2, 3, 4, 5, 6 }; + + std::vector< int > integers( array, array + SIZE ); + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector integers contains: "; + std::copy( integers.begin(), integers.end(), output ); + + cout << "\nFirst element of integers: " << integers.front() + << "\nLast element of integers: " << integers.back(); + + integers[ 0 ] = 7; // set first element to 7 + integers.at( 2 ) = 10; // set element at position 2 to 10 + + // insert 22 as 2nd element + integers.insert( integers.begin() + 1, 22 ); + + cout << "\n\nContents of vector integers after changes: "; + std::copy( integers.begin(), integers.end(), output ); + + // access out-of-range element + try { + integers.at( 100 ) = 777; + + } // end try + + // catch out_of_range exception + catch ( std::out_of_range outOfRange ) { + cout << "\n\nException: " << outOfRange.what(); + + } // end catch + + // erase first element + integers.erase( integers.begin() ); + cout << "\n\nVector integers after erasing first element: "; + std::copy( integers.begin(), integers.end(), output ); + + // erase remaining elements + integers.erase( integers.begin(), integers.end() ); + cout << "\nAfter erasing all elements, vector integers " + << ( integers.empty() ? "is" : "is not" ) << " empty"; + + // insert elements from array + integers.insert( integers.begin(), array, array + SIZE ); + cout << "\n\nContents of vector integers before clear: "; + std::copy( integers.begin(), integers.end(), output ); + + // empty integers; clear calls erase to empty a collection + integers.clear(); + cout << "\nAfter clear, vector integers " + << ( integers.empty() ? "is" : "is not" ) << " empty"; + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_17.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_17.CPP new file mode 100644 index 0000000..bd6398d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_17.CPP @@ -0,0 +1,145 @@ +// Fig. 21.17: fig21_17.cpp +// Standard library list class template test program. +#include + +using std::cout; +using std::endl; + +#include // list class-template definition +#include // copy algorithm + +// prototype for function template printList +template < class T > +void printList( const std::list< T > &listRef ); + +int main() +{ + const int SIZE = 4; + int array[ SIZE ] = { 2, 6, 4, 8 }; + + std::list< int > values; + std::list< int > otherValues; + + // insert items in values + values.push_front( 1 ); + values.push_front( 2 ); + values.push_back( 4 ); + values.push_back( 3 ); + + cout << "values contains: "; + printList( values ); + + values.sort(); // sort values + + cout << "\nvalues after sorting contains: "; + printList( values ); + + // insert elements of array into otherValues + otherValues.insert( otherValues.begin(), + array, array + SIZE ); + + cout << "\nAfter insert, otherValues contains: "; + printList( otherValues ); + + // remove otherValues elements and insert at end of values + values.splice( values.end(), otherValues ); + + cout << "\nAfter splice, values contains: "; + printList( values ); + + values.sort(); // sort values + + cout << "\nAfter sort, values contains: "; + printList( values ); + + // insert elements of array into otherValues + otherValues.insert( otherValues.begin(), + array, array + SIZE ); + otherValues.sort(); + + cout << "\nAfter insert, otherValues contains: "; + printList( otherValues ); + + // remove otherValues elements and insert into values + // in sorted order + values.merge( otherValues ); + + cout << "\nAfter merge:\n values contains: "; + printList( values ); + cout << "\n otherValues contains: "; + printList( otherValues ); + + values.pop_front(); // remove element from front + values.pop_back(); // remove element from back + + cout << "\nAfter pop_front and pop_back:" + << "\n values contains: "; + printList( values ); + + values.unique(); // remove duplicate elements + + cout << "\nAfter unique, values contains: "; + printList( values ); + + // swap elements of values and otherValues + values.swap( otherValues ); + + cout << "\nAfter swap:\n values contains: "; + printList( values ); + cout << "\n otherValues contains: "; + printList( otherValues ); + + // replace contents of values with elements of otherValues + values.assign( otherValues.begin(), otherValues.end() ); + + cout << "\nAfter assign, values contains: "; + printList( values ); + + // remove otherValues elements and insert into values + // in sorted order + values.merge( otherValues ); + + cout << "\nAfter merge, values contains: "; + printList( values ); + + values.remove( 4 ); // remove all 4s + + cout << "\nAfter remove( 4 ), values contains: "; + printList( values ); + + cout << endl; + + return 0; + +} // end main + +// printList function template definition; uses +// ostream_iterator and copy algorithm to output list elements +template < class T > +void printList( const std::list< T > &listRef ) +{ + if ( listRef.empty() ) + cout << "List is empty"; + + else { + std::ostream_iterator< T > output( cout, " " ); + std::copy( listRef.begin(), listRef.end(), output ); + + } // end else + +} // end function printList + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_18.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_18.CPP new file mode 100644 index 0000000..c8edb5d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_18.CPP @@ -0,0 +1,57 @@ +// Fig. 21.18: fig21_18.cpp +// Standard library class deque test program. +#include + +using std::cout; +using std::endl; + +#include // deque class-template definition +#include // copy algorithm + +int main() +{ + std::deque< double > values; + std::ostream_iterator< double > output( cout, " " ); + + // insert elements in values + values.push_front( 2.2 ); + values.push_front( 3.5 ); + values.push_back( 1.1 ); + + cout << "values contains: "; + + // use subscript operator to obtain elements of values + for ( int i = 0; i < values.size(); ++i ) + cout << values[ i ] << ' '; + + values.pop_front(); // remove first element + + cout << "\nAfter pop_front, values contains: "; + std::copy( values.begin(), values.end(), output ); + + // use subscript operator to modify element at location 1 + values[ 1 ] = 5.4; + + cout << "\nAfter values[ 1 ] = 5.4, values contains: "; + std::copy( values.begin(), values.end(), output ); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_19.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_19.CPP new file mode 100644 index 0000000..8b3e890 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_19.CPP @@ -0,0 +1,90 @@ +// Fig. 21.19: fig21_19.cpp +// Testing Standard Library class multiset +#include + +using std::cout; +using std::endl; + +#include // multiset class-template definition + +// define short name for multiset type used in this program +typedef std::multiset< int, std::less< int > > ims; + +#include // copy algorithm + +int main() +{ + const int SIZE = 10; + int a[ SIZE ] = { 7, 22, 9, 1, 18, 30, 100, 22, 85, 13 }; + + ims intMultiset; // ims is typedef for "integer multiset" + std::ostream_iterator< int > output( cout, " " ); + + cout << "There are currently " << intMultiset.count( 15 ) + << " values of 15 in the multiset\n"; + + intMultiset.insert( 15 ); // insert 15 in intMultiset + intMultiset.insert( 15 ); // insert 15 in intMultiset + + cout << "After inserts, there are " + << intMultiset.count( 15 ) + << " values of 15 in the multiset\n\n"; + + // iterator that cannot be used to change element values + ims::const_iterator result; + + // find 15 in intMultiset; find returns iterator + result = intMultiset.find( 15 ); + + if ( result != intMultiset.end() ) // if iterator not at end + cout << "Found value 15\n"; // found search value 15 + + // find 20 in intMultiset; find returns iterator + result = intMultiset.find( 20 ); + + if ( result == intMultiset.end() ) // will be true hence + cout << "Did not find value 20\n"; // did not find 20 + + // insert elements of array a into intMultiset + intMultiset.insert( a, a + SIZE ); + + cout << "\nAfter insert, intMultiset contains:\n"; + std::copy( intMultiset.begin(), intMultiset.end(), output ); + + // determine lower and upper bound of 22 in intMultiset + cout << "\n\nLower bound of 22: " + << *( intMultiset.lower_bound( 22 ) ); + cout << "\nUpper bound of 22: " + << *( intMultiset.upper_bound( 22 ) ); + + // p represents pair of const_iterators + std::pair< ims::const_iterator, ims::const_iterator > p; + + // use equal_range to determine lower and upper bound + // of 22 in intMultiset + p = intMultiset.equal_range( 22 ); + + cout << "\n\nequal_range of 22:" + << "\n Lower bound: " << *( p.first ) + << "\n Upper bound: " << *( p.second ); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_20.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_20.CPP new file mode 100644 index 0000000..76415d7 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_20.CPP @@ -0,0 +1,68 @@ +// Fig. 21.20: fig21_20.cpp +// Standard library class set test program. +#include + +using std::cout; +using std::endl; + +#include + +// define short name for set type used in this program +typedef std::set< double, std::less< double > > double_set; + +#include + +int main() +{ + const int SIZE = 5; + double a[ SIZE ] = { 2.1, 4.2, 9.5, 2.1, 3.7 }; + + double_set doubleSet( a, a + SIZE );; + std::ostream_iterator< double > output( cout, " " ); + + cout << "doubleSet contains: "; + std::copy( doubleSet.begin(), doubleSet.end(), output ); + + // p represents pair containing const_iterator and bool + std::pair< double_set::const_iterator, bool > p; + + // insert 13.8 in doubleSet; insert returns pair in which + // p.first represents location of 13.8 in doubleSet and + // p.second represents whether 13.8 was inserted + p = doubleSet.insert( 13.8 ); // value not in set + + cout << "\n\n" << *( p.first ) + << ( p.second ? " was" : " was not" ) << " inserted"; + + cout << "\ndoubleSet contains: "; + std::copy( doubleSet.begin(), doubleSet.end(), output ); + + // insert 9.5 in doubleSet + p = doubleSet.insert( 9.5 ); // value already in set + + cout << "\n\n" << *( p.first ) + << ( p.second ? " was" : " was not" ) << " inserted"; + + cout << "\ndoubleSet contains: "; + std::copy( doubleSet.begin(), doubleSet.end(), output ); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_21.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_21.CPP new file mode 100644 index 0000000..66036ae --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_21.CPP @@ -0,0 +1,62 @@ +// Fig. 21.21: fig21_21.cpp +// Standard library class multimap test program. +#include + +using std::cout; +using std::endl; + +#include // map class-template definition + +// define short name for multimap type used in this program +typedef std::multimap< int, double, std::less< int > > mmid; + +int main() +{ + mmid pairs; + + cout << "There are currently " << pairs.count( 15 ) + << " pairs with key 15 in the multimap\n"; + + // insert two value_type objects in pairs + pairs.insert( mmid::value_type( 15, 2.7 ) ); + pairs.insert( mmid::value_type( 15, 99.3 ) ); + + cout << "After inserts, there are " + << pairs.count( 15 ) + << " pairs with key 15\n\n"; + + // insert five value_type objects in pairs + pairs.insert( mmid::value_type( 30, 111.11 ) ); + pairs.insert( mmid::value_type( 10, 22.22 ) ); + pairs.insert( mmid::value_type( 25, 33.333 ) ); + pairs.insert( mmid::value_type( 20, 9.345 ) ); + pairs.insert( mmid::value_type( 5, 77.54 ) ); + + cout << "Multimap pairs contains:\nKey\tValue\n"; + + // use const_iterator to walk through elements of pairs + for ( mmid::const_iterator iter = pairs.begin(); + iter != pairs.end(); ++iter ) + cout << iter->first << '\t' + << iter->second << '\n'; + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_22.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_22.CPP new file mode 100644 index 0000000..5dc0f95 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_22.CPP @@ -0,0 +1,68 @@ +// Fig. 21.22: fig21_22.cpp +// Standard library class map test program. +#include + +using std::cout; +using std::endl; + +#include // map class-template definition + +// define short name for map type used in this program +typedef std::map< int, double, std::less< int > > mid; + +int main() +{ + mid pairs; + + // insert eight value_type objects in pairs + pairs.insert( mid::value_type( 15, 2.7 ) ); + pairs.insert( mid::value_type( 30, 111.11 ) ); + pairs.insert( mid::value_type( 5, 1010.1 ) ); + pairs.insert( mid::value_type( 10, 22.22 ) ); + pairs.insert( mid::value_type( 25, 33.333 ) ); + pairs.insert( mid::value_type( 5, 77.54 ) ); // dupe ignored + pairs.insert( mid::value_type( 20, 9.345 ) ); + pairs.insert( mid::value_type( 15, 99.3 ) ); // dupe ignored + + cout << "pairs contains:\nKey\tValue\n"; + + // use const_iterator to walk through elements of pairs + for ( mid::const_iterator iter = pairs.begin(); + iter != pairs.end(); ++iter ) + cout << iter->first << '\t' + << iter->second << '\n'; + + // use subscript operator to change value for key 25 + pairs[ 25 ] = 9999.99; + + // use subscript operator insert value for key 40 + pairs[ 40 ] = 8765.43; + + cout << "\nAfter subscript operations, pairs contains:" + << "\nKey\tValue\n"; + + for ( mid::const_iterator iter2 = pairs.begin(); + iter2 != pairs.end(); ++iter2 ) + cout << iter2->first << '\t' + << iter2->second << '\n'; + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_23.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_23.CPP new file mode 100644 index 0000000..6614c19 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_23.CPP @@ -0,0 +1,74 @@ +// Fig. 21.23: fig21_23.cpp +// Standard library adapter stack test program. +#include + +using std::cout; +using std::endl; + +#include // stack adapter definition +#include // vector class-template definition +#include // list class-template definition + +// popElements function-template prototype +template< class T > +void popElements( T &stackRef ); + +int main() +{ + // stack with default underlying deque + std::stack< int > intDequeStack; + + // stack with underlying vector + std::stack< int, std::vector< int > > intVectorStack; + + // stack with underlying list + std::stack< int, std::list< int > > intListStack; + + // push the values 0-9 onto each stack + for ( int i = 0; i < 10; ++i ) { + intDequeStack.push( i ); + intVectorStack.push( i ); + intListStack.push( i ); + + } // end for + + // display and remove elements from each stack + cout << "Popping from intDequeStack: "; + popElements( intDequeStack ); + cout << "\nPopping from intVectorStack: "; + popElements( intVectorStack ); + cout << "\nPopping from intListStack: "; + popElements( intListStack ); + + cout << endl; + + return 0; + +} // end main + +// pop elements from stack object to which stackRef refers +template< class T > +void popElements( T &stackRef ) +{ + while ( !stackRef.empty() ) { + cout << stackRef.top() << ' '; // view top element + stackRef.pop(); // remove top element + + } // end while + +} // end function popElements + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_24.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_24.CPP new file mode 100644 index 0000000..14fd951 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_24.CPP @@ -0,0 +1,46 @@ +// Fig. 21.24: fig21_24.cpp +// Standard library adapter queue test program. +#include + +using std::cout; +using std::endl; + +#include // queue adapter definition + +int main() +{ + std::queue< double > values; + + // push elements onto queue values + values.push( 3.2 ); + values.push( 9.8 ); + values.push( 5.4 ); + + cout << "Popping from values: "; + + while ( !values.empty() ) { + cout << values.front() << ' '; // view front element + values.pop(); // remove element + + } // end while + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_25.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_25.CPP new file mode 100644 index 0000000..f4b0e2d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_25.CPP @@ -0,0 +1,46 @@ +// Fig. 21.25: fig21_25.cpp +// Standard library adapter priority_queue test program. +#include + +using std::cout; +using std::endl; + +#include // priority_queue adapter definition + +int main() +{ + std::priority_queue< double > priorities; + + // push elements onto priorities + priorities.push( 3.2 ); + priorities.push( 9.8 ); + priorities.push( 5.4 ); + + cout << "Popping from priorities: "; + + while ( !priorities.empty() ) { + cout << priorities.top() << ' '; // view top element + priorities.pop(); // remove top element + + } // end while + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_26.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_26.CPP new file mode 100644 index 0000000..b1aa127 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_26.CPP @@ -0,0 +1,73 @@ +// Fig. 21.26: fig21_26.cpp +// Standard library algorithms fill, fill_n, generate +// and generate_n. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // vector class-template definition + +char nextLetter(); // prototype + +int main() +{ + std::vector< char > chars( 10 ); + std::ostream_iterator< char > output( cout, " " ); + + // fill chars with 5s + std::fill( chars.begin(), chars.end(), '5' ); + + cout << "Vector chars after filling with 5s:\n"; + std::copy( chars.begin(), chars.end(), output ); + + // fill first five elements of chars with As + std::fill_n( chars.begin(), 5, 'A' ); + + cout << "\n\nVector chars after filling five elements" + << " with As:\n"; + std::copy( chars.begin(), chars.end(), output ); + + // generate values for all elements of chars with nextLetter + std::generate( chars.begin(), chars.end(), nextLetter ); + + cout << "\n\nVector chars after generating letters A-J:\n"; + std::copy( chars.begin(), chars.end(), output ); + + // generate values for first five elements of chars + // with nextLetter + std::generate_n( chars.begin(), 5, nextLetter ); + + cout << "\n\nVector chars after generating K-O for the" + << " first five elements:\n"; + std::copy( chars.begin(), chars.end(), output ); + + cout << endl; + + return 0; + +} // end main + +// returns next letter in the alphabet (starts with A) +char nextLetter() +{ + static char letter = 'A'; + return letter++; + +} // end function nextLetter + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_27.cpp b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_27.cpp new file mode 100644 index 0000000..c016b57 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_27.cpp @@ -0,0 +1,86 @@ +// Fig. 21.27: fig21_27.cpp +// Standard library functions equal, +// mismatch and lexicographical_compare. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // vector class-template definition + +int main() +{ + const int SIZE = 10; + int a1[ SIZE ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int a2[ SIZE ] = { 1, 2, 3, 4, 1000, 6, 7, 8, 9, 10 }; + + std::vector< int > v1( a1, a1 + SIZE ); + std::vector< int > v2( a1, a1 + SIZE ); + std::vector< int > v3( a2, a2 + SIZE ); + + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector v1 contains: "; + std::copy( v1.begin(), v1.end(), output ); + cout << "\nVector v2 contains: "; + std::copy( v2.begin(), v2.end(), output ); + cout << "\nVector v3 contains: "; + std::copy( v3.begin(), v3.end(), output ); + + // compare vectors v1 and v2 for equality + bool result = + std::equal( v1.begin(), v1.end(), v2.begin() ); + + cout << "\n\nVector v1 " << ( result ? "is" : "is not" ) + << " equal to vector v2.\n"; + + // compare vectors v1 and v3 for equality + result = std::equal( v1.begin(), v1.end(), v3.begin() ); + cout << "Vector v1 " << ( result ? "is" : "is not" ) + << " equal to vector v3.\n"; + + // location represents pair of vector iterators + std::pair< std::vector< int >::iterator, + std::vector< int >::iterator > location; + + // check for mismatch between v1 and v3 + location = + std::mismatch( v1.begin(), v1.end(), v3.begin() ); + + cout << "\nThere is a mismatch between v1 and v3 at " + << "location " << ( location.first - v1.begin() ) + << "\nwhere v1 contains " << *location.first + << " and v3 contains " << *location.second + << "\n\n"; + + char c1[ SIZE ] = "HELLO"; + char c2[ SIZE ] = "BYE BYE"; + + // perform lexicographical comparison of c1 and c2 + result = std::lexicographical_compare( + c1, c1 + SIZE, c2, c2 + SIZE ); + + cout << c1 + << ( result ? " is less than " : + " is greater than or equal to " ) + << c2 << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_28.cpp b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_28.cpp new file mode 100644 index 0000000..9d36184 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_28.cpp @@ -0,0 +1,102 @@ +// Fig. 21.28: fig21_28.cpp +// Standard library functions remove, remove_if, +// remove_copy and remove_copy_if. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // vector class-template definition + +bool greater9( int ); // prototype + +int main() +{ + const int SIZE = 10; + int a[ SIZE ] = { 10, 2, 10, 4, 16, 6, 14, 8, 12, 10 }; + + std::ostream_iterator< int > output( cout, " " ); + + std::vector< int > v( a, a + SIZE ); + std::vector< int >::iterator newLastElement; + + cout << "Vector v before removing all 10s:\n "; + std::copy( v.begin(), v.end(), output ); + + // remove 10 from v + newLastElement = std::remove( v.begin(), v.end(), 10 ); + + cout << "\nVector v after removing all 10s:\n "; + std::copy( v.begin(), newLastElement, output ); + + std::vector< int > v2( a, a + SIZE ); + std::vector< int > c( SIZE, 0 ); + + cout << "\n\nVector v2 before removing all 10s " + << "and copying:\n "; + std::copy( v2.begin(), v2.end(), output ); + + // copy from v2 to c, removing 10s in the process + std::remove_copy( v2.begin(), v2.end(), c.begin(), 10 ); + + cout << "\nVector c after removing all 10s from v2:\n "; + std::copy( c.begin(), c.end(), output ); + + std::vector< int > v3( a, a + SIZE ); + + cout << "\n\nVector v3 before removing all elements" + << "\ngreater than 9:\n "; + std::copy( v3.begin(), v3.end(), output ); + + // remove elements greater than 9 from v3 + newLastElement = + std::remove_if( v3.begin(), v3.end(), greater9 ); + + cout << "\nVector v3 after removing all elements" + << "\ngreater than 9:\n "; + std::copy( v3.begin(), newLastElement, output ); + + std::vector< int > v4( a, a + SIZE ); + std::vector< int > c2( SIZE, 0 ); + + cout << "\n\nVector v4 before removing all elements" + << "\ngreater than 9 and copying:\n "; + std::copy( v4.begin(), v4.end(), output ); + + // copy elements from v4 to c2, removing elements greater + // than 9 in the process + std::remove_copy_if( + v4.begin(), v4.end(), c2.begin(), greater9 ); + + cout << "\nVector c2 after removing all elements" + << "\ngreater than 9 from v4:\n "; + std::copy( c2.begin(), c2.end(), output ); + + cout << endl; + + return 0; + +} // end main + +// determine whether argument is greater than 9 +bool greater9( int x ) +{ + return x > 9; + +} // end greater9 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_29.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_29.CPP new file mode 100644 index 0000000..252fed4 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_29.CPP @@ -0,0 +1,99 @@ +// Fig. 21.29: fig21_29.cpp +// Standard library functions replace, replace_if, +// replace_copy and replace_copy_if. +#include + +using std::cout; +using std::endl; + +#include +#include + +bool greater9( int ); + +int main() +{ + const int SIZE = 10; + int a[ SIZE ] = { 10, 2, 10, 4, 16, 6, 14, 8, 12, 10 }; + + std::ostream_iterator< int > output( cout, " " ); + + std::vector< int > v1( a, a + SIZE ); + cout << "Vector v1 before replacing all 10s:\n "; + std::copy( v1.begin(), v1.end(), output ); + + // replace 10s in v1 with 100 + std::replace( v1.begin(), v1.end(), 10, 100 ); + + cout << "\nVector v1 after replacing 10s with 100s:\n "; + std::copy( v1.begin(), v1.end(), output ); + + std::vector< int > v2( a, a + SIZE ); + std::vector< int > c1( SIZE ); + + cout << "\n\nVector v2 before replacing all 10s " + << "and copying:\n "; + std::copy( v2.begin(), v2.end(), output ); + + // copy from v2 to c1, replacing 10s with 100s + std::replace_copy( + v2.begin(), v2.end(), c1.begin(), 10, 100 ); + + cout << "\nVector c1 after replacing all 10s in v2:\n "; + std::copy( c1.begin(), c1.end(), output ); + + std::vector< int > v3( a, a + SIZE ); + + cout << "\n\nVector v3 before replacing values greater" + << " than 9:\n "; + std::copy( v3.begin(), v3.end(), output ); + + // replace values greater than 9 in v3 with 100 + std::replace_if( v3.begin(), v3.end(), greater9, 100 ); + + cout << "\nVector v3 after replacing all values greater" + << "\nthan 9 with 100s:\n "; + std::copy( v3.begin(), v3.end(), output ); + + std::vector< int > v4( a, a + SIZE ); + std::vector< int > c2( SIZE ); + + cout << "\n\nVector v4 before replacing all values greater " + << "than 9 and copying:\n "; + std::copy( v4.begin(), v4.end(), output ); + + // copy v4 to c2, replacing elements greater than 9 with 100 + std::replace_copy_if( + v4.begin(), v4.end(), c2.begin(), greater9, 100 ); + + cout << "\nVector c2 after replacing all values greater " + << "than 9 in v4:\n "; + std::copy( c2.begin(), c2.end(), output ); + + cout << endl; + + return 0; + +} // end main + +// determine whether argument is greater than 9 +bool greater9( int x ) +{ + return x > 9; + +} // end function greater9 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_30.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_30.CPP new file mode 100644 index 0000000..c961976 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_30.CPP @@ -0,0 +1,116 @@ +// Fig. 21.30: fig21_30.cpp +// Mathematical algorithms of the standard library. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // accumulate is defined here +#include + +bool greater9( int ); +void outputSquare( int ); +int calculateCube( int ); + +int main() +{ + const int SIZE = 10; + int a1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + std::vector< int > v( a1, a1 + SIZE ); + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector v before random_shuffle: "; + std::copy( v.begin(), v.end(), output ); + + // shuffle elements of v + std::random_shuffle( v.begin(), v.end() ); + + cout << "\nVector v after random_shuffle: "; + std::copy( v.begin(), v.end(), output ); + + int a2[] = { 100, 2, 8, 1, 50, 3, 8, 8, 9, 10 }; + std::vector< int > v2( a2, a2 + SIZE ); + + cout << "\n\nVector v2 contains: "; + std::copy( v2.begin(), v2.end(), output ); + + // count number of elements in v2 with value 8 + int result = std::count( v2.begin(), v2.end(), 8 ); + + std::cout << "\nNumber of elements matching 8: " << result; + + // count number of elements in v2 that are greater than 9 + result = std::count_if( v2.begin(), v2.end(), greater9 ); + + cout << "\nNumber of elements greater than 9: " << result; + + // locate minimum element in v2 + cout << "\n\nMinimum element in Vector v2 is: " + << *( std::min_element( v2.begin(), v2.end() ) ); + + // locate maximum element in v2 + cout << "\nMaximum element in Vector v2 is: " + << *( std::max_element( v2.begin(), v2.end() ) ); + + // calculate sum of elements in v + cout << "\n\nThe total of the elements in Vector v is: " + << std::accumulate( v.begin(), v.end(), 0 ); + + cout << "\n\nThe square of every integer in Vector v is:\n"; + + // output square of every element in v + std::for_each( v.begin(), v.end(), outputSquare ); + + std::vector< int > cubes( SIZE ); + + // calculate cube of each element in v; + // place results in cubes + std::transform( + v.begin(), v.end(), cubes.begin(), calculateCube ); + + cout << "\n\nThe cube of every integer in Vector v is:\n"; + std::copy( cubes.begin(), cubes.end(), output ); + + cout << endl; + + return 0; + +} // end main + +// determine whether argument is greater than 9 +bool greater9( int value ) +{ + return value > 9; + +} // end function greater9 + +// output square of argument +void outputSquare( int value ) +{ + cout << value * value << ' '; + +} // end function outputSquare + +// return cube of argument +int calculateCube( int value ) +{ + return value * value * value; + +} // end function calculateCube + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_31.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_31.CPP new file mode 100644 index 0000000..97720e4 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_31.CPP @@ -0,0 +1,97 @@ +// Fig. 21.31: fig21_31.cpp +// Standard library search and sort algorithms. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // vector class-template definition + +bool greater10( int value ); // prototype + +int main() +{ + const int SIZE = 10; + int a[ SIZE ] = { 10, 2, 17, 5, 16, 8, 13, 11, 20, 7 }; + + std::vector< int > v( a, a + SIZE ); + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector v contains: "; + std::copy( v.begin(), v.end(), output ); + + // locate first occurrence of 16 in v + std::vector< int >::iterator location; + location = std::find( v.begin(), v.end(), 16 ); + + if ( location != v.end() ) + cout << "\n\nFound 16 at location " + << ( location - v.begin() ); + else + cout << "\n\n16 not found"; + + // locate first occurrence of 100 in v + location = std::find( v.begin(), v.end(), 100 ); + + if ( location != v.end() ) + cout << "\nFound 100 at location " + << ( location - v.begin() ); + else + cout << "\n100 not found"; + + // locate first occurrence of value greater than 10 in v + location = std::find_if( v.begin(), v.end(), greater10 ); + + if ( location != v.end() ) + cout << "\n\nThe first value greater than 10 is " + << *location << "\nfound at location " + << ( location - v.begin() ); + else + cout << "\n\nNo values greater than 10 were found"; + + // sort elements of v + std::sort( v.begin(), v.end() ); + + cout << "\n\nVector v after sort: "; + std::copy( v.begin(), v.end(), output ); + + // use binary_search to locate 13 in v + if ( std::binary_search( v.begin(), v.end(), 13 ) ) + cout << "\n\n13 was found in v"; + else + cout << "\n\n13 was not found in v"; + + // use binary_search to locate 100 in v + if ( std::binary_search( v.begin(), v.end(), 100 ) ) + cout << "\n100 was found in v"; + else + cout << "\n100 was not found in v"; + + cout << endl; + + return 0; + +} // end main + +// determine whether argument is greater than 10 +bool greater10( int value ) +{ + return value > 10; + +} // end function greater10 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_32.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_32.CPP new file mode 100644 index 0000000..439a8da --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_32.CPP @@ -0,0 +1,60 @@ +// Fig. 21.32: fig21_32.cpp +// Standard library algorithms iter_swap, swap and swap_ranges. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions + +int main() +{ + const int SIZE = 10; + int a[ SIZE ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + std::ostream_iterator< int > output( cout, " " ); + + cout << "Array a contains:\n "; + std::copy( a, a + SIZE, output ); + + // swap elements at locations 0 and 1 of array a + std::swap( a[ 0 ], a[ 1 ] ); + + cout << "\nArray a after swapping a[0] and a[1] " + << "using swap:\n "; + std::copy( a, a + SIZE, output ); + + // use iterators to swap elements at locations + // 0 and 1 of array a + std::iter_swap( &a[ 0 ], &a[ 1 ] ); + cout << "\nArray a after swapping a[0] and a[1] " + << "using iter_swap:\n "; + std::copy( a, a + SIZE, output ); + + // swap elements in first five elements of array a with + // elements in last five elements of array a + std::swap_ranges( a, a + 5, a + 5 ); + + cout << "\nArray a after swapping the first five elements\n" + << "with the last five elements:\n "; + std::copy( a, a + SIZE, output ); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_33.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_33.CPP new file mode 100644 index 0000000..f489c5e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_33.CPP @@ -0,0 +1,79 @@ +// Fig. 21.33: fig21_33.cpp +// Standard library functions copy_backward, merge, +// unique and reverse. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // vector class-template definition + +int main() +{ + const int SIZE = 5; + int a1[ SIZE ] = { 1, 3, 5, 7, 9 }; + int a2[ SIZE ] = { 2, 4, 5, 7, 9 }; + + std::vector< int > v1( a1, a1 + SIZE ); + std::vector< int > v2( a2, a2 + SIZE ); + + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector v1 contains: "; + std::copy( v1.begin(), v1.end(), output ); + cout << "\nVector v2 contains: "; + std::copy( v2.begin(), v2.end(), output ); + + std::vector< int > results( v1.size() ); + + // place elements of v1 into results in reverse order + std::copy_backward( v1.begin(), v1.end(), results.end() ); + + cout << "\n\nAfter copy_backward, results contains: "; + std::copy( results.begin(), results.end(), output ); + + std::vector< int > results2( v1.size() + v2.size() ); + + // merge elements of v1 and v2 into results2 in sorted order + std::merge( v1.begin(), v1.end(), v2.begin(), v2.end(), + results2.begin() ); + + cout << "\n\nAfter merge of v1 and v2 results2 contains:\n"; + std::copy( results2.begin(), results2.end(), output ); + + // eliminate duplicate values from results2 + std::vector< int >::iterator endLocation; + endLocation = + std::unique( results2.begin(), results2.end() ); + + cout << "\n\nAfter unique results2 contains:\n"; + std::copy( results2.begin(), endLocation, output ); + + cout << "\n\nVector v1 after reverse: "; + + // reverse elements of v1 + std::reverse( v1.begin(), v1.end() ); + + std::copy( v1.begin(), v1.end(), output ); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_34.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_34.CPP new file mode 100644 index 0000000..e893200 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_34.CPP @@ -0,0 +1,69 @@ +// Fig. 21.34: fig21_34.cpp +// Standard library algorithms inplace_merge, +// reverse_copy and unique_copy. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // vector class-template definition +#include // back_inserter definition + +int main() +{ + const int SIZE = 10; + int a1[ SIZE ] = { 1, 3, 5, 7, 9, 1, 3, 5, 7, 9 }; + std::vector< int > v1( a1, a1 + SIZE ); + + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector v1 contains: "; + std::copy( v1.begin(), v1.end(), output ); + + // merge first half of v1 with second half of v1 such that + // v1 contains sorted set of elements after merge + std::inplace_merge( v1.begin(), v1.begin() + 5, v1.end() ); + + cout << "\nAfter inplace_merge, v1 contains: "; + std::copy( v1.begin(), v1.end(), output ); + + std::vector< int > results1; + + // copy only unique elemements of v1 into results1 + std::unique_copy( + v1.begin(), v1.end(), std::back_inserter( results1 ) ); + + cout << "\nAfter unique_copy results1 contains: "; + std::copy( results1.begin(), results1.end(), output ); + + std::vector< int > results2; + + cout << "\nAfter reverse_copy, results2 contains: "; + + // copy elements of v1 into results2 in reverse order + std::reverse_copy( + v1.begin(), v1.end(), std::back_inserter( results2 ) ); + + std::copy( results2.begin(), results2.end(), output ); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_35.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_35.CPP new file mode 100644 index 0000000..10df8f5 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_35.CPP @@ -0,0 +1,94 @@ +// Fig. 21.35: fig21_35.cpp +// Standard library algorithms includes, set_difference, +// set_intersection, set_symmetric_difference and set_union. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions + +int main() +{ + const int SIZE1 = 10, SIZE2 = 5, SIZE3 = 20; + int a1[ SIZE1 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int a2[ SIZE2 ] = { 4, 5, 6, 7, 8 }; + int a3[ SIZE2 ] = { 4, 5, 6, 11, 15 }; + std::ostream_iterator< int > output( cout, " " ); + + cout << "a1 contains: "; + std::copy( a1, a1 + SIZE1, output ); + cout << "\na2 contains: "; + std::copy( a2, a2 + SIZE2, output ); + cout << "\na3 contains: "; + std::copy( a3, a3 + SIZE2, output ); + + // determine whether set a2 is completely contained in a1 + if ( std::includes( a1, a1 + SIZE1, a2, a2 + SIZE2 ) ) + cout << "\n\na1 includes a2"; + else + cout << "\n\na1 does not include a2"; + + // determine whether set a3 is completely contained in a1 + if ( std::includes( a1, a1 + SIZE1, a3, a3 + SIZE2 ) ) + cout << "\na1 includes a3"; + else + cout << "\na1 does not include a3"; + + int difference[ SIZE1 ]; + + // determine elements of a1 not in a2 + int *ptr = std::set_difference( a1, a1 + SIZE1, + a2, a2 + SIZE2, difference ); + + cout << "\n\nset_difference of a1 and a2 is: "; + std::copy( difference, ptr, output ); + + int intersection[ SIZE1 ]; + + // determine elements in both a1 and a2 + ptr = std::set_intersection( a1, a1 + SIZE1, + a2, a2 + SIZE2, intersection ); + + cout << "\n\nset_intersection of a1 and a2 is: "; + std::copy( intersection, ptr, output ); + + int symmetric_difference[ SIZE1 ]; + + // determine elements of a1 that are not in a2 and + // elements of a2 that are not in a1 + ptr = std::set_symmetric_difference( a1, a1 + SIZE1, + a2, a2 + SIZE2, symmetric_difference ); + + cout << "\n\nset_symmetric_difference of a1 and a2 is: "; + std::copy( symmetric_difference, ptr, output ); + + int unionSet[ SIZE3 ]; + + // determine elements that are in either or both sets + ptr = std::set_union( a1, a1 + SIZE1, + a3, a3 + SIZE2, unionSet ); + + cout << "\n\nset_union of a1 and a3 is: "; + std::copy( unionSet, ptr, output ); + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_36.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_36.CPP new file mode 100644 index 0000000..b742eec --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_36.CPP @@ -0,0 +1,96 @@ +// Fig. 21.36: fig21_36.cpp +// Standard library functions lower_bound, upper_bound and +// equal_range for a sorted sequence of values. +#include + +using std::cout; +using std::endl; + +#include // algorithm definitions +#include // vector class-template definition + +int main() +{ + const int SIZE = 10; + int a1[] = { 2, 2, 4, 4, 4, 6, 6, 6, 6, 8 }; + std::vector< int > v( a1, a1 + SIZE ); + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector v contains:\n"; + std::copy( v.begin(), v.end(), output ); + + // determine lower-bound insertion point for 6 in v + std::vector< int >::iterator lower; + lower = std::lower_bound( v.begin(), v.end(), 6 ); + + cout << "\n\nLower bound of 6 is element " + << ( lower - v.begin() ) << " of vector v"; + + // determine upper-bound insertion point for 6 in v + std::vector< int >::iterator upper; + upper = std::upper_bound( v.begin(), v.end(), 6 ); + + cout << "\nUpper bound of 6 is element " + << ( upper - v.begin() ) << " of vector v"; + + // use equal_range to determine both the lower- and + // upper-bound insertion points for 6 + std::pair< std::vector< int >::iterator, + std::vector< int >::iterator > eq; + eq = std::equal_range( v.begin(), v.end(), 6 ); + + cout << "\nUsing equal_range:\n" + << " Lower bound of 6 is element " + << ( eq.first - v.begin() ) << " of vector v"; + cout << "\n Upper bound of 6 is element " + << ( eq.second - v.begin() ) << " of vector v"; + + cout << "\n\nUse lower_bound to locate the first point\n" + << "at which 5 can be inserted in order"; + + // determine lower-bound insertion point for 5 in v + lower = std::lower_bound( v.begin(), v.end(), 5 ); + + cout << "\n Lower bound of 5 is element " + << ( lower - v.begin() ) << " of vector v"; + + cout << "\n\nUse upper_bound to locate the last point\n" + << "at which 7 can be inserted in order"; + + // determine upper-bound insertion point for 7 in v + upper = std::upper_bound( v.begin(), v.end(), 7 ); + + cout << "\n Upper bound of 7 is element " + << ( upper - v.begin() ) << " of vector v"; + + cout << "\n\nUse equal_range to locate the first and\n" + << "last point at which 5 can be inserted in order"; + + // use equal_range to determine both the lower- and + // upper-bound insertion points for 5 + eq = std::equal_range( v.begin(), v.end(), 5 ); + + cout << "\n Lower bound of 5 is element " + << ( eq.first - v.begin() ) << " of vector v"; + cout << "\n Upper bound of 5 is element " + << ( eq.second - v.begin() ) << " of vector v" + << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_37.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_37.CPP new file mode 100644 index 0000000..496b449 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_37.CPP @@ -0,0 +1,79 @@ +// Fig. 21.37: fig21_37.cpp +// Standard library algorithms push_heap, pop_heap, +// make_heap and sort_heap. +#include + +using std::cout; +using std::endl; + +#include +#include + +int main() +{ + const int SIZE = 10; + int a[ SIZE ] = { 3, 100, 52, 77, 22, 31, 1, 98, 13, 40 }; + std::vector< int > v( a, a + SIZE ), v2; + std::ostream_iterator< int > output( cout, " " ); + + cout << "Vector v before make_heap:\n"; + std::copy( v.begin(), v.end(), output ); + + // create heap from vector v + std::make_heap( v.begin(), v.end() ); + + cout << "\nVector v after make_heap:\n"; + std::copy( v.begin(), v.end(), output ); + + // sort elements of v with sort_heap + std::sort_heap( v.begin(), v.end() ); + + cout << "\nVector v after sort_heap:\n"; + std::copy( v.begin(), v.end(), output ); + + // perform the heapsort with push_heap and pop_heap + cout << "\n\nArray a contains: "; + std::copy( a, a + SIZE, output ); + + cout << endl; + + // place elements of array a into v2 and + // maintain elements of v2 in heap + for ( int i = 0; i < SIZE; ++i ) { + v2.push_back( a[ i ] ); + std::push_heap( v2.begin(), v2.end() ); + cout << "\nv2 after push_heap(a[" << i << "]): "; + std::copy( v2.begin(), v2.end(), output ); + + } // end for + + cout << endl; + + // remove elements from heap in sorted order + for ( int j = 0; j < v2.size(); ++j ) { + cout << "\nv2 after " << v2[ 0 ] << " popped from heap\n"; + std::pop_heap( v2.begin(), v2.end() - j ); + std::copy( v2.begin(), v2.end(), output ); + + } // end for + + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_38.cpp b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_38.cpp new file mode 100644 index 0000000..907c83e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_38.cpp @@ -0,0 +1,38 @@ +// Fig. 21.38: fig21_38.cpp +// Standard library algorithms min and max. +#include + +using std::cout; +using std::endl; + +#include + +int main() +{ + cout << "The minimum of 12 and 7 is: " + << std::min( 12, 7 ); + cout << "\nThe maximum of 12 and 7 is: " + << std::max( 12, 7 ); + cout << "\nThe minimum of 'G' and 'Z' is: " + << std::min( 'G', 'Z' ); + cout << "\nThe maximum of 'G' and 'Z' is: " + << std::max( 'G', 'Z' ) << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_40.CPP b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_40.CPP new file mode 100644 index 0000000..e1d8a91 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_40.CPP @@ -0,0 +1,82 @@ +// Fig. 21.40: fig21_40.cpp +// Using a bitset to demonstrate the Sieve of Eratosthenes. +#include + +using std::cin; +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include // bitset class definition +#include // sqrt prototype + +int main() +{ + const int size = 1024; + int value; + std::bitset< size > sieve; + + sieve.flip(); + + // perform Sieve of Eratosthenes + int finalBit = sqrt( sieve.size() ) + 1; + + for ( int i = 2; i < finalBit; ++i ) + + if ( sieve.test( i ) ) + + for ( int j = 2 * i; j < size; j += i ) + sieve.reset( j ); + + cout << "The prime numbers in the range 2 to 1023 are:\n"; + + // display prime numbers in range 2-1023 + for ( int k = 2, counter = 0; k < size; ++k ) + + if ( sieve.test( k ) ) { + cout << setw( 5 ) << k; + + if ( ++counter % 12 == 0 ) + cout << '\n'; + + } // end outer if + + cout << endl; + + // get value from user to determine whether value is prime + cout << "\nEnter a value from 1 to 1023 (-1 to end): "; + cin >> value; + + while ( value != -1 ) { + + if ( sieve[ value ] ) + cout << value << " is a prime number\n"; + else + cout << value << " is not a prime number\n"; + + cout << "\nEnter a value from 2 to 1023 (-1 to end): "; + cin >> value; + + } // end while + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_42.cpp b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_42.cpp new file mode 100644 index 0000000..4dc79f8 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/7_ch21/fig21_42.cpp @@ -0,0 +1,86 @@ +// Fig. 21.42: fig21_42.cpp +// Demonstrating function objects. +#include + +using std::cout; +using std::endl; + +#include // vector class-template definition +#include // copy algorithm +#include // accumulate algorithm +#include // binary_function definition + +// binary function adds square of its second argument and +// running total in its first argument, then returns sum +int sumSquares( int total, int value ) +{ + return total + value * value; + +} // end function sumSquares + +// binary function class template defines overloaded operator() +// that adds suare of its second argument and running total in +// its first argument, then returns sum +template< class T > +class SumSquaresClass : public std::binary_function< T, T, T > { + +public: + + // add square of value to total and return result + const T operator()( const T &total, const T &value ) + { + return total + value * value; + + } // end function operator() + +}; // end class SumSquaresClass + +int main() +{ + const int SIZE = 10; + int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + std::vector< int > integers( array, array + SIZE ); + + std::ostream_iterator< int > output( cout, " " ); + + int result = 0; + + cout << "vector v contains:\n"; + std::copy( integers.begin(), integers.end(), output ); + + // calculate sum of squares of elements of vector integers + // using binary function sumSquares + result = std::accumulate( integers.begin(), integers.end(), + 0, sumSquares ); + + cout << "\n\nSum of squares of elements in integers using " + << "binary\nfunction sumSquares: " << result; + + // calculate sum of squares of elements of vector integers + // using binary-function object + result = std::accumulate( integers.begin(), integers.end(), + 0, SumSquaresClass< int >() ); + + cout << "\n\nSum of squares of elements in integers using " + << "binary\nfunction object of type " + << "SumSquaresClass< int >: " << result << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/8_ch13/Fig13_01.cpp b/Bachelor/Prog2/Codebeispiele/8_ch13/Fig13_01.cpp new file mode 100644 index 0000000..1d3ba0b --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/8_ch13/Fig13_01.cpp @@ -0,0 +1,89 @@ +// Fig. 13.1: fig13_01.cpp +// A simple exception-handling example that checks for +// divide-by-zero exceptions. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::exception; + +// DivideByZeroException objects should be thrown by functions +// upon detecting division-by-zero exceptions +class DivideByZeroException : public exception { + +public: + + // constructor specifies default error message + DivideByZeroException::DivideByZeroException() + : exception( "attempted to divide by zero" ) {} + +}; // end class DivideByZeroException + +// perform division and throw DivideByZeroException object if +// divide-by-zero exception occurs +double quotient( int numerator, int denominator ) +{ + // throw DivideByZeroException if trying to divide by zero + if ( denominator == 0 ) + throw DivideByZeroException(); // terminate function + + // return division result + return static_cast< double >( numerator ) / denominator; + +} // end function quotient + +int main() +{ + int number1; // user-specified numerator + int number2; // user-specified denominator + double result; // result of division + + cout << "Enter two integers (end-of-file to end): "; + + // enable user to enter two integers to divide + while ( cin >> number1 >> number2 ) { + + // try block contains code that might throw exception + // and code that should not execute if an exception occurs + try { + result = quotient( number1, number2 ); + cout << "The quotient is: " << result << endl; + + } // end try + + // exception handler handles a divide-by-zero exception + catch ( DivideByZeroException ÷ByZeroException ) { + cout << "Exception occurred: " << + divideByZeroException.what() << endl; + + } // end catch + + cout << "\nEnter two integers (end-of-file to end): "; + + } // end while + + cout << endl; + + return 0; // terminate normally + +} // end main + + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_02.cpp b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_02.cpp new file mode 100644 index 0000000..f685afb --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_02.cpp @@ -0,0 +1,71 @@ +// Fig. 13.2: fig13_02.cpp +// Demonstrating exception rethrowing. +#include + +using std::cout; +using std::endl; + +#include + +using std::exception; + +// throw, catch and rethrow exception +void throwException() +{ + // throw exception and catch it immediately + try { + cout << " Function throwException throws an exception\n"; + throw exception(); // generate exception + + } // end try + + // handle exception + catch ( exception &caughtException ) { + cout << " Exception handled in function throwException" + << "\n Function throwException rethrows exception"; + + throw; // rethrow exception for further processing + + } // end catch + + cout << "This also should not print\n"; + +} // end function throwException + +int main() +{ + // throw exception + try { + cout << "\nmain invokes function throwException\n"; + throwException(); + cout << "This should not print\n"; + + } // end try + + // handle exception + catch ( exception &caughtException ) { + cout << "\n\nException handled in main\n"; + + } // end catch + + cout << "Program control continues after catch in main\n"; + + return 0; + +} // end main + + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_03.cpp b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_03.cpp new file mode 100644 index 0000000..c9147e8 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_03.cpp @@ -0,0 +1,63 @@ +// Fig. 13.3: fig13_03.cpp +// Demonstrating stack unwinding. +#include + +using std::cout; +using std::endl; + +#include + +using std::runtime_error; + +// function3 throws run-time error +void function3() throw ( runtime_error ) +{ + throw runtime_error( "runtime_error in function3" ); // fourth +} + +// function2 invokes function3 +void function2() throw ( runtime_error ) +{ + function3(); // third +} + +// function1 invokes function2 +void function1() throw ( runtime_error ) +{ + function2(); // second +} + +// demonstrate stack unwinding +int main() +{ + // invoke function1 + try { + function1(); // first + + } // end try + + // handle run-time error + catch ( runtime_error &error ) // fifth + { + cout << "Exception occurred: " << error.what() << endl; + + } // end catch + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_04.cpp b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_04.cpp new file mode 100644 index 0000000..34f588a --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_04.cpp @@ -0,0 +1,49 @@ +// Fig. 13.4: fig13_04.cpp +// Demonstrating pre-standard new returning 0 when memory +// is not allocated. +#include + +using std::cout; + +int main() +{ + double *ptr[ 50 ]; + + // allocate memory for ptr + for ( int i = 0; i < 50; i++ ) { + ptr[ i ] = new double[ 5000000 ]; + + // new returns 0 on failure to allocate memory + if ( ptr[ i ] == 0 ) { + cout << "Memory allocation failed for ptr[ " + << i << " ]\n"; + + break; + + } // end if + + // successful memory allocation + else + cout << "Allocated 5000000 doubles in ptr[ " + << i << " ]\n"; + + } // end for + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_05.cpp b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_05.cpp new file mode 100644 index 0000000..4fde5dd --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_05.cpp @@ -0,0 +1,54 @@ +// Fig. 13.5: fig13_05.cpp +// Demonstrating standard new throwing bad_alloc when memory +// cannot be allocated. +#include + +using std::cout; +using std::endl; + +#include // standard operator new + +using std::bad_alloc; + +int main() +{ + double *ptr[ 50 ]; + + // attempt to allocate memory + try { + + // allocate memory for ptr[ i ]; new throws bad_alloc + // on failure + for ( int i = 0; i < 50; i++ ) { + ptr[ i ] = new double[ 5000000 ]; + cout << "Allocated 5000000 doubles in ptr[ " + << i << " ]\n"; + } + + } // end try + + // handle bad_alloc exception + catch ( bad_alloc &memoryAllocationException ) { + cout << "Exception occurred: " + << memoryAllocationException.what() << endl; + + } // end catch + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_06.cpp b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_06.cpp new file mode 100644 index 0000000..b9656fb --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_06.cpp @@ -0,0 +1,53 @@ +// Fig. 13.6: fig13_06.cpp +// Demonstrating set_new_handler. +#include + +using std::cout; +using std::cerr; + +#include // standard operator new +#include // abort function prototype + +void customNewHandler() +{ + cerr << "customNewHandler was called"; + abort(); +} + +// using set_new_handler to handle failed memory allocation +int main() +{ + double *ptr[ 50 ]; + + // specify that customNewHandler should be called on failed + // memory allocation + set_new_handler( customNewHandler ); + + // allocate memory for ptr[ i ]; customNewHandler will be + // called on failed memory allocation + for ( int i = 0; i < 50; i++ ) { + ptr[ i ] = new double[ 5000000 ]; + + cout << "Allocated 5000000 doubles in ptr[ " + << i << " ]\n"; + + } // end for + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_07.cpp b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_07.cpp new file mode 100644 index 0000000..975c0fc --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/8_ch13/fig13_07.cpp @@ -0,0 +1,86 @@ +// Fig. 13.7: fig13_07.cpp +// Demonstrating auto_ptr. +#include + +using std::cout; +using std::endl; + +#include + +using std::auto_ptr; // auto_ptr class definition + +class Integer { + +public: + + // Integer constructor + Integer( int i = 0 ) + : value( i ) + { + cout << "Constructor for Integer " << value << endl; + + } // end Integer constructor + + // Integer destructor + ~Integer() + { + cout << "Destructor for Integer " << value << endl; + + } // end Integer destructor + + // functions to set Integer + void setInteger( int i ) + { + value = i; + + } // end function setInteger + + // function to return Integer + int getInteger() const + { + return value; + + } // end function getInteger + +private: + int value; + +}; // end class Integer + +// use auto_ptr to manipulate Integer object +int main() +{ + cout << "Creating an auto_ptr object that points to an " + << "Integer\n"; + + // "aim" auto_ptr at Integer object + auto_ptr< Integer > ptrToInteger( new Integer( 7 ) ); + + cout << "\nUsing the auto_ptr to manipulate the Integer\n"; + + // use auto_ptr to set Integer value + ptrToInteger->setInteger( 99 ); + + // use auto_ptr to get Integer value + cout << "Integer after setInteger: " + << ( *ptrToInteger ).getInteger() + << "\n\nTerminating program" << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/Student/StudDat.cpp b/Bachelor/Prog2/Codebeispiele/Student/StudDat.cpp new file mode 100644 index 0000000..306ae62 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/Student/StudDat.cpp @@ -0,0 +1,35 @@ +// Persistence of objects: Storing of Student-Objects +// Author: Hans-Peter Weber +// Date: 07.03.05 + +#include +using std::cout; +using std::endl; +using std::ios; + +#include +using std::fstream; + +#include "Student.h" + +int main() +{ + Student stud; + + cout << "Adresse von Student-Objekt: " << &stud << endl; + cout << "Groesse von Student-Objekt: " << sizeof( Student ) << " Byte" << endl; + +/* fstream outFile( "Studs.seq", ios::binary | ios::out ); // write + stud.set( "Hans Castorp", 578111, 23 ); + stud.write( outFile ); + stud.set( "Claudia Chauchat", 578666, 27 ); + stud.write( outFile ); + outFile.close(); +*/ + fstream inFile( "Studs.seq", ios::binary | ios::in ); // read + while( stud.read( inFile ) ) + stud.print(); + inFile.close(); + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/Student/Student.cpp b/Bachelor/Prog2/Codebeispiele/Student/Student.cpp new file mode 100644 index 0000000..d58d6df --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/Student/Student.cpp @@ -0,0 +1,49 @@ +// Student.cpp: Implementation of class Student. + +#include +using std::cout; +using std::endl; +using std::istream; +using std::ostream; + +#include +using std::string; +using std::getline; + +#include "Student.h" + +Student::Student() +{ +} + +Student::~Student() +{ +} + +void Student::set( string n, int m, int a ) +{ + name = n; + matNr = m; + age = a; +} + +void Student::print() +{ + cout << name << ", Matrikelnummer: " << matNr << ", Alter: " << age << endl; +} + +ostream& Student::write( std::ostream& os ) const +{ +// os.write( ( char* )&matNr, sizeof matNr ); // stores '578111' as an int in 4 Bytes +// os << matNr; // stores '578111' as ASCII-Code in 6 Bytes! + os << name << '\0'; // write string + os.write( ( char* ) &matNr, 2 * sizeof( int ) ); // write 2 int starting at address of matNr + return os; +} + +istream& Student::read( std::istream& is ) +{ + getline( is, name, '\0' ); // read string + is.read( ( char* ) &matNr, 2 * sizeof( int ) ); // read 2 int starting at address of matNr + return is; +} \ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/Student/Student.h b/Bachelor/Prog2/Codebeispiele/Student/Student.h new file mode 100644 index 0000000..3bcb426 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/Student/Student.h @@ -0,0 +1,26 @@ +// Student.h: Interface for class Student. + +#if !defined STUDENT_H +#define STUDENT_H + +#include + +class Student +{ + +public: + Student(); + ~Student(); + void set( std::string, int, int ); + void print(); + std::ostream& write( std::ostream& ) const; + std::istream& read( std::istream& ); + +private: + std::string name; + int matNr; + int age; + +}; + +#endif diff --git a/Bachelor/Prog2/Codebeispiele/ex9_21.zip b/Bachelor/Prog2/Codebeispiele/ex9_21.zip new file mode 100644 index 0000000..36256da Binary files /dev/null and b/Bachelor/Prog2/Codebeispiele/ex9_21.zip differ diff --git a/Bachelor/Prog2/FileIn/Demo.txt b/Bachelor/Prog2/FileIn/Demo.txt new file mode 100644 index 0000000..cd18069 --- /dev/null +++ b/Bachelor/Prog2/FileIn/Demo.txt @@ -0,0 +1,16 @@ +String Integer1 Integer2 +Eins 2 3 +Zwei 3 4 +Drei 4 ? +Vier 5 6 +Fuenf ? 7 +sechs 7 8 +Sieben 8 9 +Sieben,Fuenf 9 9 +Sieben,Sechs ? ? +Sieben Drei Viertel 9 10 +Acht 9 10 +9 10 11 +Kurz vor 10 11 12 +10 11 ! + diff --git a/Bachelor/Prog2/FileIn/FileIn.cpp b/Bachelor/Prog2/FileIn/FileIn.cpp new file mode 100644 index 0000000..6395c39 --- /dev/null +++ b/Bachelor/Prog2/FileIn/FileIn.cpp @@ -0,0 +1,67 @@ +// reading a file that contains data in wrong format +// Author: H.P.Weber +// Date: 26.06.05 + +#include +using std::cout; +using std::cerr; +using std::endl; +using std::ios; +using std::left; + +#include +using std::setw; + +#include +using std::ifstream; + +#include +using std::string; +using std::getline; + +int main() { + + ifstream inFile( "Demo.txt" ); + if( !inFile ) { + cerr << "Datei kann nicht geoeffnet werden.\n"; + exit( 1 ); + } + + string headline; + getline( inFile, headline ); // read header + + // input records from file + string stringVariable; + int intVariable1, intVariable2; + + while( true ) { + + std::ws( inFile ); // remove leading whitespace + getline( inFile, stringVariable, '\t'); + inFile >> intVariable1; + inFile >> intVariable2; + + if( !inFile.good() ) { + // if not complete, read complete line from buffer + inFile.clear(); + string str; + getline( inFile, str, '\n' ); + inFile.setstate( ios::failbit ); + } + + if( inFile.eof() ) break; + + if( !inFile.good() ) { // record not complete + cout << "Unvollstaendiger Datensatz" << endl; + inFile.clear(); + } + + else // record complete + cout << left << setw( 30 ) << stringVariable << setw( 10 ) << intVariable1 + << setw( 10 ) << intVariable2 << endl; + } + + inFile.close(); + + return 0; +} diff --git a/Bachelor/Prog2/Folien/1_chapter09.ppt b/Bachelor/Prog2/Folien/1_chapter09.ppt new file mode 100644 index 0000000..8b27c1a Binary files /dev/null and b/Bachelor/Prog2/Folien/1_chapter09.ppt differ diff --git a/Bachelor/Prog2/Folien/2_chapter10.ppt b/Bachelor/Prog2/Folien/2_chapter10.ppt new file mode 100644 index 0000000..f7f7ea4 Binary files /dev/null and b/Bachelor/Prog2/Folien/2_chapter10.ppt differ diff --git a/Bachelor/Prog2/Folien/3_chapter15.ppt b/Bachelor/Prog2/Folien/3_chapter15.ppt new file mode 100644 index 0000000..d1c9714 Binary files /dev/null and b/Bachelor/Prog2/Folien/3_chapter15.ppt differ diff --git a/Bachelor/Prog2/Folien/4_chapter14.ppt b/Bachelor/Prog2/Folien/4_chapter14.ppt new file mode 100644 index 0000000..55baf18 Binary files /dev/null and b/Bachelor/Prog2/Folien/4_chapter14.ppt differ diff --git a/Bachelor/Prog2/Folien/5_chapter11.ppt b/Bachelor/Prog2/Folien/5_chapter11.ppt new file mode 100644 index 0000000..6cdaf05 Binary files /dev/null and b/Bachelor/Prog2/Folien/5_chapter11.ppt differ diff --git a/Bachelor/Prog2/Folien/6_chapter17.ppt b/Bachelor/Prog2/Folien/6_chapter17.ppt new file mode 100644 index 0000000..3b3aeb1 Binary files /dev/null and b/Bachelor/Prog2/Folien/6_chapter17.ppt differ diff --git a/Bachelor/Prog2/Folien/7_chapter21.ppt b/Bachelor/Prog2/Folien/7_chapter21.ppt new file mode 100644 index 0000000..fa29f35 Binary files /dev/null and b/Bachelor/Prog2/Folien/7_chapter21.ppt differ diff --git a/Bachelor/Prog2/Folien/8_chapter13.ppt b/Bachelor/Prog2/Folien/8_chapter13.ppt new file mode 100644 index 0000000..31726be Binary files /dev/null and b/Bachelor/Prog2/Folien/8_chapter13.ppt differ diff --git a/Bachelor/Prog2/Folien/chap9_21.zip b/Bachelor/Prog2/Folien/chap9_21.zip new file mode 100644 index 0000000..4ada5da Binary files /dev/null and b/Bachelor/Prog2/Folien/chap9_21.zip differ diff --git a/Bachelor/Prog2/ListIterator/ListIter.cpp b/Bachelor/Prog2/ListIterator/ListIter.cpp new file mode 100644 index 0000000..166850c --- /dev/null +++ b/Bachelor/Prog2/ListIterator/ListIter.cpp @@ -0,0 +1,46 @@ +// List class with Iterator +// for illustration purposes only, no robust implementation ( no error-ckecking, etc) + +#include +using std::cout; +using std::endl; + +#include +#include + +#include "list.h" // List class definition + +void print( int& intValue) +{ + cout << intValue << " "; +} + +int main() +{ + // test List of int values + List< int > integerList; + + cout << "insertAtFront square numbers:\n"; + for( int i = 0; i < 10; ++i) + integerList.insertAtFront( i*i ); + + List< int >::Iterator listIter( integerList ); + + // using iterator like pointer: + for( int j = 0; j < 10; ++j) { + cout << *listIter << " "; + ++listIter; + } + cout << endl; + + // using iterator with STL algorithms: + cout << "Summe: " << + std::accumulate( integerList.begin(), integerList.end(), 0 ); + cout << "\nAusgabe der Werte:\n"; + std::for_each( integerList.begin(), integerList.end(), print ); + + cout << endl << endl; + + return 0; + +} // end main \ No newline at end of file diff --git a/Bachelor/Prog2/ListIterator/list1.h b/Bachelor/Prog2/ListIterator/list1.h new file mode 100644 index 0000000..93ff588 --- /dev/null +++ b/Bachelor/Prog2/ListIterator/list1.h @@ -0,0 +1,248 @@ +// Template List class definition +// for illustration purposes only, no robust implementation ( no error-ckecking, etc) + +#ifndef LIST_H +#define LIST_H + +#include +using std::cout; + +#include + +template< class NODETYPE > +class List { + +public: + List(); // constructor + ~List(); // destructor + void insertAtFront( const NODETYPE & ); + void insertAtBack( const NODETYPE & ); + bool removeFromFront( NODETYPE & ); + bool removeFromBack( NODETYPE & ); + bool isEmpty() const; + void print() const; + +private: + struct ListNode { + ListNode( const NODETYPE & info ): data( info ), nextPtr( 0 ) { } // constructor + NODETYPE data; // data + ListNode* nextPtr; // next node in list + }; // end struct ListNode + + ListNode* firstPtr; // pointer to first node + ListNode* lastPtr; // pointer to last node + +public: + class Iterator { // public access! + public: + friend class List< NODETYPE >; + + Iterator( ListNode* initPos = 0 ) : currentPos( initPos ) { } + Iterator( const List< NODETYPE >& currentList ) + { + *this = currentList.begin(); + } + + const NODETYPE& operator*() const + { + return currentPos->data; + } + NODETYPE& operator*() + { + return currentPos->data; + } + + Iterator& operator++() // prefix + { + if( currentPos ) + currentPos = currentPos->nextPtr; + return *this; + } + Iterator operator++( int ) // postfix + { + Iterator temp = *this; + ++*this; + return temp; + } + + bool operator==( const Iterator& x ) const + { + return currentPos == x.currentPos; + } + bool operator!=( const Iterator& x ) const + { + return currentPos != x.currentPos; + } + + private: + ListNode* currentPos; + }; // end class Iterator + + Iterator begin() const + { + return Iterator( firstPtr ); + } + Iterator end() const + { + return Iterator(); + } +}; // end class List + +// default constructor +template< class NODETYPE > +List< NODETYPE >::List() + : firstPtr( 0 ), + lastPtr( 0 ) +{ + // empty body + +} // end List constructor + +// destructor +template< class NODETYPE > +List< NODETYPE >::~List() +{ + if ( !isEmpty() ) { // List is not empty + cout << "Destroying nodes ...\n"; + + ListNode *currentPtr = firstPtr; + ListNode *tempPtr; + + while ( currentPtr != 0 ) { // delete remaining nodes + tempPtr = currentPtr; + cout << tempPtr->data << '\n'; + currentPtr = currentPtr->nextPtr; + delete tempPtr; + + } // end while + + } // end if + + cout << "All nodes destroyed\n\n"; + +} // end List destructor + +// insert node at front of list +template< class NODETYPE > +void List< NODETYPE >::insertAtFront( const NODETYPE &value ) +{ + ListNode *newPtr = new ListNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + newPtr->nextPtr = firstPtr; + firstPtr = newPtr; + + } // end else + +} // end function insertAtFront + +// insert node at back of list +template< class NODETYPE > +void List< NODETYPE >::insertAtBack( const NODETYPE &value ) +{ + ListNode *newPtr = new ListNode( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + lastPtr->nextPtr = newPtr; + lastPtr = newPtr; + + } // end else + +} // end function insertAtBack + +// delete node from front of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromFront( NODETYPE &value ) +{ + if ( isEmpty() ) // List is empty + return false; // delete unsuccessful + + else { + ListNode *tempPtr = firstPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else + firstPtr = firstPtr->nextPtr; + + value = tempPtr->data; // data being removed + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function removeFromFront + +// delete node from back of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromBack( NODETYPE &value ) +{ + if ( isEmpty() ) + return false; // delete unsuccessful + + else { + ListNode *tempPtr = lastPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else { + ListNode *currentPtr = firstPtr; + + // locate second-to-last element + while ( currentPtr->nextPtr != lastPtr ) + currentPtr = currentPtr->nextPtr; + + lastPtr = currentPtr; + currentPtr->nextPtr = 0; + + } // end else + + value = tempPtr->data; + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function removeFromBack + +// is List empty? +template< class NODETYPE > +bool List< NODETYPE >::isEmpty() const +{ + return firstPtr == 0; + +} // end function isEmpty + +// display contents of List +template< class NODETYPE > +void List< NODETYPE >::print() const +{ + if ( isEmpty() ) { + cout << "The list is empty\n\n"; + return; + + } // end if + + ListNode *currentPtr = firstPtr; + + cout << "The list is: "; + + while ( currentPtr != 0 ) { + cout << currentPtr->data << ' '; + currentPtr = currentPtr->nextPtr; + + } // end while + + cout << "\n\n"; + +} // end function print + +#endif \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt1/index.htm b/Bachelor/Prog2/Prakt1/index.htm new file mode 100644 index 0000000..4f896eb --- /dev/null +++ b/Bachelor/Prog2/Prakt1/index.htm @@ -0,0 +1,186 @@ + + + + + Praktikum 1 + +  + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren II +
Praktikum
+
+
1
+
+ +
+ + + + + +
Ziel: +Sie sollen die in Programmieren I erlernten Sprachelemente von C++ +(insbesondere Klassendefinition und Überladen von Operatoren) anwenden können. +
+ +
+
+ + + + + + + + + + + + +
+

1    MasterMind-Spiel

+Realisieren Sie eine objektorientierte Version des in den 70er-Jahren +des letzten Jahrhunderts beliebten Spieles +MasterMind.  +
    +
  • +In der Version für diese Aufgabe 'denkt sich' der Computer eine +vierstellige Zahl aus den Ziffern 1 bis 6 (Methode +makeDigitsToGuess im Klassendiagramm unten). Der Mensch rät sie. Jeden +Rateversuch bewertet der Computer, indem er angibt, wieviele Ziffern an der richtigen Stelle +genannt worden sind (locationRight) und wieviele sonst noch richtig genannt wurden, ohne +an der richtigen Stelle zu stehen (locationWrong). +
  • +
  • +Nehmen wir einmal an, der Computer hat sich die Zahl 1434 ausgedacht. +Ein Dialog könnte dann so aussehen:  +
    Mensch rät:  3654  Computer-Antwort: +1 +an der richtigen Stelle; sonst 1 richtig +
    Mensch rät:  4444  Computer-Antwort: +2 +an der richtigen Stelle; sonst 0 richtig +
  • +
  • +Neben der Standardvariante, bei der der Computer eine zu ratende Zahl +vorgibt, soll auch ein Testmodus möglich sein, bei dem vom Tester +eine beliebige vierstellige Zahl aus den Ziffern 1 bis 6 eingegeben werden +kann, die dann zu 'raten' ist. + +Überlegen Sie sich vor der Realisierung Ihrer Lösung +eine Reihe von Testfällen mit den zugehörigen Computer-Antworten. +Welche Fälle sind besonders kritisch? Berücksichtigen Sie bei +der Implementierung Ihrer Lösung auch diese kritischen Testfälle. +
  • +
+
+
    +
  • +Realisieren Sie anhand des folgenden Klassendiagramms eine Klasse +MastermindDigits, die die oben geschilderten +Anforderungen erfüllt (achten Sie dabei auch auf möglichst weitgehende +'const-correctness').
  • +
  • +Der (Konvertierungs-)Konstruktor erzeugt +ein dynamisches int-Array digits, dessen Elemente die einzelnen Ziffern der +vierstelligen int-Zahl enthalten. Er übernimmt diese int-Zahl als Parameter und +speichert die einzelnen Ziffern der Zahl in die Elemente von digits.
  • +
  • + Realisieren Sie außerdem die drei weiteren +Methoden/Operatoren, die Bestandteil jeder Klasse sein sollten, deren Objekte +Zeiger auf dynamisch zugewiesenen Speicher enthalten. (Sie sind im + Klassendiagramm unten nicht aufgeführt!) Dies sollen aber die +einzigen Ergänzungen der öffentlichen Schnittstelle sein.
    +
  • +
  • +Schreiben Sie ein Anwendungsprogramm, das den oben beschriebenen +Spielablauf und den Testmodus als Konsolenanwendung realisiert. Das Anwendungsprogramm +soll mit nur einem MastermindDigits-Objekt +arbeiten, von dem aus die Methoden der Klasse aufgerufen werden. Die +Nutzereingabe und der Vergleich soll daher mit int-Zahlen und den entsprechenden +Typ-Konvertierungen der MastermindDigits-Klasse +arbeiten.
  • +
+
+ + + + + + + + + + +
+
MastermindDigits
+
-digits: int*
+ ++MastermindDigits(int)
++makeDigitsToGuess(): void
++locationRight(MastermindDigits&): int
++locationWrong(MastermindDigits): int
++operator int() +
+
+ +
+
+
+
+ + + +
+

+2    Lösungsalgorithmus für MasterMind-Spiel (fakultativ)

+ + + +
In Aufgabe 1 wird das Mastermind-Spiel  in der +Form realisiert, dass ein menschlicher Benutzer eine vom Computer ausgedachte +Zahl rät. Jetzt soll der Computer eine Zahl raten, die sich der menschliche +Benutzer ausgedacht hat. +
    +
  • +Versehen Sie Ihre Lösung mit +einer Konsolen-Ausgabe und -Eingabe, über die ihr Programm seinen Tip ausgibt +und ein menschlicher Gegenspieler die Zahl der Ziffern an der richtigen +Stelle und die sonst noch richtigen Ziffern eingeben kann. +
  • +
  • +Wieviele Versuche benötigt Ihr Programm im Mittel, um eine Zahl zu raten? +Um Ihre Lösung besser testen zu können, lassen Sie den Computer auch die Rolle +des Benutzers übernehmen: Er denkt sich eine Zahl aus, die er dann zu erraten +versucht. Bestimmen Sie, wieviele Versuche hierbei im Mittel bei z.B. 10000 +Spielen gebraucht werden und wieviele Versuche ihr Programm dabei maximal +braucht.
  • +
  • + Anzustreben ist eine Lösung, die jedes Spiel gewinnt, d.h. mit maximal acht + Versuchen wird jede Zahl (mit vier Ziffern aus sechs möglichen) ermittelt, die sich der + menschliche Gegenspieler (oder der Rechner selbst) ausdenkt. +
  • +
+ + +
+ + +
+ + + +
  +
\ No newline at end of file diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.ilk b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.ilk new file mode 100644 index 0000000..21a3bcf Binary files /dev/null and b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.ilk differ diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pch b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pch new file mode 100644 index 0000000..b36b80f Binary files /dev/null and b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pch differ diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pdb b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pdb new file mode 100644 index 0000000..8338416 Binary files /dev/null and b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/mastermind.pdb differ diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.idb b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.idb new file mode 100644 index 0000000..c0885b9 Binary files /dev/null and b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.idb differ diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.pdb b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.pdb new file mode 100644 index 0000000..0d436a6 Binary files /dev/null and b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/Debug/vc60.pdb differ diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/main.cpp b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/main.cpp new file mode 100644 index 0000000..c981178 --- /dev/null +++ b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/main.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include "mastermind.h" + +using std::cout; +using std::cin; +using std::endl; + +const int MAXROUND=8; + +void playRound(MastermindDigits&); + +int main() +{ + int menuSel=0; + int input=0; + + MastermindDigits game; + + srand(time(0)); + + do { + system ("cls"); + cout << "1: Spiel" << endl; + cout << "2: Testmodus" << endl; + cout << "Ende: beliebige Taste"<> menuSel; + switch (menuSel) + { + case 1 : + { + game.makeDigitsToGuess(); + playRound(game); + break; + } + case 2: + { + cout << "Please enter test values (1111 - 6666): "; + cin >> input; + MastermindDigits testGame(input); + playRound(testGame); + break; + } + default: menuSel=0; + } + + } while (menuSel!=0); + + return 0; +} + +void playRound(MastermindDigits& game) +{ + int tip; + int won=0; + int round=1; + + do { + cout << endl << "Ihr Tip: "; + cin >> tip; + MastermindDigits user(tip); + cout << "Position richtig: " << game.locationRight(user) << endl; + cout << "Ansonsten richtig: " << game.locationWrong(user) << endl; + if (game.locationRight(user)==4) + { + won=1; + cout << endl << "Sie haben gewonnen!" << endl; + system("pause"); + } + round++; + } while ((won==0) && (round <= MAXROUND)); +} diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.cpp b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.dsp b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.dsp new file mode 100644 index 0000000..642caa2 --- /dev/null +++ b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.dsp @@ -0,0 +1,108 @@ +# Microsoft Developer Studio Project File - Name="mastermind" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=mastermind - 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 "mastermind.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 "mastermind.mak" CFG="mastermind - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "mastermind - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "mastermind - Win32 Debug" (basierend auf "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "mastermind" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "mastermind - 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)" == "mastermind - 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 /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 "mastermind - Win32 Release" +# Name "mastermind - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# Begin Source File + +SOURCE=.\mastermind.cpp +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\mastermind.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/Prakt1/prg2p1/mastermind/mastermind.dsw b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.dsw new file mode 100644 index 0000000..580dad6 --- /dev/null +++ b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.dsw @@ -0,0 +1,33 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN! + +############################################################################### + +Project: "mastermind"=.\mastermind.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + mastermind + . + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.h b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.h new file mode 100644 index 0000000..e69de29 diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.ncb b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.ncb new file mode 100644 index 0000000..1309382 Binary files /dev/null and b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.ncb differ diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.opt b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.opt new file mode 100644 index 0000000..3c43e3f Binary files /dev/null and b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.opt differ diff --git a/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.plg b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.plg new file mode 100644 index 0000000..33980de --- /dev/null +++ b/Bachelor/Prog2/Prakt1/prg2p1/mastermind/mastermind.plg @@ -0,0 +1,33 @@ + + +

+

Erstellungsprotokoll

+

+--------------------Konfiguration: mastermind - Win32 Debug-------------------- +

+

Befehlszeilen

+Erstellen der temporären Datei "C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP195.tmp" mit Inhalten +[ +/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/mastermind.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"D:\Studium\Prog2\Prakt1\prg2p1\mastermind\mastermind.cpp" +] +Creating command line "cl.exe @C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP195.tmp" +Erstellen der temporären Datei "C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP196.tmp" mit Inhalten +[ +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 /incremental:yes /pdb:"Debug/mastermind.pdb" /debug /machine:I386 /out:"Debug/mastermind.exe" /pdbtype:sept +.\Debug\main.obj +.\Debug\mastermind.obj +] +Erstellen der Befehlzeile "link.exe @C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP196.tmp" +

Ausgabefenster

+Kompilierung läuft... +mastermind.cpp +Linker-Vorgang läuft... + + + +

Ergebnisse

+mastermind.exe - 0 Fehler, 0 Warnung(en) +
+ + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/.cdtbuild b/Bachelor/Prog2/Prakt2/SmartHouse/.cdtbuild new file mode 100644 index 0000000..6318112 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/.cdtbuild @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/.cdtproject b/Bachelor/Prog2/Prakt2/SmartHouse/.cdtproject new file mode 100644 index 0000000..aecd7f1 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/.cdtproject @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/.project b/Bachelor/Prog2/Prakt2/SmartHouse/.project new file mode 100644 index 0000000..58e9156 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/.project @@ -0,0 +1,19 @@ + + + SmartHouse + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.cpp b/Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.cpp new file mode 100644 index 0000000..68c6e5e --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.cpp @@ -0,0 +1,42 @@ +#include "Coffeemachine.h" +#include + +using std::cout; +using std::endl; +using std::string; +//using std::istream; +using std::ostream; + +Coffeemachine::Coffeemachine() +{ + numberOfCups=0; + cout << "Konstruktor Coffeemachine called" << endl; +} + +Coffeemachine::Coffeemachine(char * devName) + :GeneralDevice(devName) +{ + numberOfCups=0; + cout << "Überladener Konstruktor Coffeemachine called" << endl; +} + +Coffeemachine::~Coffeemachine() +{ + cout << "Destruktor Coffeemachine called" << endl; +} + +void Coffeemachine::operator++(int) +{ + numberOfCups++; +} + +void Coffeemachine::operator--(int) +{ + numberOfCups<=0?numberOfCups=0:numberOfCups--; +} + +void Coffeemachine::print() +{ + cout << "Name: " << getDeviceName() + << " Cups: " << numberOfCups << endl; +} diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.h b/Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.h new file mode 100644 index 0000000..d5d2ac5 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Coffeemachine.h @@ -0,0 +1,26 @@ +#ifndef _COFFEEMACHINE_H_ +#define _COFFEEMACHINE_H_ + +#include "GeneralDevice.h" +#include + +using std::istream; +using std::ostream; + +class Coffeemachine : public GeneralDevice +{ + //friend ostream &operator<<( ostream&, const Coffeemachine & ); + +public: + Coffeemachine(); + Coffeemachine(char *); + virtual ~Coffeemachine(); + virtual void operator++(int); + virtual void operator--(int); + virtual void print(); + +private: + int numberOfCups; +}; + +#endif //_COFFEEMACHINE_H_ diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Coffeemachine.d b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Coffeemachine.d new file mode 100644 index 0000000..6148646 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Coffeemachine.d @@ -0,0 +1,11 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +Coffeemachine.d ./Coffeemachine.o: ../Coffeemachine.cpp ../Coffeemachine.h \ + ../GeneralDevice.h + +../Coffeemachine.h: + +../GeneralDevice.h: + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/GeneralDevice.d b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/GeneralDevice.d new file mode 100644 index 0000000..9c526ae --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/GeneralDevice.d @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +GeneralDevice.d ./GeneralDevice.o: ../GeneralDevice.cpp ../GeneralDevice.h + +../GeneralDevice.h: + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Heating.d b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Heating.d new file mode 100644 index 0000000..1b8c962 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Heating.d @@ -0,0 +1,10 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +Heating.d ./Heating.o: ../Heating.cpp ../Heating.h ../GeneralDevice.h + +../Heating.h: + +../GeneralDevice.h: + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Radio.d b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Radio.d new file mode 100644 index 0000000..a543cf7 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/Radio.d @@ -0,0 +1,10 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +Radio.d ./Radio.o: ../Radio.cpp ../Radio.h ../GeneralDevice.h + +../Radio.h: + +../GeneralDevice.h: + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/SmartHouse b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/SmartHouse new file mode 100644 index 0000000..c4b3586 Binary files /dev/null and b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/SmartHouse differ diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/main.d b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/main.d new file mode 100644 index 0000000..891f3e9 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/main.d @@ -0,0 +1,15 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +main.d ./main.o: ../main.cpp ../Coffeemachine.h ../GeneralDevice.h ../Heating.h \ + ../Radio.h + +../Coffeemachine.h: + +../GeneralDevice.h: + +../Heating.h: + +../Radio.h: + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/makefile b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/makefile new file mode 100644 index 0000000..7e0fccb --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/makefile @@ -0,0 +1,30 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +ROOT := .. + +-include $(ROOT)/makefile.init + +RM := rm -rf + +# All of the sources participating in the build are defined here +-include sources.mk +-include $(SUBDIRS:%=%/subdir.mk) +-include objects.mk +-include $(DEPS) +-include $(ROOT)/makefile.defs + +all: SmartHouse + +SmartHouse: $(OBJS) + @echo 'Building target: $@' + g++ -o $@ $(OBJS) $(USER_OBJS) $(LIBS) + @echo 'Finished building: $@' + +clean: + -$(RM) $(OBJS) $(DEPS) SmartHouse + +.PHONY: all clean dependents + +-include $(ROOT)/makefile.targets diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/objects.mk b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/objects.mk new file mode 100644 index 0000000..59a3b5b --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/objects.mk @@ -0,0 +1,13 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +LIBS := +USER_OBJS := + + +OBJS := \ + $(C_SRCS:$(ROOT)/%.c=%.o) $(C_UPPER_SRCS:$(ROOT)/%.C=%.o) $(CC_SRCS:$(ROOT)/%.cc=%.o) $(CXX_SRCS:$(ROOT)/%.cxx=%.o) $(CPP_SRCS:$(ROOT)/%.cpp=%.o) $(S_SRCS:$(ROOT)/%.s=%.o) $(S_UPPER_SRCS:$(ROOT)/%.S=%.o) + +DEPS := \ + $(C_SRCS:$(ROOT)/%.c=%.d) $(C_UPPER_SRCS:$(ROOT)/%.C=%.d) $(CC_SRCS:$(ROOT)/%.cc=%.d) $(CXX_SRCS:$(ROOT)/%.cxx=%.d) $(CPP_SRCS:$(ROOT)/%.cpp=%.d) $(S_SRCS:$(ROOT)/%.s=%.d) $(S_UPPER_SRCS:$(ROOT)/%.S=%.d) \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/sources.mk b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/sources.mk new file mode 100644 index 0000000..357bfc1 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/sources.mk @@ -0,0 +1,16 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +C_SRCS := +C_UPPER_SRCS := +CC_SRCS := +CXX_SRCS := +CPP_SRCS := +S_SRCS := +S_UPPER_SRCS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Debug/subdir.mk b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/subdir.mk new file mode 100644 index 0000000..b0df7bd --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Debug/subdir.mk @@ -0,0 +1,48 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +S_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CPP_SRCS += \ +${addprefix $(ROOT)/, \ +Coffeemachine.cpp \ +GeneralDevice.cpp \ +Heating.cpp \ +Radio.cpp \ +main.cpp \ +} + +CC_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CXX_SRCS += \ +${addprefix $(ROOT)/, \ +} + +S_SRCS += \ +${addprefix $(ROOT)/, \ +} + +# Each subdirectory must supply rules for building sources it contributes +%.o: $(ROOT)/%.cpp + @echo 'Building file: $<' + @echo g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< + @g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< && \ + echo -n $(@:%.o=%.d) $(dir $@) > $(@:%.o=%.d) && \ + g++ -MM -MG -P -w -O0 -g3 -Wall -c -fmessage-length=0 $< >> $(@:%.o=%.d) + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.cpp b/Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.cpp new file mode 100644 index 0000000..738051e --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.cpp @@ -0,0 +1,42 @@ +#include "GeneralDevice.h" +#include +#include + +using std::cout; +using std::endl; +using std::istream; +using std::ostream; +using std::string; + +ostream &operator<<( ostream& outstream, GeneralDevice &GenDev) +{ + GenDev.print(); + return outstream; +} + +GeneralDevice::GeneralDevice() +{ + cout << "Konstruktor GeneralDevice called" << endl; +} + +GeneralDevice::GeneralDevice(char* devName) + :deviceName(devName) +{ + cout << "Überladener Konstruktor GeneralDevice called" << endl; +} + +GeneralDevice::~GeneralDevice() +{ + cout << "Destruktor GeneralDevice called" << endl; +} + +string GeneralDevice::getDeviceName() +{ + //cout << deviceName; + return deviceName; +} + +void GeneralDevice::setDeviceName(string devName) +{ + deviceName=devName; +} diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.h b/Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.h new file mode 100644 index 0000000..44512f2 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/GeneralDevice.h @@ -0,0 +1,28 @@ +#ifndef _GENERALDEVICE_H_ +#define _GENERALDEVICE_H_ + +#include +#include + +//using std::istream; +using std::ostream; +using std::string; + +class GeneralDevice +{ +friend ostream &operator<<( ostream&, GeneralDevice &); + +public: + GeneralDevice(); + GeneralDevice(char *); + virtual ~GeneralDevice(); + virtual void operator++(int) =0; + virtual void operator--(int) =0; + string getDeviceName(); + void setDeviceName(string); + virtual void print()=0; +private: + string deviceName; +}; + +#endif //_GENERALDEVICE_H_ diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Heating.cpp b/Bachelor/Prog2/Prakt2/SmartHouse/Heating.cpp new file mode 100644 index 0000000..1669848 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Heating.cpp @@ -0,0 +1,40 @@ +#include "Heating.h" +#include + +using std::cout; +using std::endl; +using std::string; + +Heating::Heating() +{ + temperature=0; + cout << "Konstruktor Heating called" << endl; +} + +Heating::Heating(char * devName) + : GeneralDevice(devName) +{ + temperature=0; + cout << "Überladener Konstruktor Heating called" << endl; +} + +Heating::~Heating() +{ + cout << "Destruktor Heating called" << endl; +} + +void Heating::operator++(int) +{ + temperature++; +} + +void Heating::operator--(int) +{ + temperature<=0?temperature=0:temperature--; +} + +void Heating::print() +{ + cout << "Name: " << getDeviceName() + << " Temperatur: " << temperature << endl; +} diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Heating.h b/Bachelor/Prog2/Prakt2/SmartHouse/Heating.h new file mode 100644 index 0000000..d1e5d3c --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Heating.h @@ -0,0 +1,26 @@ +#ifndef _HEATING_H_ +#define _HEATING_H_ + +#include "GeneralDevice.h" +#include + +//using std::istream; +using std::ostream; + +class Heating : public GeneralDevice +{ + //friend ostream &operator<<( ostream&, const Heating& ); + +public: + Heating(); + Heating(char *); + virtual ~Heating(); + virtual void operator++(int); + virtual void operator--(int); + virtual void print(); + +private: + float temperature; +}; + +#endif //_HEATING_H_ diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Radio.cpp b/Bachelor/Prog2/Prakt2/SmartHouse/Radio.cpp new file mode 100644 index 0000000..6cbc24b --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Radio.cpp @@ -0,0 +1,38 @@ +#include "Radio.h" +#include + +using std::cout; +using std::endl; + +Radio::Radio() +{ + volume=0; + cout << "Konstruktor Radio called" << endl; +} + +Radio::Radio(char * devName) + :GeneralDevice(devName) +{ + volume=0; + cout << "Überladener Konstruktor Radio called" << endl; +} + +Radio::~Radio() +{ + cout << "Destruktor Radio called" << endl; +} + +void Radio::operator++(int) +{ + volume++; +} + +void Radio::operator--(int) +{ + volume<=0?volume=0:volume--; +} + +void Radio::print() +{ + cout << "Name: "<< getDeviceName() << " Volume: " << volume << endl; +} diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/Radio.h b/Bachelor/Prog2/Prakt2/SmartHouse/Radio.h new file mode 100644 index 0000000..4f839f7 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/Radio.h @@ -0,0 +1,25 @@ +#ifndef _RADIO_H_ +#define _RADIO_H_ + +#include "GeneralDevice.h" +#include + +//using std::istream; +using std::ostream; + +class Radio : public GeneralDevice +{ + //friend ostream &operator<<( ostream&, const Radio& ); + +public: + Radio(); + Radio(char *); + virtual ~Radio(); + virtual void operator++(int); + virtual void operator--(int); + virtual void print(); +private: + double volume; +}; + +#endif //_RADIO_H_ diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/main.cpp b/Bachelor/Prog2/Prakt2/SmartHouse/main.cpp new file mode 100644 index 0000000..eadd146 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/SmartHouse/main.cpp @@ -0,0 +1,61 @@ +#include +#include "Coffeemachine.h" +#include "Heating.h" +#include "Radio.h" +#include "GeneralDevice.h" + +using std::cin; +using std::cout; +using std::endl; +using std::string; + +int main() +{ + GeneralDevice *actualDevice; + GeneralDevice *array[5]; + + char input; + + Heating htog("Heizung OG"); + Heating hteg("Heizung EG"); + Coffeemachine cm("Tchibo KM 3"); + Radio radw("Radio Wohnzimmer"); + Radio radk("Radio Küche"); + + array[0]=&cm; + array[1]=&radw; + array[2]=&radk; + array[3]=&htog; + array[4]=&hteg; + + actualDevice=array[0]; + + cout << "SmartHouse" << endl; + + do + { + cout << "+ : laut/warm/mehr" << endl; + cout << "- : leise/kalt/weniger" << endl; + cout << "1 : Tchibo KM 3"<> input; + switch (input) { + case '1':actualDevice=array[0]; break; + case '2':actualDevice=array[1]; break; + case '3':actualDevice=array[2]; break; + case '4':actualDevice=array[3]; break; + case '5': actualDevice=array[4]; break; + case '+': (*actualDevice)++; break; + case '-': (*actualDevice)--; break; + case '?': cout << *actualDevice; break; + } + }while (input!='0'); + + return 0; +} diff --git a/Bachelor/Prog2/Prakt2/SmartHouse/prg2p2_1.zip b/Bachelor/Prog2/Prakt2/SmartHouse/prg2p2_1.zip new file mode 100644 index 0000000..61c418b Binary files /dev/null and b/Bachelor/Prog2/Prakt2/SmartHouse/prg2p2_1.zip differ diff --git a/Bachelor/Prog2/Prakt2/geomObj/.cdtbuild b/Bachelor/Prog2/Prakt2/geomObj/.cdtbuild new file mode 100644 index 0000000..e0c01e4 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/.cdtbuild @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt2/geomObj/.cdtproject b/Bachelor/Prog2/Prakt2/geomObj/.cdtproject new file mode 100644 index 0000000..82c36e0 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/.cdtproject @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt2/geomObj/.project b/Bachelor/Prog2/Prakt2/geomObj/.project new file mode 100644 index 0000000..166cc9d --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/.project @@ -0,0 +1,19 @@ + + + geomObj + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Circle.cpp b/Bachelor/Prog2/Prakt2/geomObj/Circle.cpp new file mode 100644 index 0000000..14415bf --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Circle.cpp @@ -0,0 +1,27 @@ +#include "Circle.h" + +const double pi = 3.14159265358979; + +Circle::Circle() + :radius(.0) +{ +} + +Circle::Circle(double newR) + :radius(newR) +{ +} + +Circle::~Circle() +{ +} + +double Circle::getArea() +{ + return (radius * radius * pi); +} + +double Circle::getCircumference() +{ + return (2 * radius * pi); +} diff --git a/Bachelor/Prog2/Prakt2/geomObj/Circle.h b/Bachelor/Prog2/Prakt2/geomObj/Circle.h new file mode 100644 index 0000000..580b254 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Circle.h @@ -0,0 +1,18 @@ +#ifndef _CIRCLE_H_ +#define _CIRCLE_H_ + +#include "Shape.h" + +class Circle : public Shape +{ +public: + Circle(); + Circle(double); + virtual ~Circle(); + virtual double getArea(); + virtual double getCircumference(); +private: + const double radius; +}; + +#endif //_CIRCLE_H_ diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/Circle.d b/Bachelor/Prog2/Prakt2/geomObj/Debug/Circle.d new file mode 100644 index 0000000..61b13d0 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/Circle.d @@ -0,0 +1,10 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +Circle.d ./Circle.o: ../Circle.cpp ../Circle.h ../Shape.h + +../Circle.h: + +../Shape.h: + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/Rectangle.d b/Bachelor/Prog2/Prakt2/geomObj/Debug/Rectangle.d new file mode 100644 index 0000000..3cca9be --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/Rectangle.d @@ -0,0 +1,10 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +Rectangle.d ./Rectangle.o: ../Rectangle.cpp ../Rectangle.h ../Shape.h + +../Rectangle.h: + +../Shape.h: + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/Shape.d b/Bachelor/Prog2/Prakt2/geomObj/Debug/Shape.d new file mode 100644 index 0000000..3ca796d --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/Shape.d @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +Shape.d ./Shape.o: ../Shape.cpp ../Shape.h + +../Shape.h: + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/Square.d b/Bachelor/Prog2/Prakt2/geomObj/Debug/Square.d new file mode 100644 index 0000000..15e7998 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/Square.d @@ -0,0 +1,12 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +Square.d ./Square.o: ../Square.cpp ../Square.h ../Rectangle.h ../Shape.h + +../Square.h: + +../Rectangle.h: + +../Shape.h: + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/geomObj b/Bachelor/Prog2/Prakt2/geomObj/Debug/geomObj new file mode 100644 index 0000000..809ba37 Binary files /dev/null and b/Bachelor/Prog2/Prakt2/geomObj/Debug/geomObj differ diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/main.d b/Bachelor/Prog2/Prakt2/geomObj/Debug/main.d new file mode 100644 index 0000000..b5a4438 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/main.d @@ -0,0 +1,14 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +main.d ./main.o: ../main.cpp ../Rectangle.h ../Shape.h ../Circle.h ../Square.h + +../Rectangle.h: + +../Shape.h: + +../Circle.h: + +../Square.h: + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/makefile b/Bachelor/Prog2/Prakt2/geomObj/Debug/makefile new file mode 100644 index 0000000..698fd9d --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/makefile @@ -0,0 +1,30 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +ROOT := .. + +-include $(ROOT)/makefile.init + +RM := rm -rf + +# All of the sources participating in the build are defined here +-include sources.mk +-include $(SUBDIRS:%=%/subdir.mk) +-include objects.mk +-include $(DEPS) +-include $(ROOT)/makefile.defs + +all: geomObj + +geomObj: $(OBJS) + @echo 'Building target: $@' + g++ -o $@ $(OBJS) $(USER_OBJS) $(LIBS) + @echo 'Finished building: $@' + +clean: + -$(RM) $(OBJS) $(DEPS) geomObj + +.PHONY: all clean dependents + +-include $(ROOT)/makefile.targets diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/objects.mk b/Bachelor/Prog2/Prakt2/geomObj/Debug/objects.mk new file mode 100644 index 0000000..59a3b5b --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/objects.mk @@ -0,0 +1,13 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +LIBS := +USER_OBJS := + + +OBJS := \ + $(C_SRCS:$(ROOT)/%.c=%.o) $(C_UPPER_SRCS:$(ROOT)/%.C=%.o) $(CC_SRCS:$(ROOT)/%.cc=%.o) $(CXX_SRCS:$(ROOT)/%.cxx=%.o) $(CPP_SRCS:$(ROOT)/%.cpp=%.o) $(S_SRCS:$(ROOT)/%.s=%.o) $(S_UPPER_SRCS:$(ROOT)/%.S=%.o) + +DEPS := \ + $(C_SRCS:$(ROOT)/%.c=%.d) $(C_UPPER_SRCS:$(ROOT)/%.C=%.d) $(CC_SRCS:$(ROOT)/%.cc=%.d) $(CXX_SRCS:$(ROOT)/%.cxx=%.d) $(CPP_SRCS:$(ROOT)/%.cpp=%.d) $(S_SRCS:$(ROOT)/%.s=%.d) $(S_UPPER_SRCS:$(ROOT)/%.S=%.d) \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/sources.mk b/Bachelor/Prog2/Prakt2/geomObj/Debug/sources.mk new file mode 100644 index 0000000..357bfc1 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/sources.mk @@ -0,0 +1,16 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +C_SRCS := +C_UPPER_SRCS := +CC_SRCS := +CXX_SRCS := +CPP_SRCS := +S_SRCS := +S_UPPER_SRCS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Debug/subdir.mk b/Bachelor/Prog2/Prakt2/geomObj/Debug/subdir.mk new file mode 100644 index 0000000..f9a4a41 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Debug/subdir.mk @@ -0,0 +1,48 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +S_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CPP_SRCS += \ +${addprefix $(ROOT)/, \ +Circle.cpp \ +Rectangle.cpp \ +Shape.cpp \ +Square.cpp \ +main.cpp \ +} + +CC_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CXX_SRCS += \ +${addprefix $(ROOT)/, \ +} + +S_SRCS += \ +${addprefix $(ROOT)/, \ +} + +# Each subdirectory must supply rules for building sources it contributes +%.o: $(ROOT)/%.cpp + @echo 'Building file: $<' + @echo g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< + @g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< && \ + echo -n $(@:%.o=%.d) $(dir $@) > $(@:%.o=%.d) && \ + g++ -MM -MG -P -w -O0 -g3 -Wall -c -fmessage-length=0 $< >> $(@:%.o=%.d) + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/Bachelor/Prog2/Prakt2/geomObj/Rectangle.cpp b/Bachelor/Prog2/Prakt2/geomObj/Rectangle.cpp new file mode 100644 index 0000000..cc48ae2 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Rectangle.cpp @@ -0,0 +1,25 @@ +#include "Rectangle.h" + +Rectangle::Rectangle() + :sideA(.0),sideB(.0) +{ +} + +Rectangle::~Rectangle() +{ +} + +Rectangle::Rectangle(double newA, double newB) + :sideA(newA),sideB(newB) +{ +} + +double Rectangle::getCircumference() +{ + return 2 * (sideA + sideB); +} + +double Rectangle::getArea() +{ + return sideA*sideB; +} diff --git a/Bachelor/Prog2/Prakt2/geomObj/Rectangle.h b/Bachelor/Prog2/Prakt2/geomObj/Rectangle.h new file mode 100644 index 0000000..586110a --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Rectangle.h @@ -0,0 +1,19 @@ +#ifndef _RECTANGLE_H_ +#define _RECTANGLE_H_ + +#include "Shape.h" + +class Rectangle : public Shape +{ +public: + Rectangle(); + Rectangle(double,double); + virtual ~Rectangle(); + virtual double getArea(); + virtual double getCircumference(); +private: + const double sideA; + const double sideB; +}; + +#endif //_RECTANGLE_H_ diff --git a/Bachelor/Prog2/Prakt2/geomObj/Shape.cpp b/Bachelor/Prog2/Prakt2/geomObj/Shape.cpp new file mode 100644 index 0000000..8eb43e5 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Shape.cpp @@ -0,0 +1,14 @@ +#include "Shape.h" + +Shape::Shape() +{ +} + +Shape::~Shape() +{ +} + +double Shape::operator-(Shape* toSub) +{ + return (this->getArea() - toSub->getArea()); +} diff --git a/Bachelor/Prog2/Prakt2/geomObj/Shape.h b/Bachelor/Prog2/Prakt2/geomObj/Shape.h new file mode 100644 index 0000000..481c2be --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Shape.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_H_ +#define _SHAPE_H_ + +class Shape +{ +public: + Shape(); + virtual ~Shape(); + virtual double getCircumference() = 0; + virtual double getArea() = 0; + double operator-(Shape*); +}; + +#endif //_SHAPE_H_ diff --git a/Bachelor/Prog2/Prakt2/geomObj/Square.cpp b/Bachelor/Prog2/Prakt2/geomObj/Square.cpp new file mode 100644 index 0000000..3bd6682 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Square.cpp @@ -0,0 +1,25 @@ +#include "Square.h" + +Square::Square() + :length(.0) +{ +} + +Square::Square(double newlength) +:length(newlength) +{ +} + +Square::~Square() +{ +} + +double Square::getArea() +{ + return length*length; +} + +double Square::getCircumference() +{ + return 2 * (length + length); +} diff --git a/Bachelor/Prog2/Prakt2/geomObj/Square.h b/Bachelor/Prog2/Prakt2/geomObj/Square.h new file mode 100644 index 0000000..022483b --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/Square.h @@ -0,0 +1,18 @@ +#ifndef _SQUARE_H_ +#define _SQUARE_H_ + +#include "Rectangle.h" + +class Square : public Rectangle +{ +public: + Square(); + Square(double); + virtual ~Square(); + virtual double getCircumference(); + virtual double getArea(); +private: + const double length; +}; + +#endif //_SQUARE_H_ diff --git a/Bachelor/Prog2/Prakt2/geomObj/geomObj.zip b/Bachelor/Prog2/Prakt2/geomObj/geomObj.zip new file mode 100644 index 0000000..cad5044 Binary files /dev/null and b/Bachelor/Prog2/Prakt2/geomObj/geomObj.zip differ diff --git a/Bachelor/Prog2/Prakt2/geomObj/main.cpp b/Bachelor/Prog2/Prakt2/geomObj/main.cpp new file mode 100644 index 0000000..e81de02 --- /dev/null +++ b/Bachelor/Prog2/Prakt2/geomObj/main.cpp @@ -0,0 +1,39 @@ +#include +#include "Rectangle.h" +#include "Circle.h" +#include "Square.h" + +using std::cout; +using std::endl; + +int main() +{ + Circle circle(15.0); + Rectangle rectangle(3.0,4.0); + Square square(4.2); + + int n,j; + + Shape* ptrArray[3]; + + ptrArray[0]=&circle; + ptrArray[1]=&rectangle; + ptrArray[2]=□ + + for (n=0;n<3;n++) + { + cout << "Area: "<< (ptrArray[n]->getArea()) << " Circumference: " + << (ptrArray[n]->getCircumference()) << endl; + } + + for (n=0;n<3;n++) + { + for (j=0;j<3;j++) + { + cout << "Difference: " + << (ptrArray[j]->getArea() - ptrArray[n]->getArea()) << endl; + } + } + + return 0; +} diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/Table.obj b/Bachelor/Prog2/Prakt3/Aufg1/Debug/Table.obj new file mode 100644 index 0000000..2c53ebf Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/Table.obj differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/Team.obj b/Bachelor/Prog2/Prakt3/Aufg1/Debug/Team.obj new file mode 100644 index 0000000..93fa9f3 Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/Team.obj differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/main.obj b/Bachelor/Prog2/Prakt3/Aufg1/Debug/main.obj new file mode 100644 index 0000000..9a3588f Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/main.obj differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.exe b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.exe new file mode 100644 index 0000000..ce2ebc3 Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.exe differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.ilk b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.ilk new file mode 100644 index 0000000..3cf9141 Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.ilk differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pch b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pch new file mode 100644 index 0000000..320bfab Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pch differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pdb b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pdb new file mode 100644 index 0000000..18da3b0 Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/tabletennis.pdb differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.idb b/Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.idb new file mode 100644 index 0000000..02f399c Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.idb differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.pdb b/Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.pdb new file mode 100644 index 0000000..5b3ab24 Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/Debug/vc60.pdb differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Table.cpp b/Bachelor/Prog2/Prakt3/Aufg1/Table.cpp new file mode 100644 index 0000000..9b6a2bf --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/Table.cpp @@ -0,0 +1,52 @@ +#include "Table.h" +#include "Team.h" +#include +#include + +using std::cout; +using std::endl; +using std::string; +using std::ostream; +using std::left; +using std::setw; + +void Table::setTeam(const Team& toSet) +{ + teams.push_back(toSet); +} + +void Table::print(ostream& output) +{ + int n=0; + output << left << setw(22) << "Team" << setw(9) << "Matches" << setw(12) << "Games won" << setw(12) + << "Games lost" << setw(12) << "Points won" << setw(12) << "Points lost" << endl;; + + while(nteams[n].getpointsWon()) + if(!(teams[j] +#include +#include "Team.h" + +using std::ostream; +using std::vector; + +class Table +{ +public: + void setTeam(const Team&); + void print(ostream&); + void sort(); +private: + vector teams; +}; + +#endif //_TABLE_H_ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Team.cpp b/Bachelor/Prog2/Prakt3/Aufg1/Team.cpp new file mode 100644 index 0000000..86b1a95 --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/Team.cpp @@ -0,0 +1,116 @@ +#include "Team.h" +#include +using std::istream; +using std::getline; + +Team::Team() +{ +} + +Team::~Team() +{ +} + +void Team::setTeamName(const string& name) +{ + teamName=name; +} + +const string& Team::getTeamName() const +{ + return teamName; +} + +void Team::setmatchesPlayed(int matchesp) +{ + matchesPlayed=matchesp; +} + +const int Team::getmatchesPlayed() const +{ + return matchesPlayed; +} + +void Team::setgamesWon(int gw) +{ + gamesWon=gw; +} + +const int Team::getgamesWon() const +{ + return gamesWon; +} + +void Team::setgamesLost(int gl) +{ + gamesLost=gl; +} + +const int Team::getgamesLost() const +{ + return gamesLost; +} + +void Team::setpointsWon(int pw) +{ + pointsWon=pw; +} + +const int Team::getpointsWon() const +{ + return pointsWon; +} + +void Team::setpointsLost(int pl) +{ + pointsLost=pl; +} + +const int Team::getpointsLost() const +{ + return pointsLost; +} + +const Team& Team::operator=(const Team& toCopy) +{ + setTeamName(toCopy.getTeamName()); + setgamesWon(toCopy.getgamesWon()); + setgamesLost(toCopy.getgamesLost()); + setpointsWon(toCopy.getpointsWon()); + setpointsLost(toCopy.getpointsLost()); + setmatchesPlayed(toCopy.getmatchesPlayed()); + + return *this; +} + +bool Team::operator<(const Team& toComp) +{ + if (getpointsWon() < toComp.getpointsWon()) + return true; + else + { + if (getpointsWon() == toComp.getpointsWon()) + { + if (getpointsLost() < toComp.getpointsLost()) + return true; + if (getpointsLost() == toComp.getpointsLost()) + { + if ( (getgamesWon()-getgamesLost()) < (toComp.getgamesWon()-toComp.getgamesLost())) + return true; + } + } + + return false; + } +} + +istream& Team::read(istream& input) +{ + + + string test; + getline( input, test, '\0' ); + this->setTeamName(test); + input.read( reinterpret_cast (&matchesPlayed), 5 * sizeof( int ) ); + return input; +} diff --git a/Bachelor/Prog2/Prakt3/Aufg1/Team.h b/Bachelor/Prog2/Prakt3/Aufg1/Team.h new file mode 100644 index 0000000..89d759d --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/Team.h @@ -0,0 +1,39 @@ +#ifndef _TABLETENNIS_H_ +#define _TABLETENNIS_H_ + +#include +#include + +using std::string; +using std::istream; + +class Team +{ +public: + Team(); + virtual ~Team(); + void setTeamName(const string&); + const string& getTeamName() const; + void setmatchesPlayed(int); + const int getmatchesPlayed() const; + void setgamesWon(int); + const int getgamesWon() const; + void setgamesLost(int); + const int getgamesLost() const; + void setpointsWon(int); + const int getpointsWon() const; + void setpointsLost(int); + const int getpointsLost() const; + istream& read(istream&); + const Team& operator=(const Team&); + bool operator<(const Team&); +private: + string teamName; + int matchesPlayed; + int gamesWon; + int gamesLost; + int pointsWon; + int pointsLost; +}; + +#endif //_TABLETENNIS_H_ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/main.cpp b/Bachelor/Prog2/Prakt3/Aufg1/main.cpp new file mode 100644 index 0000000..e8a47cc --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/main.cpp @@ -0,0 +1,50 @@ +#include "Team.h" +#include "Table.h" +#include +#include +#include +#include +#include +#include + +using std::cout; +using std::cerr; +using std::string; +using std::ifstream; +using std::ofstream; +using std::ios; +using std::endl; +using std::setw; +using std::left; +using std::ostream; + + +int main() +{ + int n=0; + Team team; + Table tab; + ifstream inDTA("tabletennis.dta",ios::binary); + + if ( !inDTA ) { + cerr << "File could not be opened." << endl; + exit( 1 ); + } // end if + + while(team.read(inDTA)) + { + tab.setTeam(team); + } + + inDTA.close(); + + tab.print(cout); + tab.sort(); + tab.print(cout); + + ofstream outF("tabletennis.txt",ios::out); + tab.print(outF); + outF.close(); + + return 0; +} diff --git a/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsp b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsp new file mode 100644 index 0000000..fa7fd45 --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsp @@ -0,0 +1,116 @@ +# Microsoft Developer Studio Project File - Name="tabletennis" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=tabletennis - 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 "tabletennis.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 "tabletennis.mak" CFG="tabletennis - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "tabletennis - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "tabletennis - Win32 Debug" (basierend auf "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "tabletennis" +# PROP Scc_LocalPath "." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "tabletennis - 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)" == "tabletennis - 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 /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 "tabletennis - Win32 Release" +# Name "tabletennis - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# Begin Source File + +SOURCE=.\Table.cpp +# End Source File +# Begin Source File + +SOURCE=.\Team.cpp +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\Table.h +# End Source File +# Begin Source File + +SOURCE=.\Team.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/Prakt3/Aufg1/tabletennis.dsw b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsw new file mode 100644 index 0000000..11922e3 --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dsw @@ -0,0 +1,33 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN! + +############################################################################### + +Project: "tabletennis"=.\tabletennis.dsp - Package Owner=<4> + +Package=<5> +{{{ + begin source code control + tabletennis + . + end source code control +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dta b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dta new file mode 100644 index 0000000..4891053 Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.dta differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.ncb b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.ncb new file mode 100644 index 0000000..5344aae Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.ncb differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.opt b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.opt new file mode 100644 index 0000000..35bb89f Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.opt differ diff --git a/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.plg b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.plg new file mode 100644 index 0000000..7d0aa9d --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.plg @@ -0,0 +1,26 @@ + + +
+

Erstellungsprotokoll

+

+--------------------Konfiguration: tabletennis - Win32 Debug-------------------- +

+

Befehlszeilen

+Erstellen der temporären Datei "C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP1D2.tmp" mit Inhalten +[ +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 /incremental:yes /pdb:"Debug/tabletennis.pdb" /debug /machine:I386 /out:"Debug/tabletennis.exe" /pdbtype:sept +.\Debug\main.obj +.\Debug\Table.obj +.\Debug\Team.obj +] +Erstellen der Befehlzeile "link.exe @C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP1D2.tmp" +

Ausgabefenster

+Linker-Vorgang läuft... + + + +

Ergebnisse

+tabletennis.exe - 0 Fehler, 0 Warnung(en) +
+ + diff --git a/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.txt b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.txt new file mode 100644 index 0000000..4ad94db --- /dev/null +++ b/Bachelor/Prog2/Prakt3/Aufg1/tabletennis.txt @@ -0,0 +1,11 @@ +Team Matches Games won Games lost Points won Points lost +SV Crumstadt II 18 108 36 36 0 +TSV Hoechst II 18 91 48 28 8 +TV Stockheim 18 87 54 24 12 +TV Buerstadt 18 88 58 21 15 +DJK/Scc Pfungstadt 18 79 78 16 20 +TSV Ernsthofen 18 68 83 14 22 +TSV Auerbach 18 64 86 14 22 +TTC Langen-Brombach 18 60 94 12 24 +SV Moerlenbach II 18 53 90 11 25 +TV Seeheim 18 30 101 4 32 diff --git a/Bachelor/Prog2/Prakt3/Aufg2/tools.dta b/Bachelor/Prog2/Prakt3/Aufg2/tools.dta new file mode 100644 index 0000000..aea166b Binary files /dev/null and b/Bachelor/Prog2/Prakt3/Aufg2/tools.dta differ diff --git a/Bachelor/Prog2/Prakt3/index.htm b/Bachelor/Prog2/Prakt3/index.htm new file mode 100644 index 0000000..bbd2dfb --- /dev/null +++ b/Bachelor/Prog2/Prakt3/index.htm @@ -0,0 +1,231 @@ + + + + +Praktikum 3 + + + + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren II  +
Praktikum
+
+
3
+
+ +
+ + + + +
Ziel: +Sie sollen Dateien ein- und auslesen und die enthaltenen Daten weiter verarbeiten können.  +
+ +
+
+ + + + + + + + + + + + +
+

+1    Einlesen einer Binärdatei und Weiterverarbeitung ihrer Daten

+
+Der Spielleiter der Tischtennis-Bezirksklasse möchte +den aktuellen Tabellenstand des Spielbetriebs darstellen lassen. Eine Datei + mit dem +aktuellen Stand aller Mannschaften steht hierfür zur Verfügung; allerdings noch nicht + in Form einer sortierten Tabelle. Die Mannschaftsdaten liegen als Binärdatei +vor. Die nebenstehende Abbildung zeigt die verwendete Datenstruktur. Der in der +Datei vorhandene C-String für 'teamName' ist in den einzelnen Datensätzen +unterschiedlich lang und enthält jeweils als letztes Zeichen eine binäre Null.

Als Hexadezimal-Darstellung sieht das +dann beispielsweise so aus - zu sehen ist zu Beginn der Datei der TSV Auerbach (teamName) mit 18 Spielen (matchesPlayed), +64:86 Sätzen (gamesWon : gamesLost) und 14:22 Punkten (pointsWon : pointsLost).

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributDatentyp
teamName std::string
matchesPlayedint
gamesWonint
gamesLostint
pointsWonint
pointsLostint
+
+ +

Technische Hinweise:   +

Entwerfen Sie ein Anwendungsprogramm, das +

    +
  • +die Daten dieser Datei in eine Tabelle einliest, sie am Bildschirm ausgibt, +innerhalb der Tabelle sortiert und danach nochmals am Bildschirm ausgibt und +
  • +
  • +die sortierte Tabelle in einer Textdatei speichert. +
  • +
+ +Sehen Sie folgende Klassen vor: +
Team   hat die oben dargestellte + Attributstruktur, die zur binären Eingabedatei passt,
Table   enthält einen vector<Team> + (mit allen Mannschaften) als Attribut.
+Zum Sortieren der Mannschaften innerhalb der Tabelle können Sie einen +beliebigen Sortieralgorithmus verwenden. Die Reihenfolge +der Mannschaften in der sortierten Tabelle wird bestimmt durch +
    +
  1. +die Anzahl der gewonnenen Punkte (pointsWon)
  2. + +
  3. +bei Gleichheit: Anzahl der verlorenen Punkte (pointsLost)
  4. + +
  5. +bei Gleichheit: Differenz der Satzresultate (gamesWon - gamesLost)
  6. + +
  7. +bei Gleichheit: ursprüngliche Reihenfolge
  8. +
+ + +
+ +
+
+
+ + + + + + + + + + +
+

+2    Bestandsliste (fakultativ)

+ +

+

+Für eine Eisenwarenhandlung soll eine Bestandsliste geführt werden, die +Auskunft über die vorhandenen Werkzeuge (toolName) einschließlich Stückzahl im +Lager (inStock) und Einzelpreis (unitPrice) gibt. Schreiben Sie ein Programm, das menügesteuert +
    +
  • die Binärdatei +(Random Access File) "tools.dta" + mit 100 leeren Records initialisiert, +
  • +
  • +die Eingabe der Daten für jedes Werkzeug erlaubt, +
  • +
  • +alle Werkzeuge mit ihren Daten auflistet, +
  • +
  • +das Löschen eines nicht mehr benötigten Records ermöglicht +
  • +
  • +und die Aktualisierung jeder Information in der Datei erlaubt. +
  • +
+ +

Die partNumber jedes Werkzeugs soll auch die Record-Nummer sein. +
+Benutzen Sie diese Datei zum Testen Ihres Programms. + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributDatentyp
partNumber int
toolNamechar[30]
inStockint
unitPricedouble
+
+ + + \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt3/index_dateien/AuschnittBinaerdatei.gif b/Bachelor/Prog2/Prakt3/index_dateien/AuschnittBinaerdatei.gif new file mode 100644 index 0000000..fca1c06 Binary files /dev/null and b/Bachelor/Prog2/Prakt3/index_dateien/AuschnittBinaerdatei.gif differ diff --git a/Bachelor/Prog2/Prakt4/Max.txt b/Bachelor/Prog2/Prakt4/Max.txt new file mode 100644 index 0000000..9b1a536 --- /dev/null +++ b/Bachelor/Prog2/Prakt4/Max.txt @@ -0,0 +1,67 @@ +Maonche held im Stall sisch Hinggel, +fittert se mit Waas un Dinggel +un mit Kleie - dodewäije, +dass se schaeine Aaije laeije. +Sundaogs hot me daonn im Dippche, +alsemol e Hinggelsippche, +un die Färren, zaart un foi, +stobbt me in die Pilwe noi, +daonn im Winde leit me haolt +liewe waarm im Bett wie kaolt +Sou waar sellemols des aa +bei dem Bolde soine Fraa: +Hinggel hatt se Sticke drei +un en Gickel noch debei. +Säigt de Max zum Moritz kaolt: +"Kumm, mer äijen jetz die Aolt!" - +-Hordisch nemme se e Broud, +schneires mirrem Messe noud +in vier Sticke, gaar nit grouß, +wie en klaone Finge blouß. + +Jede Mumbel werd vun unne +iwwes Kreiz daonn feschdgebunne, +un die läije se genaa +in de Houf vun sellre Fraa. - +Wie de Giggel guckt do druff, +sperrt e glei de Schnawwel uff, +kreeht un kreischt gickerigie, +un die Hinggel renne hie. + +Jede schlickt soin Brogge nunne- +äwwe daon, das is kao Wunne, +henggt des ao aom aonnen drou +un fengt glei ze ziehe ou. + +Riwwe, niwwe, hie un her +renne se die Kreiz un Quer, +gacken, fladden in die Häih - +äwwe lous kimmt kaone mäih! + +Aome laonge derre Ascht +hengge se, verstrumbt schun fascht; +mirrem Hals sou laong wie Mosse +misse se eer Läwe losse. +E letscht Aig noch - des is alles, +un daonn häwwe se de Dalles! + +De aold Bolden in de Stobb +häijet waos un häibt de Kobb. +Un schun sterzt se aus de Kaomme - +ach, waos is des fer en Jaomme! + + +"Ich arrm Witfraa bin geschlaoe - +issch kaonn´s jao kaom Mensche saoe! +Drowwe uffm Ebbelboam +henggt moin alleschäinschte Draom!" +Gaons vesteert un halwe kraonk +helt se´s Messe aus em Schaonk +schneid die Hinggel aob vum Ascht +groint sisch aus die Aache fascht, +dabbt ins Haus im diefschte Schmerz, +drickt des Veehzeig aon eer Herz. +Is de erschte Straasch vebei, +kimmt de zwatte siche glei. + +Quelle: Elisabeth Kunz: De Ourewälle Max un Moritz Odenwald-Verlag 2. Auflage 1996 \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt4/aufg1/.cdtbuild b/Bachelor/Prog2/Prakt4/aufg1/.cdtbuild new file mode 100644 index 0000000..8ff663c --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/.cdtbuild @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt4/aufg1/.cdtproject b/Bachelor/Prog2/Prakt4/aufg1/.cdtproject new file mode 100644 index 0000000..e36be9f --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/.cdtproject @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt4/aufg1/.project b/Bachelor/Prog2/Prakt4/aufg1/.project new file mode 100644 index 0000000..37c964a --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/.project @@ -0,0 +1,19 @@ + + + aufg1 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + + diff --git a/Bachelor/Prog2/Prakt4/aufg1/Debug/aufg1 b/Bachelor/Prog2/Prakt4/aufg1/Debug/aufg1 new file mode 100644 index 0000000..2f2827f Binary files /dev/null and b/Bachelor/Prog2/Prakt4/aufg1/Debug/aufg1 differ diff --git a/Bachelor/Prog2/Prakt4/aufg1/Debug/main.d b/Bachelor/Prog2/Prakt4/aufg1/Debug/main.d new file mode 100644 index 0000000..820922e --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/Debug/main.d @@ -0,0 +1,10 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +main.d ./main.o: ../main.cpp ../Tree.h ../Treenode.h + +../Tree.h: + +../Treenode.h: + diff --git a/Bachelor/Prog2/Prakt4/aufg1/Debug/makefile b/Bachelor/Prog2/Prakt4/aufg1/Debug/makefile new file mode 100644 index 0000000..0733bbf --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/Debug/makefile @@ -0,0 +1,30 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +ROOT := .. + +-include $(ROOT)/makefile.init + +RM := rm -rf + +# All of the sources participating in the build are defined here +-include sources.mk +-include $(SUBDIRS:%=%/subdir.mk) +-include objects.mk +-include $(DEPS) +-include $(ROOT)/makefile.defs + +all: aufg1 + +aufg1: $(OBJS) + @echo 'Building target: $@' + g++ -o $@ $(OBJS) $(USER_OBJS) $(LIBS) + @echo 'Finished building: $@' + +clean: + -$(RM) $(OBJS) $(DEPS) aufg1 + +.PHONY: all clean dependents + +-include $(ROOT)/makefile.targets diff --git a/Bachelor/Prog2/Prakt4/aufg1/Debug/objects.mk b/Bachelor/Prog2/Prakt4/aufg1/Debug/objects.mk new file mode 100644 index 0000000..c83c443 --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/Debug/objects.mk @@ -0,0 +1,13 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +LIBS := +USER_OBJS := + + +OBJS := \ + $(C_SRCS:$(ROOT)/%.c=%.o) $(C_UPPER_SRCS:$(ROOT)/%.C=%.o) $(CC_SRCS:$(ROOT)/%.cc=%.o) $(CXX_SRCS:$(ROOT)/%.cxx=%.o) $(CPP_SRCS:$(ROOT)/%.cpp=%.o) $(S_SRCS:$(ROOT)/%.s=%.o) $(S_UPPER_SRCS:$(ROOT)/%.S=%.o) + +DEPS := \ + $(C_SRCS:$(ROOT)/%.c=%.d) $(C_UPPER_SRCS:$(ROOT)/%.C=%.d) $(CC_SRCS:$(ROOT)/%.cc=%.d) $(CXX_SRCS:$(ROOT)/%.cxx=%.d) $(CPP_SRCS:$(ROOT)/%.cpp=%.d) $(S_SRCS:$(ROOT)/%.s=%.d) $(S_UPPER_SRCS:$(ROOT)/%.S=%.d) \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt4/aufg1/Debug/sources.mk b/Bachelor/Prog2/Prakt4/aufg1/Debug/sources.mk new file mode 100644 index 0000000..6c40c81 --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/Debug/sources.mk @@ -0,0 +1,16 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +C_SRCS := +C_UPPER_SRCS := +CC_SRCS := +CXX_SRCS := +CPP_SRCS := +S_SRCS := +S_UPPER_SRCS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + diff --git a/Bachelor/Prog2/Prakt4/aufg1/Debug/subdir.mk b/Bachelor/Prog2/Prakt4/aufg1/Debug/subdir.mk new file mode 100644 index 0000000..2f01c61 --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/Debug/subdir.mk @@ -0,0 +1,44 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +S_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CPP_SRCS += \ +${addprefix $(ROOT)/, \ +main.cpp \ +} + +CC_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CXX_SRCS += \ +${addprefix $(ROOT)/, \ +} + +S_SRCS += \ +${addprefix $(ROOT)/, \ +} + +# Each subdirectory must supply rules for building sources it contributes +%.o: $(ROOT)/%.cpp + @echo 'Building file: $<' + @echo g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< + @g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< && \ + echo -n $(@:%.o=%.d) $(dir $@) > $(@:%.o=%.d) && \ + g++ -MM -MG -P -w -O0 -g3 -Wall -c -fmessage-length=0 $< >> $(@:%.o=%.d) + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/Bachelor/Prog2/Prakt4/aufg1/Tree.h b/Bachelor/Prog2/Prakt4/aufg1/Tree.h new file mode 100644 index 0000000..bcb154f --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/Tree.h @@ -0,0 +1,130 @@ +// Fig. 15.16: tree.h +// Definition of template class Tree + +#ifndef TREE_H +#define TREE_H + +#include +using std::cout; +using std::endl; +using std::ostream; +#include + +#include + +#include +using std::ofstream; +using std::ifstream; +using std::ios; + +#include "Treenode.h" + +template< class NODETYPE > +class Tree { +public: + Tree(); + void insertNode( const NODETYPE & ); + void preOrderTraversal() const; + void inOrderTraversal() const; + void postOrderTraversal() const; + int gettreeElementCount(); +private: + TreeNode< NODETYPE > *rootPtr; + int treeElementCount; + + // utility functions + void insertNodeHelper( + TreeNode< NODETYPE > **, const NODETYPE & ); + void preOrderHelper( TreeNode< NODETYPE > * ) const; + void inOrderHelper( TreeNode< NODETYPE > * ) const; + void postOrderHelper( TreeNode< NODETYPE > * ) const; +}; + +template< class NODETYPE > +Tree< NODETYPE >::Tree() { rootPtr = 0; treeElementCount=0; } + +template< class NODETYPE > +void Tree< NODETYPE >::insertNode( const NODETYPE &value ) + { insertNodeHelper( &rootPtr, value ); } + +// This function receives a pointer to a pointer so the +// pointer can be modified. +template< class NODETYPE > +void Tree< NODETYPE >::insertNodeHelper( + TreeNode< NODETYPE > **ptr, const NODETYPE &value ) +{ + if ( *ptr == 0 ) { // tree is empty + *ptr = new TreeNode< NODETYPE >( value ); + (*ptr)->frequency++; + ++treeElementCount; + assert( *ptr != 0 ); + } + else // tree is not empty + if ( value < ( *ptr )->data ) + insertNodeHelper( &( ( *ptr )->leftPtr ), value ); + else + if ( value > ( *ptr )->data ) + insertNodeHelper( &( ( *ptr )->rightPtr ), value ); + else + (*ptr)->frequency++; +} + +template< class NODETYPE > +void Tree< NODETYPE >::preOrderTraversal() const + { preOrderHelper( rootPtr ); } + +template< class NODETYPE > +void Tree< NODETYPE >::preOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + if ( ptr != 0 ) { + cout << ptr->data << ' '; + preOrderHelper( ptr->leftPtr ); + preOrderHelper( ptr->rightPtr ); + } +} + +template< class NODETYPE > +void Tree< NODETYPE >::inOrderTraversal() const + { inOrderHelper( rootPtr ); } + +template< class NODETYPE > +void Tree< NODETYPE >::inOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + ofstream outFile("output.txt",ios::app); + if( !outFile ) { + cerr << "Output-Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + if ( ptr != 0 ) { + inOrderHelper( ptr->leftPtr ); + outFile << std::setw(30) << std::left << std::setfill('.') << ptr->data + << ptr->frequency << endl; + inOrderHelper( ptr->rightPtr ); + } + outFile.close(); +} + +template< class NODETYPE > +void Tree< NODETYPE >::postOrderTraversal() const + { postOrderHelper( rootPtr ); } + +template< class NODETYPE > +void Tree< NODETYPE >::postOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + if ( ptr != 0 ) { + postOrderHelper( ptr->leftPtr ); + postOrderHelper( ptr->rightPtr ); + cout << ptr->data << ' '; + } +} + +template +int Tree::gettreeElementCount() +{ + return treeElementCount; +} + +#endif diff --git a/Bachelor/Prog2/Prakt4/aufg1/Treenode.h b/Bachelor/Prog2/Prakt4/aufg1/Treenode.h new file mode 100644 index 0000000..027ad0e --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/Treenode.h @@ -0,0 +1,24 @@ +// Fig. 15.16: treenode.h +// Definition of class TreeNode + +#ifndef TREENODE_H +#define TREENODE_H + +template< class NODETYPE > class Tree; // forward declaration + +template< class NODETYPE > +class TreeNode { + friend class Tree< NODETYPE >; +public: + TreeNode( const NODETYPE &d ) + : leftPtr( 0 ), data( d ), rightPtr( 0 ) { } + NODETYPE getData() const { return data; } + int getFreq() const { return frequency; } +private: + TreeNode< NODETYPE > *leftPtr; // pointer to left subtree + NODETYPE data; + int frequency; + TreeNode< NODETYPE > *rightPtr; // pointer to right subtree +}; + +#endif diff --git a/Bachelor/Prog2/Prakt4/aufg1/main.cpp b/Bachelor/Prog2/Prakt4/aufg1/main.cpp new file mode 100644 index 0000000..79581e3 --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/main.cpp @@ -0,0 +1,47 @@ +// Tree with string objects +// Author: Sven Eisenhauer +// Date: 05.06.05 + +#include +using std::cout; +using std::cerr; +using std::cin; +using std::endl; + +#include +using std::ofstream; +using std::ifstream; +using std::ios; + +#include +using std::string; + +#include +#include + +#include "Tree.h" + +int main() +{ + int wordsInFile=0; + Tree< string > wordTree; + string word; + + ifstream inFile( "max.txt", ios::in ); + + if( !inFile ) { + cerr << "Input-Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + + while( inFile >> word) { + wordTree.insertNode( *( new string( word ) ) ); + wordsInFile++; + } + + wordTree.inOrderTraversal(); + cout << "Words in input file: "<< wordsInFile << endl; + cout << "Different words: " << wordTree.gettreeElementCount() << endl; + + return 0; +} diff --git a/Bachelor/Prog2/Prakt4/aufg1/max.txt b/Bachelor/Prog2/Prakt4/aufg1/max.txt new file mode 100644 index 0000000..9b1a536 --- /dev/null +++ b/Bachelor/Prog2/Prakt4/aufg1/max.txt @@ -0,0 +1,67 @@ +Maonche held im Stall sisch Hinggel, +fittert se mit Waas un Dinggel +un mit Kleie - dodewäije, +dass se schaeine Aaije laeije. +Sundaogs hot me daonn im Dippche, +alsemol e Hinggelsippche, +un die Färren, zaart un foi, +stobbt me in die Pilwe noi, +daonn im Winde leit me haolt +liewe waarm im Bett wie kaolt +Sou waar sellemols des aa +bei dem Bolde soine Fraa: +Hinggel hatt se Sticke drei +un en Gickel noch debei. +Säigt de Max zum Moritz kaolt: +"Kumm, mer äijen jetz die Aolt!" - +-Hordisch nemme se e Broud, +schneires mirrem Messe noud +in vier Sticke, gaar nit grouß, +wie en klaone Finge blouß. + +Jede Mumbel werd vun unne +iwwes Kreiz daonn feschdgebunne, +un die läije se genaa +in de Houf vun sellre Fraa. - +Wie de Giggel guckt do druff, +sperrt e glei de Schnawwel uff, +kreeht un kreischt gickerigie, +un die Hinggel renne hie. + +Jede schlickt soin Brogge nunne- +äwwe daon, das is kao Wunne, +henggt des ao aom aonnen drou +un fengt glei ze ziehe ou. + +Riwwe, niwwe, hie un her +renne se die Kreiz un Quer, +gacken, fladden in die Häih - +äwwe lous kimmt kaone mäih! + +Aome laonge derre Ascht +hengge se, verstrumbt schun fascht; +mirrem Hals sou laong wie Mosse +misse se eer Läwe losse. +E letscht Aig noch - des is alles, +un daonn häwwe se de Dalles! + +De aold Bolden in de Stobb +häijet waos un häibt de Kobb. +Un schun sterzt se aus de Kaomme - +ach, waos is des fer en Jaomme! + + +"Ich arrm Witfraa bin geschlaoe - +issch kaonn´s jao kaom Mensche saoe! +Drowwe uffm Ebbelboam +henggt moin alleschäinschte Draom!" +Gaons vesteert un halwe kraonk +helt se´s Messe aus em Schaonk +schneid die Hinggel aob vum Ascht +groint sisch aus die Aache fascht, +dabbt ins Haus im diefschte Schmerz, +drickt des Veehzeig aon eer Herz. +Is de erschte Straasch vebei, +kimmt de zwatte siche glei. + +Quelle: Elisabeth Kunz: De Ourewälle Max un Moritz Odenwald-Verlag 2. Auflage 1996 \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt4/index.htm b/Bachelor/Prog2/Prakt4/index.htm new file mode 100644 index 0000000..b94d773 --- /dev/null +++ b/Bachelor/Prog2/Prakt4/index.htm @@ -0,0 +1,170 @@ + + + + +Praktikum 3 + + + + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren II  +
Praktikum
+
+
4
+
+ +
+ + + + +
Ziel: +Sie sollen die Datenstruktur Baum in Form einer Template-Klasse anwenden können. +
+ +
+ + + + + + + +
+

+1    Wörterliste

+
+Zu einer gegebenen, beliebigen Textdatei soll eine Liste der darin +auftretenden Wörter erstellt werden. Alle Wörter werden dabei +alphabetisch sortiert in eine zweite Textdatei ausgegeben. Jedes +Wort soll nur einmal in der Liste wiedergegeben werden; zusätzlich +soll angegeben werden, wie oft es in der Ursprungsdatei vorkommt. Die Einträge +in der Ausgabedatei sollen formatiert sein (s. Beispiel). Auf der Konsole soll +außerdem die Gesamtzahl der Wörter und die Anzahl der unterschiedlichen in der Eingabedatei +auftretenden Wörter ausgegeben werden. +
Ein Beispiel : +
+ + + + + + + + + + + +
Eingabedatei:Ausgabedatei:
Zu einer gegebenen, beliebigen Textdatei soll eine Liste der darin +auftretenden Wörter erstellt werden. Alle Wörter werden dabei +alphabetisch sortiert in eine zweite Textdatei ausgegeben.Alle..........................1 +Liste.........................1 +Textdatei.....................2 +Wörter........................2 +Zu............................1 +alphabetisch..................1 +auftretenden..................1 +ausgegeben....................1 +beliebigen....................1 +dabei.........................1 +darin.........................1 +der...........................1 +eine..........................2 +einer.........................1 +erstellt......................1 +gegebenen,....................1 +in............................1 +soll..........................1 +sortiert......................1 +werden........................1 +werden........................1 +zweite........................1
+ +
+ + + + +

Technische Hinweise: +

    +
  • + Verwenden Sie die Template-Klasse Tree aus der Vorlesung, indem Sie im +Anwendungsprogramm mit einem Tree<string> - Objekt arbeiten. +
  • +
  • +Führen Sie ein Attribut frequency in die Template-Klasse + TreeNode ein und erweitern Sie die +Methode insertNodeHelper an der +passenden Stelle, um mehrfach vorkommende Wörter durch Inkrementierung von frequency +zu zählen. +
  • +
  • +Modifizieren Sie die +Methode inOrderHelper so, dass +die Wörter mit ihren Häufigkeiten nicht auf die Konsole, sondern richtig +formatiert in die oben erwähnte Ausgabedatei geschrieben werden. +
  • +
  • +Eine Sortierung nach dem eingebauten Code ASCII reicht aus (Sortierung nach +DUDEN ist nicht verlangt). Weiter ist nicht verlangt, echte Wörter +zu erkennen ("gegebenen," [incl. Komma] gilt in dem Beispiel oben +auch als ein Wort). +
  • +
  • +Verwenden Sie für die Demonstration Ihres Programms +während des Praktikums diese Datei. +
  • +
+ + + + +
+ + + + +
+

+2    Verbesserte Wörterliste (fakultativ)

+ +

Verbessern Sie Ihr Programm aus Aufgabe 1, indem Sie echte Wörter erkennen +(also Satzzeichen und Ziffern entfernen) und eine wirkliche lexikalische +Sortierung vornehmen (also groß und klein geschriebene Wörter nicht separat +sortieren sowie die Umlaute richtig einsortieren). Realisieren Sie zur Lösung dieser Aufgaben +eine Klasse GermanWord, +die es Ihnen erlaubt, die Template-Klassen aus Aufgabe 1 unverändert zu +übernehmen, indem Sie im Anwendungsprogramm jetzt mit einem Tree<GermanWord> - Objekt arbeiten. +Ihre GermanWord-Klasse sollte folgende Methoden enthalten: +

    +
  • +Der Konstruktor übernimmt einen string und entfernt alle Satzzeichen und +Ziffern, so dass nur noch echte Wörter übrig bleiben. Verwenden Sie hierzu +Methoden +der string-Klasse +wie find_first_of und replace.
  • +Die überladenen Operatoren operator< und operator> sorgen dafür, dass groß und +klein geschriebene Wörter nicht wie bei der einfachen ASCII-Code-Sortierung separat +sortiert werden und dass die Umlaute richtig +einsortiert werden (also z.B. 'ä' unter 'a').
  • +Eine Methode isEmpty sollte vorhanden sein, damit im Anwendungsprogramm nur +nicht-leere GermanWord-Objekte (also keine, die nur einen +leeren string enthalten) in den Tree eingefügt werden können.
  • +Ein cast-Operator operator string  soll vorhanden sein, damit der Tree aus +Aufgabe 1 unverändert übernommen werden kann (und GermanWord-Objekte wenn nötig +implizit in strings gewandelt werden).
+ + + \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt5/Aufg1/.cdtbuild b/Bachelor/Prog2/Prakt5/Aufg1/.cdtbuild new file mode 100644 index 0000000..b4ce8ad --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/.cdtbuild @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt5/Aufg1/.cdtproject b/Bachelor/Prog2/Prakt5/Aufg1/.cdtproject new file mode 100644 index 0000000..bd768a8 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/.cdtproject @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Bachelor/Prog2/Prakt5/Aufg1/.project b/Bachelor/Prog2/Prakt5/Aufg1/.project new file mode 100644 index 0000000..02b0148 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/.project @@ -0,0 +1,19 @@ + + + Aufg1 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + + diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsp b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsp new file mode 100644 index 0000000..1051125 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="Aufg1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Aufg1 - 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 "Aufg1.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 "Aufg1.mak" CFG="Aufg1 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "Aufg1 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "Aufg1 - 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)" == "Aufg1 - 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)" == "Aufg1 - 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 /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 "Aufg1 - Win32 Release" +# Name "Aufg1 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# 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/Prakt5/Aufg1/Aufg1.dsw b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsw new file mode 100644 index 0000000..11f6b18 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN! + +############################################################################### + +Project: "Aufg1"=.\Aufg1.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.ncb b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.ncb new file mode 100644 index 0000000..1ce0270 Binary files /dev/null and b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.ncb differ diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.opt b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.opt new file mode 100644 index 0000000..c1e3b51 Binary files /dev/null and b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.opt differ diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.plg b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.plg new file mode 100644 index 0000000..f63f1a5 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Aufg1.plg @@ -0,0 +1,44 @@ + + +
+

Erstellungsprotokoll

+

+--------------------Konfiguration: Aufg1 - Win32 Debug-------------------- +

+

Befehlszeilen

+Erstellen der temporären Datei "C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP1B.tmp" mit Inhalten +[ +/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/Aufg1.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"D:\Studium\Prog2\Prakt5\Aufg1\main.cpp" +] +Creating command line "cl.exe @C:\DOKUME~1\SVEN~1.HOM\LOKALE~1\Temp\RSP1B.tmp" +

Ausgabefenster

+Kompilierung läuft... +main.cpp +c:\programme\microsoft visual studio\vc98\include\xtree(118) : warning C4786: 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >' : Bezeichner wurde auf '255' Zeichen in den Debug-Informationen reduziert + c:\programme\microsoft visual studio\vc98\include\map(46) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >' + D:\Studium\Prog2\Prakt5\Aufg1\main.cpp(32) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >' +c:\programme\microsoft visual studio\vc98\include\xtree(118) : warning C4786: 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >::const_iterator' : Bezeichner wurde auf '255' Zeichen in den Debug-Informationen reduziert + c:\programme\microsoft visual studio\vc98\include\map(46) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >' + D:\Studium\Prog2\Prakt5\Aufg1\main.cpp(32) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >' +c:\programme\microsoft visual studio\vc98\include\xtree(118) : warning C4786: 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >::iterator' : Bezeichner wurde auf '255' Zeichen in den Debug-Informationen reduziert + c:\programme\microsoft visual studio\vc98\include\map(46) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >' + D:\Studium\Prog2\Prakt5\Aufg1\main.cpp(32) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >' +c:\programme\microsoft visual studio\vc98\include\xtree(118) : warning C4786: 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Node' : Bezeichner wurde auf '255' Zeichen in den Debug-Informationen reduziert + c:\programme\microsoft visual studio\vc98\include\map(46) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >' + D:\Studium\Prog2\Prakt5\Aufg1\main.cpp(32) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >' +c:\programme\microsoft visual studio\vc98\include\xtree(118) : warning C4786: 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >::const_iterator' : Bezeichner wurde auf '255' Zeichen in den Debug-Informationen reduziert + c:\programme\microsoft visual studio\vc98\include\map(46) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::_Tree,std::allocator >,std::pair,std::allocator > const ,std::basic_string,std::allocator > >,std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >::_Kfn,std::less,std::allocator > >,std::allocator,std::allocator > > >' + D:\Studium\Prog2\Prakt5\Aufg1\main.cpp(32) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'std::map,std::allocator >,std::basic_string,std::allocator >,std::less,std::allocator > >,std::allocator,std::allocator > > >' +D:\Studium\Prog2\Prakt5\Aufg1\main.cpp(50) : error C2664: 'class std::basic_istream > &__thiscall std::basic_istream >::getline(char *,int)' : Konvertierung des Parameters 1 von 'class std::basic_string,class std::allocator >' in 'char *' nicht moeglich + Kein benutzerdefinierter Konvertierungsoperator verfuegbar, der diese Konvertierung durchfuehren kann, oder der Operator kann nicht aufgerufen werden +D:\Studium\Prog2\Prakt5\Aufg1\main.cpp(50) : fatal error C1903: Weiterverarbeitung nach vorhergehendem Fehler nicht moeglich; Kompilierung wird abgebrochen. +Fehler beim Ausführen von cl.exe. + + + +

Ergebnisse

+main.obj - 2 Fehler, 5 Warnung(en) +
+ + diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.exe b/Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.exe new file mode 100644 index 0000000..ac01652 Binary files /dev/null and b/Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.exe differ diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.pch b/Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.pch new file mode 100644 index 0000000..2da9163 Binary files /dev/null and b/Bachelor/Prog2/Prakt5/Aufg1/Debug/Aufg1.pch differ diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/Words.txt b/Bachelor/Prog2/Prakt5/Aufg1/Debug/Words.txt new file mode 100644 index 0000000..4a408d8 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Debug/Words.txt @@ -0,0 +1,25 @@ +blue,blau +red,rot +chance,Zufall +luminous color,Leuchtfarbe +black,schwarz +lump,Stueck +fact,Tatsache +ballot,geheime Abstimmung +meeting,Treffen +wary,vorsichtig +plea,Bitte +marauder,Pluenderer +height,Hoehe +essential,notwendig +disclaim,abstreiten +parsley,Petersilie +indefatigable,unermuedlich +combat,Kampf +broom,Besen +nugatory,belanglos +profession,Beruf +sundae,Eisbecher +riddle,Raetsel +next door,nebenan +map,Karte diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/main.d b/Bachelor/Prog2/Prakt5/Aufg1/Debug/main.d new file mode 100644 index 0000000..d2c1ccc --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Debug/main.d @@ -0,0 +1,5 @@ +################################################################################ +# Diese Datei wurde automatisch generiert. Sie darf nicht bearbeitet werden! +################################################################################ + +main.d main.o: ../main.cpp diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/makefile b/Bachelor/Prog2/Prakt5/Aufg1/Debug/makefile new file mode 100644 index 0000000..612cc5b --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Debug/makefile @@ -0,0 +1,30 @@ +################################################################################ +# Diese Datei wurde automatisch generiert. Sie darf nicht bearbeitet werden! +################################################################################ + +ROOT := .. + +-include $(ROOT)/makefile.init + +RM := rm -rf + +# Alle an der Erstellung beteiligten Quellen sind hier definiert. +-include sources.mk +-include $(SUBDIRS:%=%/subdir.mk) +-include objects.mk +-include $(DEPS) +-include $(ROOT)/makefile.defs + +all: Aufg1.exe + +Aufg1.exe: $(OBJS) + @echo 'Ziel wird erstellt: $@' + g++ -o $@ $(OBJS) $(USER_OBJS) $(LIBS) + @echo 'Erstellung fertig gestellt: $@' + +clean: + -$(RM) $(OBJS) $(DEPS) Aufg1.exe + +.PHONY: all clean dependents + +-include $(ROOT)/makefile.targets diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/objects.mk b/Bachelor/Prog2/Prakt5/Aufg1/Debug/objects.mk new file mode 100644 index 0000000..8bcaab0 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Debug/objects.mk @@ -0,0 +1,13 @@ +################################################################################ +# Diese Datei wurde automatisch generiert. Sie darf nicht bearbeitet werden! +################################################################################ + +LIBS := +USER_OBJS := + + +OBJS := \ + $(C_SRCS:$(ROOT)/%.c=%.o) $(C_UPPER_SRCS:$(ROOT)/%.C=%.o) $(CC_SRCS:$(ROOT)/%.cc=%.o) $(CXX_SRCS:$(ROOT)/%.cxx=%.o) $(CPP_SRCS:$(ROOT)/%.cpp=%.o) $(S_SRCS:$(ROOT)/%.s=%.o) $(S_UPPER_SRCS:$(ROOT)/%.S=%.o) + +DEPS := \ + $(C_SRCS:$(ROOT)/%.c=%.d) $(C_UPPER_SRCS:$(ROOT)/%.C=%.d) $(CC_SRCS:$(ROOT)/%.cc=%.d) $(CXX_SRCS:$(ROOT)/%.cxx=%.d) $(CPP_SRCS:$(ROOT)/%.cpp=%.d) $(S_SRCS:$(ROOT)/%.s=%.d) $(S_UPPER_SRCS:$(ROOT)/%.S=%.d) \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/sources.mk b/Bachelor/Prog2/Prakt5/Aufg1/Debug/sources.mk new file mode 100644 index 0000000..6f3ea65 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Debug/sources.mk @@ -0,0 +1,16 @@ +################################################################################ +# Diese Datei wurde automatisch generiert. Sie darf nicht bearbeitet werden! +################################################################################ + +C_SRCS := +C_UPPER_SRCS := +CC_SRCS := +CXX_SRCS := +CPP_SRCS := +S_SRCS := +S_UPPER_SRCS := + +# Jedes Unterverzeichnis mit Quellendateien muss hier beschrieben werden +SUBDIRS := \ +. \ + diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/subdir.mk b/Bachelor/Prog2/Prakt5/Aufg1/Debug/subdir.mk new file mode 100644 index 0000000..edf4334 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Debug/subdir.mk @@ -0,0 +1,44 @@ +################################################################################ +# Diese Datei wurde automatisch generiert. Sie darf nicht bearbeitet werden! +################################################################################ + +S_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CPP_SRCS += \ +${addprefix $(ROOT)/, \ +main.cpp \ +} + +CC_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_SRCS += \ +${addprefix $(ROOT)/, \ +} + +C_UPPER_SRCS += \ +${addprefix $(ROOT)/, \ +} + +CXX_SRCS += \ +${addprefix $(ROOT)/, \ +} + +S_SRCS += \ +${addprefix $(ROOT)/, \ +} + +# Jedes Unterverzeichnis muss Regeln für die von ihm ergänzten Erstellungsquellen angeben +%.o: $(ROOT)/%.cpp + @echo 'Datei wird erstellt: $<' + @echo g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< + @g++ -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< && \ + echo -n $(@:%.o=%.d) '' > $(@:%.o=%.d) && \ + g++ -MM -MG -P -w -O0 -g3 -Wall -c -fmessage-length=0 $< >> $(@:%.o=%.d) + @echo 'Erstellung fertig gestellt: $<' + @echo ' ' + + diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.idb b/Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.idb new file mode 100644 index 0000000..5060c09 Binary files /dev/null and b/Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.idb differ diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.pdb b/Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.pdb new file mode 100644 index 0000000..0a5b84d Binary files /dev/null and b/Bachelor/Prog2/Prakt5/Aufg1/Debug/vc60.pdb differ diff --git a/Bachelor/Prog2/Prakt5/Aufg1/Words.txt b/Bachelor/Prog2/Prakt5/Aufg1/Words.txt new file mode 100644 index 0000000..4a408d8 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/Words.txt @@ -0,0 +1,25 @@ +blue,blau +red,rot +chance,Zufall +luminous color,Leuchtfarbe +black,schwarz +lump,Stueck +fact,Tatsache +ballot,geheime Abstimmung +meeting,Treffen +wary,vorsichtig +plea,Bitte +marauder,Pluenderer +height,Hoehe +essential,notwendig +disclaim,abstreiten +parsley,Petersilie +indefatigable,unermuedlich +combat,Kampf +broom,Besen +nugatory,belanglos +profession,Beruf +sundae,Eisbecher +riddle,Raetsel +next door,nebenan +map,Karte diff --git a/Bachelor/Prog2/Prakt5/Aufg1/main.cpp b/Bachelor/Prog2/Prakt5/Aufg1/main.cpp new file mode 100644 index 0000000..07e2b93 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg1/main.cpp @@ -0,0 +1,101 @@ +// Tree with string objects +// Author: Sven Eisenhauer +// Date: 20.06.05 + +#include +using std::cout; +using std::cerr; +using std::cin; +using std::endl; + +#include +using std::ofstream; +using std::ifstream; +using std::ios; +using std::getline; + +#include +using std::string; + +#include +using std::setw; +#include +#include + +#include +#include + +typedef std::map< string,string,std::less< string > > wordpairs; + +int main() +{ + wordpairs en_de,de_en; + wordpairs *pairPtr; + + string word; + string en; + string de; + int pos; + int end; + + ifstream inFile( "Words.txt", ios::in ); + + if( !inFile ) { + cerr << "Input-Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + + while( getline(inFile,word)) { + //cout << word << endl; + pos=word.find_first_of(','); + end=word.size(); + en.assign(word,0,pos); + de.assign(word,pos+1,end); + +// cout << de << "\t " << en << endl; + en_de.insert(wordpairs::value_type(en,de)); + de_en.insert(wordpairs::value_type(de,en)); + } + inFile.close(); + cout << "Englisch - Deutsch" << endl << endl; + for (wordpairs::const_iterator it=en_de.begin(); it!=en_de.end(); + it++) + { + cout<< setw(30) << it->first << "\t "<second<< endl; + } + cout << endl << endl<< "Deutsch - Englisch"<first << "\t "<second<< endl; + } + + srand(time(0)); + int lang=(rand()%2); + if (lang==0) + pairPtr=(&en_de); + else + pairPtr=(&de_en); + int posi=(rand()%(pairPtr->size())); + wordpairs::const_iterator it3=(pairPtr->begin()); + int counter=0; + int stop=0; + cout << endl << endl; + string eingabe; + while ( it3!=(pairPtr->end()) && stop==0) + { + it3++; + counter++; + if(posi==counter) + { + cout << it3->first << endl; + cout <<"Ihre Uebersetzung: "; + cin>>eingabe; + cout << "Ihre Eingabe: " << eingabe << endl; + cout << "Richtig ist:" << it3->second << endl; + stop=1; + } + } + + return 0; +} diff --git a/Bachelor/Prog2/Prakt5/Aufg2/uebklaus.htm b/Bachelor/Prog2/Prakt5/Aufg2/uebklaus.htm new file mode 100644 index 0000000..691d811 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/Aufg2/uebklaus.htm @@ -0,0 +1,209 @@ + + + + + Praktikum 5.2 + + +  + + + + + + + + +
FH Darmstadt  +
FB Informatik +

Prof.Dr.H.P.Weber

+
Programmieren II +
Übungsklausur
+
+
+

    Juni 2005

+
+
+ + + + + + + + + +
Name:MatNr.:USER:
+ + + + + +
Wesentliches Element vieler rundenbasierter Strategiespiele ist das Konzept der 'Stadt' +(Town): Vom +Spieler angelegte Objekte vom Typ Town sind für die Produktion sowohl von +Einheiten (wird hier nicht weiter betrachtet) als auch von Ressourcen wie Geld, Forschung, Luxusgüter +(darum soll es im folgenden gehen) zuständig.
+ + + + + +
Anforderungen für die Noten ausreichend und befriedigend:
+ +

Realisieren Sie die Klasse Town zusammen mit einem Anwendungsprogramm zum +Testen. Hierbei soll folgendes gelten:

+
    +
  • +Attribute von Town-Objekten sind name (Name der Stadt), size (Größe der Stadt), +money (Geldmenge, die jede Runde produziert wird), research +(Forschungsergebnisse, die jede Runde produziert werden), luxuryGoods +(Luxusgüter, die jede Runde produziert werden). name ist vom Typ string und wird +vom Konstruktor aus dem Anwendungsprogramm übernommen, alle anderen Attribute +sind vom Typ int und werden bei der Erzeugung einer Stadt mit dem Wert 1 +initialisiert.
  • +
  • +Die Methode grow erhöht alle Attribute eines Town-Objektes (außer name) um den +Wert 1.
  • +
  • +Der überladene operator<< gibt als erstes den Namen der Stadt und dann die aktuellen +Werte aller anderen Attribute in einer geeigneten Formatierung aus.
  • +
  • +Das Anwendungsprogramm soll dem Benutzer ein Menü mit den vier Alternativen
  • +
      +
    • +Neue Stadt +
    • +
    • +Nächste Runde +
    • +
    • +Alle Städte anzeigen +
    • +
    • +Spiel beenden
    • +
    +anbieten.
    +
      +
    • +Wenn der Benutzer 'Neue Stadt' auswählt, soll er nach einem Namen gefragt werden +und, nachdem dieser eingelesen wurde, ein Town-Objekt mit diesem Namen erzeugt werden. Dieses Objekt soll in eine +verkettete Liste allTowns eingefügt werden. +
    • +
    • +Wenn der Benutzer 'Nächste Runde' auswählt, soll ein Rundenzähler inkrementiert +werden. Alle drei Runden wird die grow-Methode für alle Städte in der Liste +aufgerufen. +
    • +
    • +Wenn der Benutzer 'Alle Städte anzeigen' auswählt, sollen alle +Städte in der Liste in alphabetischer Reihenfolge (Sortierung nach +ASCII-Code reicht aus) der Namen der Städte ausgegeben werden.
    • +
    + +
  • Hinweis: Es ist erlaubt und sinnvoll, für die verkettete Liste std::list aus +der STL zu benutzen.
  • +
+ + + + + +
Anforderungen für die Note gut:
+ +

Die Leistungsfähigkeit eines Town-Objektes wird neben seiner Größe vor allem +von den in der Stadt vorhandenen Gebäuden unterschiedlicher Art bestimmt. +Realisieren Sie eine einfache Vererbungshierarchie für die Gebäude, die eine +Stadt haben kann. Hierbei gilt folgendes:

+ +
    +
  • +Basisklasse ist die abstrakte Klasse Building. Sie enthält die rein virtuelle +Methode improveTown, über die die Ressourcenproduktion der Stadt +durch Gebäude verbessert werden kann. Außerdem enthält sie als Attribut eine +Referenz auf Town, die vom Konstruktor auf diejenige Stadt gesetzt wird, zu der +das jeweilige Gebäude gehört.
  • +
  • +Von Building abgeleitet sind die Klassen MoneyBuilding (mit dem int-Attribut +moneyAdder) und ResearchBuilding (mit dem +double-Attribut researchFactor).
  • +
  • +Von MoneyBuilding abgeleitet sind die Klassen Marketplace und Bank. Bei der +Erzeugung eines Marketplace-Objekts wird sein moneyAdder +auf den Wert 5 +gesetzt, bei der Erzeugung eines Bank-Objekts wird sein moneyAdder auf den Wert +10 gesetzt.
  • +
  • +Von ResearchBuilding abgeleitet sind die Klassen Library und University. Bei der +Erzeugung eines Library-Objekts wird sein researchFactor auf den Wert +1.3 gesetzt, +bei der Erzeugung eines University-Objekts wird sein researchFactor auf den Wert +1.5 gesetzt.
  • +
  • +Die Methode improveTown soll für Marketplace und Bank die entsprechenden +moneyAdder-Werte zum Attribut money der Stadt addieren. Im Fall von Library und +University sollen die researchFactor-Werte mit dem Attribut research der Stadt +multipliziert werden.
  • +
  • +Ergänzen Sie in der Town-Klasse als Attribut eine verkettete Liste von Building*-Zeigern. 
  • +
  • +Ergänzen Sie im Benutzer-Menü einen Punkt
  • +
      +
    • +Neues Gebäude für vorhandene Stadt
    • +
    +wo dem Benutzer eine Auflistung der möglichen Gebäude zur Auswahl angezeigt wird. +Nachdem ein Gebäude ausgewählt wurde, soll nach dem Namen der Stadt gefragt +werden, zu der das Gebäude hinzugefügt wird. Das Gebäude-Objekt wird dann +dynamisch erzeugt und in die Building*-Liste der betreffenden +Stadt eingefügt. Hierfür soll die Town-Klasse um eine Methode insertBuilding +ergänzt werden. +
  • Damit die vorhandenen Gebäude die Ressourcenerzeugung in einer Stadt +beeinflussen, wird die Methode grow ergänzt: Sie soll nach der +oben angesprochenen Inkrementierung der Attribute einer Stadt die Building*-Liste +der Stadt durchgehen und für jedes vorhandene Gebäude improveTown aufrufen.
  • +
+ + + + + +
Anforderungen für die Note sehr gut:
+ +

Der Benutzer soll die Möglichkeit haben, den Spielstand zu einem beliebigen +Zeitpunkt abzuspeichern und vorher gespeicherte Spielstände wieder zu laden. Dabei gilt folgendes:

+ +
    +
  • +Ergänzen Sie im Benutzer-Menü die Punkte
  • +
      +
    • +Spiel speichern
    • +
    • +Spiel laden
    • +
    +Hierbei soll der Benutzer jeweils aufgefordert werden, den Namen der Datei +anzugeben, in die der Spielstand gespeichert bzw. aus der der Spielstand geladen +werden soll. +
  • +Beim Speichern eines Spiels sollen alle Informationen, die den aktuellen +Spielstand kennzeichnen, in einer Textdatei abgelegt werden. Dazu gehört auch, +dass in einer geeigneten Form für jede Stadt festgehalten wird, welche Gebäude +sie besitzt. Nutzen Sie hierzu die Möglichkeiten der Typinformationen zur +Laufzeit (RTTI), indem Sie z.B. typeid einsetzen.
  • +
+ + + + + +
Note:
+ + + + + +
 
+ + \ No newline at end of file diff --git a/Bachelor/Prog2/Prakt5/index.htm b/Bachelor/Prog2/Prakt5/index.htm new file mode 100644 index 0000000..db0b680 --- /dev/null +++ b/Bachelor/Prog2/Prakt5/index.htm @@ -0,0 +1,101 @@ + + + + + + Praktikum 5 + + +  + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren II +
Praktikum
+
+
5
+
+ +
+ + + + + +
Ziel: +Sie sollen Datenstrukturen aus der Standard Template Library (STL) anwenden können. +
+ +
+
+ + + + + + + +
+

1    Vokabeltrainer

+

Sie sollen ein Programm für einen Vokabeltrainer schreiben.

+
    +
  • +In der Datei Words.txt sind folgende Daten gespeichert: +pro Zeile ein englisches Wort und - getrennt durch ein Komma, aber in derselben +Zeile - die deutsche Übersetzung des englischen Wortes. Lesen Sie alle +englisch/deutschen Wortpaare von der Datei in eine geeignet gewählte +Datenstruktur aus der STL ein. Nachdem alle Daten eingelesen sind, soll Ihr +Programm die Wortpaare alphabetisch (ASCII-Codierung genügt) nach den englischen +Wörtern sortiert auf die Konsole ausgeben (pro Zeile ein englisches Wort und die +zugehörige deutsche Übersetzung).  +
  • +
  • +Ihr Programm soll zusätzlich die Wortpaare nach den deutschen Wörtern sortiert +(alphabetisch; ASCII-Codierung genügt) ausgeben. Auch hierbei soll ein Wortpaar +pro Zeile ausgegeben werden: Das Wort, nach dem sortiert wurde, steht als +erstes, die Übersetzung steht als zweites.
  • +
  • +Ihr Programm soll als nächstes ein zufällig gewähltes englisches oder +deutsches Wort (englisch und deutsch etwa gleich häufig) aus der Datenstruktur +anzeigen und den Benutzer auffordern, die deutsche bzw englische Übersetzung +einzugeben. Nachdem der Benutzer seine Eingabe gemacht hat, soll das Programm +die in der Datenstruktur gespeicherte, richtige Übersetzung zusammen mit der +Benutzereingabe anzeigen.
  • +
+
+ +
+
+
+
+ + + +
+

+2    Übungsklausur (fakultativ)

+ + + +

+Als Klausurvorbereitung können Sie diese Aufgabe +bearbeiten. Ein Hinweis: Die Aufgabe entspricht im Schwierigkeitsgrad der +Klausur. Um ausreichend Gelegenheit zum Üben zu geben, liegt sie jedoch in der +Arbeitsmenge über dem, was Sie in den 180 Minuten der Klausur +bearbeiten werden.

+ + + +
  + + \ No newline at end of file diff --git a/Bachelor/Prog2/SortedList/Ref.cpp b/Bachelor/Prog2/SortedList/Ref.cpp new file mode 100644 index 0000000..49547a5 --- /dev/null +++ b/Bachelor/Prog2/SortedList/Ref.cpp @@ -0,0 +1,23 @@ +template< class NODETYPE > +void Tree< NODETYPE >::insertNode( const NODETYPE &value ) + { insertNodeHelper( rootPtr, value ); } + +// This function receives a reference to a pointer so the +// pointer itself (not a copy of it!) can be modified. +template< class NODETYPE > +void Tree< NODETYPE >::insertNodeHelper( + TreeNode< NODETYPE >*& ptr, const NODETYPE &value ) +{ + if ( ptr == 0 ) { // tree is empty + ptr = new TreeNode< NODETYPE >( value ); + assert( ptr != 0 ); + } + else // tree is not empty + if ( value < ptr->data ) + insertNodeHelper( ptr->leftPtr, value ); + else + if ( value > ptr->data ) + insertNodeHelper( ptr->rightPtr, value ); + else + cout << value << " dup" << endl; +} \ No newline at end of file diff --git a/Bachelor/Prog2/SortedList/list.h b/Bachelor/Prog2/SortedList/list.h new file mode 100644 index 0000000..f50f6db --- /dev/null +++ b/Bachelor/Prog2/SortedList/list.h @@ -0,0 +1,266 @@ +// Template List class definition + +#ifndef LIST_H +#define LIST_H + +#include +using std::cout; + +#include + +#include "listnode.h" // ListNode class definition + +template< class NODETYPE > +class List { + +public: + List(); + ~List(); + void insertInOrder( const NODETYPE &value ); + bool removeFromFront( NODETYPE & ); + bool removeFromBack( NODETYPE & ); + bool deleteNode( const NODETYPE &, NODETYPE & ); + bool isEmpty() const; + void print() const; + +private: + void insertAtFront( const NODETYPE & ); + void insertAtBack( const NODETYPE & ); + + ListNode< NODETYPE > *firstPtr; // pointer to first node + ListNode< NODETYPE > *lastPtr; // pointer to last node + +}; // end class List + +// default constructor +template< class NODETYPE > +List< NODETYPE >::List() + : firstPtr( 0 ), + lastPtr( 0 ) +{ + // empty body + +} // end List constructor + +// destructor +template< class NODETYPE > +List< NODETYPE >::~List() +{ + if ( !isEmpty() ) { // List is not empty + cout << "Destroying nodes ...\n"; + + ListNode< NODETYPE > *currentPtr = firstPtr; + ListNode< NODETYPE > *tempPtr; + + while ( currentPtr != 0 ) { // delete remaining nodes + tempPtr = currentPtr; + cout << tempPtr->data << '\n'; + currentPtr = currentPtr->nextPtr; + delete tempPtr; + + } // end while + + } // end if + + cout << "All nodes destroyed\n\n"; + +} // end List destructor + +// insert node at front of list +template< class NODETYPE > +void List< NODETYPE >::insertAtFront( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = new ListNode< NODETYPE >( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + newPtr->nextPtr = firstPtr; + firstPtr = newPtr; + + } // end else + +} // end function insertAtFront + +// insert node at back of list +template< class NODETYPE > +void List< NODETYPE >::insertAtBack( const NODETYPE &value ) +{ + ListNode< NODETYPE > *newPtr = new ListNode< NODETYPE >( value ); + + if ( isEmpty() ) // List is empty + firstPtr = lastPtr = newPtr; + + else { // List is not empty + lastPtr->nextPtr = newPtr; + lastPtr = newPtr; + + } // end else + +} // end function insertAtBack + +// delete node from front of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromFront( NODETYPE &value ) +{ + if ( isEmpty() ) // List is empty + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = firstPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else + firstPtr = firstPtr->nextPtr; + + value = tempPtr->data; // data being removed + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function removeFromFront + +// delete node from back of list +template< class NODETYPE > +bool List< NODETYPE >::removeFromBack( NODETYPE &value ) +{ + if ( isEmpty() ) + return false; // delete unsuccessful + + else { + ListNode< NODETYPE > *tempPtr = lastPtr; + + if ( firstPtr == lastPtr ) + firstPtr = lastPtr = 0; + else { + ListNode< NODETYPE > *currentPtr = firstPtr; + + // locate second-to-last element + while ( currentPtr->nextPtr != lastPtr ) + currentPtr = currentPtr->nextPtr; + + lastPtr = currentPtr; + currentPtr->nextPtr = 0; + + } // end else + + value = tempPtr->data; + delete tempPtr; + + return true; // delete successful + + } // end else + +} // end function removeFromBack + + +// insert node in sorted order +template< class NODETYPE > +void List< NODETYPE >::insertInOrder( const NODETYPE &value ) +{ + if ( isEmpty() ) { + ListNode< NODETYPE > *newPtr = new ListNode< NODETYPE >( value ); + firstPtr = lastPtr = newPtr; + } + else { + if( firstPtr->data >= value) + insertAtFront( value ); + else if( lastPtr->data < value) + insertAtBack( value ); + else { + ListNode< NODETYPE > *currentPtr = firstPtr->nextPtr, + *previousPtr = firstPtr, + *newPtr = new ListNode< NODETYPE >( value ); + + // locate element before new node gets inserted + while ( currentPtr != lastPtr && currentPtr->data < value ) { + previousPtr = currentPtr; + currentPtr = currentPtr->nextPtr; + } + + previousPtr->nextPtr = newPtr; + newPtr->nextPtr = currentPtr; + + } // end else + + } // end else + +} // end function insertInOrder + +// delete a node from anywhere in the list +template< class NODETYPE > +bool List< NODETYPE >::deleteNode( const NODETYPE &value, NODETYPE &deletedVal ) +{ + if ( isEmpty() ) + return false; // delete unsuccessful + else { + if ( firstPtr->data == value ) { + removeFromFront( deletedVal ); + return true; // delete successful + } + else if ( lastPtr->data == value ) { + removeFromBack( deletedVal ); + return true; // delete successful + } + else { + ListNode< NODETYPE > *currentPtr = firstPtr->nextPtr, + *previousPtr = firstPtr; + + while ( currentPtr != lastPtr && currentPtr->data < value ) { + previousPtr = currentPtr; + currentPtr = currentPtr->nextPtr; + } + + if ( currentPtr->data == value ) { + ListNode< NODETYPE > *tempPtr = currentPtr; + deletedVal = currentPtr->data; + previousPtr = currentPtr->nextPtr; + delete tempPtr; + return true; // delete successful + } + else + return false; // delete unsuccessful + + } // end else + + } // end else + +} // end function deleteNode + +// is List empty? +template< class NODETYPE > +bool List< NODETYPE >::isEmpty() const +{ + return firstPtr == 0; + +} // end function isEmpty + +// display contents of List +template< class NODETYPE > +void List< NODETYPE >::print() const +{ + if ( isEmpty() ) { + cout << "The list is empty\n\n"; + return; + + } // end if + + ListNode< NODETYPE > *currentPtr = firstPtr; + + cout << "The list is: "; + + while ( currentPtr != 0 ) { + cout << currentPtr->data << ' '; + currentPtr = currentPtr->nextPtr; + + } // end while + + cout << "\n\n"; + +} // end function print + +#endif \ No newline at end of file diff --git a/Bachelor/Prog2/SortedList/listnode.h b/Bachelor/Prog2/SortedList/listnode.h new file mode 100644 index 0000000..fd51ef4 --- /dev/null +++ b/Bachelor/Prog2/SortedList/listnode.h @@ -0,0 +1,41 @@ +// Template ListNode class definition + +#ifndef LISTNODE_H +#define LISTNODE_H + +// forward declaration of class List +template< class NODETYPE > class List; + +template< class NODETYPE > +class ListNode { + friend class List< NODETYPE >; // make List a friend + +public: + ListNode( const NODETYPE & ); // constructor + NODETYPE getData() const; // return data in node + +private: + NODETYPE data; // data + ListNode< NODETYPE > *nextPtr; // next node in list + +}; // end class ListNode + +// constructor +template< class NODETYPE > +ListNode< NODETYPE >::ListNode( const NODETYPE &info ) + : data( info ), + nextPtr( 0 ) +{ + // empty body + +} // end ListNode constructor + +// return copy of data in node +template< class NODETYPE > +NODETYPE ListNode< NODETYPE >::getData() const +{ + return data; + +} // end function getData + +#endif \ No newline at end of file diff --git a/Bachelor/Prog2/SortedList/sortedList1.cpp b/Bachelor/Prog2/SortedList/sortedList1.cpp new file mode 100644 index 0000000..f0b548b --- /dev/null +++ b/Bachelor/Prog2/SortedList/sortedList1.cpp @@ -0,0 +1,80 @@ +// List class test program for sorted list + +#include +using std::cin; +using std::endl; + +#include +using std::string; + +#include "list.h" // List class definition + +// function to test a List +template< class T > +void testList( List< T > &listObject, const string &typeName ) +{ + cout << "Testing a List of " << typeName << " values\n"; + + instructions(); // display instructions + + int choice; + T value; + + do { + cout << "? "; + cin >> choice; + + switch ( choice ) { + case 1: + cout << "Enter " << typeName << ": "; + cin >> value; + listObject.insertInOrder( value ); + listObject.print(); + break; + + case 2: + if ( listObject.removeFromFront( value ) ) + cout << value << " removed from list\n"; + + listObject.print(); + break; + + case 3: + if ( listObject.removeFromBack( value ) ) + cout << value << " removed from list\n"; + + listObject.print(); + break; + + } // end switch + + } while ( choice != 5 ); // end do/while + + cout << "End list test\n\n"; + +} // end function testList + +// display program instructions to user +void instructions() +{ + cout << "Enter one of the following:\n" + << " 1 to insert in sorted order into the list\n" + << " 2 to delete from beginning of list\n" + << " 3 to delete from end of list\n" + << " 5 to end list processing\n"; + +} // end function instructions + +int main() +{ + // test List of int values + List< int > integerList; + testList( integerList, "integer" ); + + // test List of double values + List< double > doubleList; + testList( doubleList, "double" ); + + return 0; + +} // end main \ No newline at end of file diff --git a/Bachelor/Prog2/SortedList2/Compare.h b/Bachelor/Prog2/SortedList2/Compare.h new file mode 100644 index 0000000..336cf08 --- /dev/null +++ b/Bachelor/Prog2/SortedList2/Compare.h @@ -0,0 +1,20 @@ +// Function-object to compare two objects. +// This template needs operator<() for objects of type T, but it is possible to +// specialize it for any given type so that this template is not used. +// Author: U.Breymann / H.P.Weber +// Date: 05.05.05 + +#ifndef COMPARE_H +#define COMPARE_H + +template +class Compare { +public: + bool operator()( const T& a, const T& b ) const + { + return a < b; + } +}; + +#endif + diff --git a/Bachelor/Prog2/SortedList2/SL_test.cpp b/Bachelor/Prog2/SortedList2/SL_test.cpp new file mode 100644 index 0000000..f836972 --- /dev/null +++ b/Bachelor/Prog2/SortedList2/SL_test.cpp @@ -0,0 +1,75 @@ +// Driver for SortedList +// Author: U.Breymann / H.P.Weber +// Date: 05.05.05 + +#include +using std::cout; +using std::endl; + +#include +using std::setw; + +#include // std::copy + +#include // sin() +#include // abs(int) + +#include "SortedList.h" + +template <> +class Compare< int > { // specialization +public: + enum sortCriterion{ increasing, decreasing, absoluteValue }; + Compare( sortCriterion s = increasing ) : howToSort( s ) { } // Constructor + bool operator()( const int& a, const int& b ) const + { + bool result; + switch( howToSort ) { + case increasing: result = a < b; break; + case decreasing: result = a > b; break; + case absoluteValue: result = abs(a) < abs(b); break; + default: throw "Compare.operator()(): default darf nicht erreicht werden"; + } + return result; + } +private: + sortCriterion howToSort; +}; + +int main() +{ + Compare< int > absolute( Compare< int >::absoluteValue ); + SortedList< int > sortedList, sortedListAbsolute( absolute ); + std::ostream_iterator< int > output( cout, "\t" ); + + cout << "Werte mit verschiedenen Vorzeichen einfuegen:\n"; + for( int i = 0; i < 7; ++i ) { + int value = int( 100.0 * sin( static_cast< float >( i ) ) ); + cout << *sortedList.insert( value ) << endl; + sortedListAbsolute.insert( value ); + } + + cout << "\nincreasing sortiert( default ):\n"; + std::copy( sortedList.begin(), sortedList.end(), output ); + + cout << "\n\nnach Absolutbetrag sortiert:\n"; + std::copy( sortedListAbsolute.begin(), sortedListAbsolute.end(), output ); + + cout << "\n\nWert 90 finden" << endl; + SortedList< int >::Iterator search = sortedList.find( 90 ); + if( search == sortedList.end() ) + cout << "nicht gefunden\n"; + else + cout << *search << " gefunden" << endl; + + cout << "\nWert 91 finden" << endl; + search = sortedList.find( 91 ); + if( search == sortedList.end() ) + cout << "nicht gefunden\n\n"; + else + cout << *search << " gefunden" << endl << endl; + + return 0; +} + + diff --git a/Bachelor/Prog2/SortedList2/SortedList.h b/Bachelor/Prog2/SortedList2/SortedList.h new file mode 100644 index 0000000..300bd74 --- /dev/null +++ b/Bachelor/Prog2/SortedList2/SortedList.h @@ -0,0 +1,63 @@ +// Template for sorted list +// Author: U.Breymann / H.P.Weber +// Date: 05.05.05 + +#ifndef SORTEDLIST_H +#define SORTEDLIST_H + +#include +#include // find + +#include "compare.h" + +template< class T > +class SortedList +{ +public: + typedef std::list< T >::iterator Iterator; + typedef std::list< T >::const_iterator ConstIterator; + SortedList( const Compare< T >& cmp = Compare< T >() ) : comp( cmp ) { } + virtual ~SortedList() { } + + bool empty() const { return myList.empty(); } + int size() const { return myList.size(); } + + // take first or last element + void pop_front() { myList.pop_front(); } + void pop_back() { myList.pop_back(); } + + // read first or last element + T& front() { return myList.front(); } + const T& front() const { return myList.front(); } + T& back() { return myList.back(); } + const T& back() const { return myList.back(); } + + Iterator begin() { return myList.begin(); } + ConstIterator begin() const { return myList.begin(); } + Iterator end() { return myList.end(); } + ConstIterator end() const { return myList.end(); } + + void erase( Iterator& pos ) { myList.erase( pos ); } + + // find element + Iterator find( const T& value ) + { + return std::find( myList.begin(), myList.end(), value ); + } + + // sorted insert + Iterator insert( const T& value ) + { + // find place to insert + Iterator temp( begin() ); + while( temp != end() && comp( *temp, value ) ) ++temp; + return myList.insert( temp, value ); + } + +private: + std::list< T > myList; + Compare< T > comp; +}; + +#endif + diff --git a/Bachelor/Prog2/Stack/Tst_test.cpp b/Bachelor/Prog2/Stack/Tst_test.cpp new file mode 100644 index 0000000..5e9e9f8 --- /dev/null +++ b/Bachelor/Prog2/Stack/Tst_test.cpp @@ -0,0 +1,50 @@ +// Test driver for Stack template. +// Function main uses a function template to manipulate objects of type Stack< T >. +// Modification: use non-type parameter 'elements' in Stack-template + +#include +using std::cout; +using std::cin; +using std::endl; + +#include +using std::string; + +#include "tstack1.h" + +// Function template to manipulate Stack< T > +template< class T, int elements > +void testStack( + Stack< T, elements > &theStack, // reference to the Stack< T > + T value, // initial value to be pushed + T increment, // increment for subsequent values + const char *stackName ) // name of the Stack < T > object +{ + cout << "\nPushing elements onto " << stackName << '\n'; + + while ( theStack.push( value ) ) { // success true returned + cout << value << ' '; + value += increment; + } + + cout << "\nStack is full. Cannot push " << value + << "\n\nPopping elements from " << stackName << '\n'; + + while ( theStack.pop( value ) ) // success true returned + cout << value << ' '; + + cout << "\nStack is empty. Cannot pop\n"; +} + +int main() +{ + Stack< double, 5 > doubleStack; + Stack< int, 10 > intStack; + Stack< string, 5 > stringStack; + + testStack( doubleStack, 1.1, 1.1, "doubleStack" ); + testStack( intStack, 1, 1, "intStack" ); + testStack( stringStack, string("Eins"), string("UndEins"), "stringStack" ); + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog2/Stack/Tstack1.h b/Bachelor/Prog2/Stack/Tstack1.h new file mode 100644 index 0000000..8cbc5d5 --- /dev/null +++ b/Bachelor/Prog2/Stack/Tstack1.h @@ -0,0 +1,53 @@ +// tstack1.h +// Class template Stack + +#ifndef TSTACK1_H +#define TSTACK1_H + +template< class T, int elements > // # of elements in the stack +class Stack { +public: + Stack(); // default constructor + // ~Stack() { delete [] stackPtr; } // destructor (only for dynamic version) + bool push( const T& ); // push an element onto the stack + bool pop( T& ); // pop an element off the stack +private: + int top; // location of the top element + T stackHolder[elements]; // static array for stack + // T *stackPtr; // pointer to the stack (only for dynamic version) + bool isEmpty() const { return top == -1; } // utility + bool isFull() const { return top == elements - 1; } // functions +}; + +// Constructor with default size 10 +template< class T, int elements > +Stack< T, elements>::Stack() +{ + top = -1; // Stack is initially empty + // stackPtr = new T[ elements ]; // dynamically allocate space for elements (not used) +} + +// Push an element onto the stack +// return 1 if successful, 0 otherwise +template< class T, int elements > +bool Stack< T, elements >::push( const T &pushValue ) +{ + if ( !isFull() ) { + stackHolder[ ++top ] = pushValue; // place item in Stack + return true; // push successful + } + return false; // push unsuccessful +} + +// Pop an element off the stack +template< class T, int elements > +bool Stack< T, elements >::pop( T &popValue ) +{ + if ( !isEmpty() ) { + popValue = stackHolder[ top-- ]; // remove item from Stack + return true; // pop successful + } + return false; // pop unsuccessful +} + +#endif \ No newline at end of file diff --git a/Bachelor/Prog2/Studenten/StudDat.cpp b/Bachelor/Prog2/Studenten/StudDat.cpp new file mode 100644 index 0000000..12f0199 --- /dev/null +++ b/Bachelor/Prog2/Studenten/StudDat.cpp @@ -0,0 +1,35 @@ +// Persistence of objects: Storing of Student-Objects +// Author: Hans-Peter Weber +// Date: 07.03.05 + +#include +using std::cout; +using std::endl; +using std::ios; + +#include +using std::fstream; + +#include "Student.h" + +int main() +{ + Student stud; + + cout << "Adresse von Student-Objekt: " << &stud << endl; + cout << "Groesse von Student-Objekt: " << sizeof( Student ) << " Byte" << endl; + +/* fstream outFile( "Studs.seq", ios::binary | ios::out ); // write + stud.set( "Hans Castorp", 578111, 23 ); + stud.write( outFile ); + stud.set( "Claudia Chauchat", 578666, 27 ); + stud.write( outFile ); + outFile.close(); +*/ + fstream inFile( "Studs.seq", ios::binary | ios::in ); // read + while( stud.read( inFile ) ) + stud.print(); + inFile.close(); + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog2/Studenten/Student.cpp b/Bachelor/Prog2/Studenten/Student.cpp new file mode 100644 index 0000000..d8f0b00 --- /dev/null +++ b/Bachelor/Prog2/Studenten/Student.cpp @@ -0,0 +1,49 @@ +// Student.cpp: Implementation of class Student. + +#include +using std::cout; +using std::endl; +using std::istream; +using std::ostream; + +#include +using std::string; +using std::getline; + +#include "Student.h" + +Student::Student() +{ +} + +Student::~Student() +{ +} + +void Student::set( string n, int m, int a ) +{ + name = n; + matNr = m; + age = a; +} + +void Student::print() +{ + cout << name << ", Matrikelnummer: " << matNr << ", Alter: " << age << endl; +} + +ostream& Student::write( std::ostream& os ) const +{ +// os.write( ( char* )&matNr, sizeof matNr ); // stores '578111' as an int in 4 Bytes +// os << matNr; // stores '578111' as ASCII-Code in 6 Bytes! + os << name << '\0'; // write string + os.write( ( char* ) &matNr, 2 * sizeof( int ) ); // write 2 int starting at address of matNr + return os; +} + +istream& Student::read( std::istream& is ) +{ + getline( is, name, '\0' ); // read string + is.read( ( char* ) &matNr, 2 * sizeof( int ) ); // read 2 int starting at address of matNr + return is; +} \ No newline at end of file diff --git a/Bachelor/Prog2/Studenten/Student.h b/Bachelor/Prog2/Studenten/Student.h new file mode 100644 index 0000000..55d1e85 --- /dev/null +++ b/Bachelor/Prog2/Studenten/Student.h @@ -0,0 +1,26 @@ +// Student.h: Interface for class Student. + +#if !defined STUDENT_H +#define STUDENT_H + +#include + +class Student +{ + +public: + Student(); + ~Student(); + void set( std::string, int, int ); + void print(); + std::ostream& write( std::ostream& ) const; + std::istream& read( std::istream& ); + +private: + std::string name; + int matNr; + int age; + +}; + +#endif 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 +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 +using std::string; +using std::stringstream; +using std::ostream; + +#include // 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 +using std::string; +using std::stringstream; +using std::ostream; + +#include +using std::cout; +using std::endl; +using std::cin; + +#include // 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 +using std::cout; +using std::endl; +using std::cin; +using std::left; + +#include +#include // 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 +using std::string; +using std::stringstream; +using std::ostream; + +#include +using std::cout; +using std::endl; +using std::cin; + +#include // 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 +#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 +using std::string; +using std::stringstream; +using std::ostream; + +#include +using std::cout; +using std::endl; +using std::cin; + +#include // 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 +using std::cerr; +using std::left; + +#include // exit() +#include // 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 @@ + + + + + + + Klausur SS 04 + + +  + + + + + + + + +
FH Darmstadt  +
FB Informatik +

Prof.Dr.H.P.Weber

+

+

Programmieren II
+
+
Übung
+
+
+

    Juni 2005

+
+
+ +
+ + + + + +
Es soll die folgende Klassenhierarchie für zweidimensionale Figuren +implementiert werden:
+ Abstrakte Basisklasse Shape, davon direkt abgeleitet die + Klassen +Polyline und Ellipse. Von +Polyline direkt abgeleitet die Klassen Line + und Polygon und zusätzlich von Polygon + abgeleitet die Klasse Rectangle. Außerdem von Ellipse + abgeleitet die Klasse Circle.
+ +
+ + + + + +
Teil 1:
+ +

Zunächst werden nur die grundlegenden Klassen Shape und +Polyline entwickelt und getestet. Da die Klassen der Shape-Hierarchie +mit Punkten arbeiten, wird zur Darstellung eines Punktes auch eine Klasse +Point definiert:

+
    +
  • +Die Klasse Point besitzt die public-Elemente +x und y vom Typ double und einen +entsprechenden Konstruktor mit zwei Parametern, die beide den Default-Wert + 0.0 haben.
    +Die Methode distance 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)2 + (y2 - y1)2 . +
    +Die Methode toString liefert den Punkt als String in der Form +(x, y).
    +Der Operator *= multipliziert den Punkt mit einer +Gleitpunktzahl.
    +Außerdem werden die folgenden globalen Operationen bereitgestellt:
    + + und -        +Liefert die Summe bzw. Differenz zweier Punkte.
    + == und !=    Vergleicht zwei +Punkte.
    + <<               +Gibt einen Punkt auf einen Stream aus.
  • +
  • +Die Shape-Klasse enthält ein Attribut anchor (Anker, +Bezugspunkt), das die Lage der Figur festlegt. Durch Verschiebung des Ankers +wird also die gesamte Figur verschoben. Der Anker wird in der Shape-Klasse +als protected-Element gespeichert. Der Konstruktor +initialisiert den Anker mit dem als Argument übergebenen Punkt oder mit dem +Default-Wert Point(0,0). Zugriffsmethoden erlauben das Lesen und +Setzen des Ankers. Die Verschiebung erfolgt mit der Methode move, +die zwei Parameter für die Verschiebung in x- und y-Richtung besitzt.
  • + +
  • +Die Klasse Shape ist eine abstrakte Klasse. Neben dem virtuellen +Destruktor stellt sie das folgende polymorphe Interface bereit: Die Methode toString +liefert die Daten einer Figur als String. Für die Klasse Shape +sind das die Koordinaten des Ankers. Außerdem enthält Shape +die rein virtuellen Methoden scale und draw. scale +verkleinert oder vergrößert die Figur um einen Faktor, der als Argumnet +übergeben wird. Die Methode draw wird zum Zeichnen einer Figur +bereitgestellt, aber nicht genutzt (d.h. leer implementiert).
  • + +
  • +Die Klasse Polyline 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 Polyline zwei Datenelemente: Ein dynamisches Element, +nämlich einen Zeiger auf das Array mit Point-Elementen, und +eine Variable für die Anzahl der Linien. Definieren Sie verschiedene +Konstruktoren: Einen Default-Konstruktor, einen Konstruktor mit einem Point-Parameter +zur Festlegung des Ankers, einen Konstruktor mit zwei Point-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 0, 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 Polyline ein dynamisches +Element besitzt müssen auch Kopierkonstruktor und Zuweisungsoperator definiert +werden.
  • + +
  • +Redefinieren Sie für die Klasse Polyline alle rein virtuellen +Methoden der Klasse Shape und die Methode toString, 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.
  • + +
  • + +Überladen Sie schließlich zweimal den operator+=: Ist das +Argument ein Punkt, soll eine weitere Linie zu diesem Punkt angehängt werden. +Ist das Argument ein Polyline-Objekt, soll dessen gesamter +Linienzug an den letzten Punkt angehängt werden. +
      +
    • +Wenn eine Linie angehängt wird, muss das Array mit den Endpunkten vergrößert +werden. +
    • +
    • +Zu den relativen Koordinaten des anzuhängenden Linienzugs müssen die relativen +Koordinaten des letzten Punktes addiert werde. +
    • +
    +Testen Sie die Klasse Polyline, 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.
  • + +
+ + + + + +
Teil 2:
+ +

Ergänzen Sie die Shape-Klassenhierarchie um die noch +fehlenden Klassen Line, Polygon, Rectangle, +Ellipse und Circle:

+
    +
  • +Die Klasse Line besitzt mindestens zwei Konstruktoren: Die +Endpunkte einer Linie sollen als zwei Point-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!
  • +
  • +Ein Polygon 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:
  • +
  • +Die Klasse Rectangle 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.
  • + +
  • +Definieren Sie schließlich die Klassen Ellipse und Circle. +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 scale +und toString redefiniert werden.
  • + +
  • +Ein Kreis ist eine Ellipse, deren Halbachsen gleich lang sind und den Radius des +Kreises bilden. Außer einem Konstruktor soll die Klasse Circle +zusätzlich die Methoden getRadius und setRadius +bereitstellen. Auch ist die Methode toString zu redefinieren.
  • + +
  • + +Erweitern Sie das Anwendungsprogramm aus Teil 1 so, dass auch die neuen Klassen +getestet werden. +
  • + +
+ + + + + + +
Teil 3:
+ +

Die Figuren eines 'Bildes' bestehend aus Objekten der Shape-Hierarchie +werden in einer verketteten Liste verwaltet und in der Reihenfolge 'gezeichnet', +wie sie in der Liste vorkommen. Dazu soll std::list aus der STL +verwendet werden:

+ +
    +
  • +Zur Realisierung einer inhomogenen Liste werden nicht die Objekte selbst sondern +Shape-Zeiger in der Liste gespeichert. Dem Listentyp soll +daher der Name ShapePtrList mittels typedef +zugewiesen werden. Danach können Objekte dieses Typs angelegt und die in std::list +vorhandenen Methoden aufgerufen werden, z.B. wird mit push_back +ein Shape* auf ein zuvor erzeugtes Objekt der Shape-Hierarchie +an die Liste angehängt.
  • +
  • +Schreiben Sie ein Anwendungsprogramm, das Zeiger auf verschiedene Objekte der Shape-Hierarchie +in eine Liste vom Typ ShapePtrList einfügt. Die Objekte sollen +mit new dynamisch erzeugt werden. Geben Sie die Shape-Objekte +der Liste aus. Löschen Sie dann einige Elemente und zeigen Sie die Liste erneut +an. Schreiben Sie zur Ausgabe der Shape-Objekte eine globale +Funktion printShapeList, die als Argument eine Referenz auf die +Liste erhält und mithilfe der Methoden toString +die Shape-Objekte der Liste anzeigt. Geben Sie zusätzlich mit +dem Operator typeid auch den Typ der Objekte +aus.
  • +
+ + + + + +
Teil 4:
+ +

Die Klasse ShapePtrList wird noch in zwei Schritten +verbessert:

+ +
    +
  • +Bisher speichert jedes Listenelement einen einfachen Shape-Zeiger. +Deshalb wird beim Löschen eines Listenelements nur der Zeiger nicht aber das Shape-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:
  • +
      +
    • +Ergänzen Sie zuerst die Shape-Klasse durch eine rein virtuelle +Methode clone. Diese Methode muss in jeder abgeleiteten Klasse +redefiniert werden, indem sie eine dynamisch erzeugte Kopie des aktuellen +Objekts zurückgibt.
    • +
    • +Definieren Sie dann die Klasse ShapePtr zur Darstellung eines +intelligenten Zeigers auf Shape-Objekte. Als Attribut besitzt +die Klasse einen Shape-Zeiger, der vom Konstruktor mit dem +Parameter vom Typ Shape* bzw. dem Default-Wert 0 initialisiert +wird. Außerdem muss ein eigener Kopierkonstruktor definiert werden. Dieser +erzeugt zunächst mithilfe der Methode clone eine Kopie des Shape-Objekts +und läßt den Shape-Zeiger auf diese Kopie zeigen. Der +Destruktor zerstört das Shape-Objekt, auf das der Zeiger +verweist. Der Zuweisungsoperator wird zweifach überladen, so dass sowohl ein +anderes ShapePtr-Objekt als auch ein einfacher Shape-Zeiger +zugewiesen werden kann. In beiden Fällen wird das aktuelle Shape-Objekt +zerstört und der Zeiger auf eine Kopie des Shape-Objekts +gesetzt, auf das der übergebene Zeiger verweist. Die Operatoren * +und -> sind so zu überladen, dass ein ShapePtr-Objekt +wie ein gewöhnlicher Zeiger verwendet werden kann. Der +Dereferenzierungsoperator liefert eine Referenz auf das adressierte Shape-Objekt +und der Pfeiloperator liefert den Shape-Zeiger selbst. +Schließlich soll auch eine Konvertierung eines ShapePtr-Objekts +in einen Shape-Zeiger möglich sein. Fügen Sie deshalb noch die +entsprechende Konvertierungsfunktion hinzu.
    • +
    +Die Definition der Liste mit Zeiger auf Shape-Objekte lautet nun +wie folgt:
    +typedef List< ShapePtr > ShapePtrList;
    +
    Stellen Sie die Definitionen der Klassen ShapePtr und ShapePtrList +in eine neue Header-Datei ShapeList.h. Verwenden Sie zum Testen +die Funktionen main und printShapeList aus Teil +3. Diese sollten unverändert mit der neuen Definition der Liste lauffähig +sein. +
  • +Um die Klasse ShapePtrList mit eigenen Methoden erweitern zu +können, wird jetzt die Klasse ShapePtrList von der +Standardklasse std::list abgeleitet:
    +class ShapePtrList : public list< ShapePtr >
    +
    Ergänzen Sie die Klasse ShapePtrList durch die +Methoden scale und toString. Die Methode scale +verkleinert oder vergrößert jede Figur der Liste um einen Faktor, der als +Argument übergeben wird. Die Methode toString 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 toString-Methode für die jeweilige +Figur. +
  • +
+Testen Sie die verbesserte Klasse + ShapePtrList. Ändern Sie die  main-Funktion +aus Teil 3 wie folgt: Entfernen Sie die globale Funktion printShapeList +und verwenden Sie zur Ausgabe der Liste die Methode toString. +Erzeugen Sie eine Kopie der Liste und modifizieren Sie die Figuren der neuen +Liste durch einen Aufruf der Methode scale. 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  machen, +indem Sie im virtuellen Destruktor der Klasse Shape eine +Meldung ausgeben. +
+ + + + + +
+
+Quelle: Prinz / Kirch-Prinz: C++ Das Übungsbuch +
+
+ + \ 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 Binary files /dev/null and b/Bachelor/Prog2/Z-Uebung/Z_Ueb.zip 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> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog2/map/map.cpp b/Bachelor/Prog2/map/map.cpp new file mode 100644 index 0000000..c140a88 --- /dev/null +++ b/Bachelor/Prog2/map/map.cpp @@ -0,0 +1,65 @@ +// Praktikum 4.1 using an associative container (std::map) +// Author: Hans-Peter Weber +// Date: 20.02.04 + +#pragma warning( disable: 4786 ) + +#include +using std::cout; +using std::cerr; +using std::endl; +using std::ios; + +#include +using std::string; + +#include +using std::ifstream; +using std::ofstream; + +#include + +int main() +{ + typedef std::map< string, int > stringMap; + stringMap words; + string s; + int numberOfWords = 0; + + ifstream in( "Max.txt" ); + if( !in ) { + cerr << "Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + +// fill map 'words' with all words contained in file (implicitly sorted) and their frequencies + while( in >> s ) { + ++words[ s ]; + numberOfWords++; + } + + in.close(); + +// store words and frequencies in text file + ofstream out( "WordList.txt", ios::app ); + if( !out ) { + cerr << "Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + string mapElement; + + for( stringMap::const_iterator wordIterator = words.begin(); + wordIterator != words.end(); ++wordIterator ) { + mapElement = wordIterator->first; + mapElement.resize( 20, '.' ); +// cout << mapElement << wordIterator->second << endl; + out << mapElement << wordIterator->second << endl; + } + + out.close(); + + cout << "Woerter in der Datei: " << numberOfWords << endl + << "unterschiedliche Woerter: " << words.size() << endl << endl; + + return 0; +} diff --git a/Bachelor/Prog2/person-tree/Person.cpp b/Bachelor/Prog2/person-tree/Person.cpp new file mode 100644 index 0000000..f1e5206 --- /dev/null +++ b/Bachelor/Prog2/person-tree/Person.cpp @@ -0,0 +1,31 @@ +// Person.cpp: Implementation of class Person + +#include +using std::cout; +using std::endl; +using std::ostream; + +#include +using std::string; + +#include "Person.h" + +Person::Person( string last, string first ) +{ + lastName = last; + firstName = first; +} + +bool Person::operator<( const Person& p ) const +{ + return lastName < p.lastName || + ( lastName == p.lastName && + firstName < p.firstName ); +} + +ostream& operator<<( ostream& output, const Person& p ) +{ + cout << p.lastName << ", " << p.firstName << endl; + + return output; +} \ No newline at end of file diff --git a/Bachelor/Prog2/person-tree/Person.h b/Bachelor/Prog2/person-tree/Person.h new file mode 100644 index 0000000..a840996 --- /dev/null +++ b/Bachelor/Prog2/person-tree/Person.h @@ -0,0 +1,27 @@ +// Person.h: Interface for class Person + +#if !defined PERSON_H +#define PERSON_H + +#include +#include + +class Person { + + friend std::ostream& operator<<( std::ostream&, const Person& ); + +public: + Person( std::string = "", std::string = "" ); // default constructor + bool operator<( const Person& ) const; + bool operator>( const Person& right ) const + { + return right < *this; + } + +private: + std::string firstName; + std::string lastName; + +}; + +#endif // !defined PERSON_H diff --git a/Bachelor/Prog2/person-tree/Prs_test.cpp b/Bachelor/Prog2/person-tree/Prs_test.cpp new file mode 100644 index 0000000..91e6b70 --- /dev/null +++ b/Bachelor/Prog2/person-tree/Prs_test.cpp @@ -0,0 +1,68 @@ +// Tree with Person objects +// Author: Hans-Peter Weber +// Date: 08.05.04 + +#include +using std::cout; +using std::cerr; +using std::cin; +using std::endl; + +#include +using std::ofstream; +using std::ifstream; +using std::ios; + +#include +using std::string; + +#include + +#include "tree.h" +#include "person.h" + +int main() +{ + Tree< Person > personTree; + int fileOrConsole; + string lastName, firstName; + + cout << "Neue Namen eingeben(1) oder vorhandene Datei nutzen(2): "; + cin >> fileOrConsole;; + + if( fileOrConsole == 1 ) { + cout << "Name, Vorname eingeben" << endl + << "(Beenden mit 'Strg z'): "; + + ofstream out( "Daten.txt", ios::app ); + + if( !out ) { + cerr << "Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + + while( cin >> lastName >> firstName ) { + out << lastName << " " << firstName << endl; + personTree.insertNode( *( new Person( lastName, firstName ) ) ); + cout << "Eingeben: "; + } + } + else { + ifstream in( "Daten.txt", ios::in ); + + if( !in ) { + cerr << "Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + + while( in >> lastName >> firstName ) { + personTree.insertNode( *( new Person( lastName, firstName ) ) ); + } + } + + cout << "\nInorder traversal\n\n"; + personTree.inOrderTraversal(); + cout << endl << endl; + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog2/person-tree/Tree.h b/Bachelor/Prog2/person-tree/Tree.h new file mode 100644 index 0000000..c1da451 --- /dev/null +++ b/Bachelor/Prog2/person-tree/Tree.h @@ -0,0 +1,130 @@ +// Fig. 15.16: tree.h +// Definition of template class Tree + +#ifndef TREE_H +#define TREE_H + +#include +using std::cout; +using std::endl; +using std::ostream; +#include + +#include + +#include +using std::ofstream; +using std::ifstream; +using std::ios; + +#include "Treenode.h" + +template< class NODETYPE > +class Tree { +public: + Tree(); + void insertNode( const NODETYPE & ); + void preOrderTraversal() const; + void inOrderTraversal() const; + void postOrderTraversal() const; + int gettreeElementCount(); +private: + TreeNode< NODETYPE > *rootPtr; + int treeElementCount; + + // utility functions + void insertNodeHelper( + TreeNode< NODETYPE > **, const NODETYPE & ); + void preOrderHelper( TreeNode< NODETYPE > * ) const; + void inOrderHelper( TreeNode< NODETYPE > * ) const; + void postOrderHelper( TreeNode< NODETYPE > * ) const; +}; + +template< class NODETYPE > +Tree< NODETYPE >::Tree() { rootPtr = 0; treeElementCount=0; } + +template< class NODETYPE > +void Tree< NODETYPE >::insertNode( const NODETYPE &value ) + { insertNodeHelper( &rootPtr, value ); } + +// This function receives a pointer to a pointer so the +// pointer can be modified. +template< class NODETYPE > +void Tree< NODETYPE >::insertNodeHelper( + TreeNode< NODETYPE > **ptr, const NODETYPE &value ) +{ + if ( *ptr == 0 ) { // tree is empty + *ptr = new TreeNode< NODETYPE >( value ); + (*ptr)->frequency++; + ++treeElementCount; + assert( *ptr != 0 ); + } + else // tree is not empty + if ( value < ( *ptr )->data ) + insertNodeHelper( &( ( *ptr )->leftPtr ), value ); + else + if ( value > ( *ptr )->data ) + insertNodeHelper( &( ( *ptr )->rightPtr ), value ); + else + (*ptr)->frequency++; +} + +template< class NODETYPE > +void Tree< NODETYPE >::preOrderTraversal() const + { preOrderHelper( rootPtr ); } + +template< class NODETYPE > +void Tree< NODETYPE >::preOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + if ( ptr != 0 ) { + cout << ptr->data << ' '; + preOrderHelper( ptr->leftPtr ); + preOrderHelper( ptr->rightPtr ); + } +} + +template< class NODETYPE > +void Tree< NODETYPE >::inOrderTraversal() const + { inOrderHelper( rootPtr ); } + +template< class NODETYPE > +void Tree< NODETYPE >::inOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + ofstream outFile("output.txt",ios::app); + if( !outFile ) { + cerr << "Output-Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + if ( ptr != 0 ) { + inOrderHelper( ptr->leftPtr ); + outFile << std::setw(30) << std::left << std::setfill('.') << ptr->data + << ptr->frequency << endl; + inOrderHelper( ptr->rightPtr ); + } + outFile.close(); +} + +template< class NODETYPE > +void Tree< NODETYPE >::postOrderTraversal() const + { postOrderHelper( rootPtr ); } + +template< class NODETYPE > +void Tree< NODETYPE >::postOrderHelper( + TreeNode< NODETYPE > *ptr ) const +{ + if ( ptr != 0 ) { + postOrderHelper( ptr->leftPtr ); + postOrderHelper( ptr->rightPtr ); + cout << ptr->data << ' '; + } +} + +template +int Tree::gettreeElementCount() +{ + return treeElementCount; +} + +#endif diff --git a/Bachelor/Prog2/person-tree/Treenode.h b/Bachelor/Prog2/person-tree/Treenode.h new file mode 100644 index 0000000..4a2b1f1 --- /dev/null +++ b/Bachelor/Prog2/person-tree/Treenode.h @@ -0,0 +1,24 @@ +// Fig. 15.16: treenode.h +// Definition of class TreeNode + +#ifndef TREENODE_H +#define TREENODE_H + +template< class NODETYPE > class Tree; // forward declaration + +template< class NODETYPE > +class TreeNode { + friend class Tree< NODETYPE >; +public: + TreeNode( const NODETYPE &d ) + : leftPtr( 0 ), data( d ), rightPtr( 0 ) { } + NODETYPE getData() const { return data; } + int getFreq() const { return frequency; } +private: + TreeNode< NODETYPE > *leftPtr; // pointer to left subtree + NODETYPE data; + int frequency; + TreeNode< NODETYPE > *rightPtr; // pointer to right subtree +}; + +#endif diff --git a/Bachelor/Prog2/person-tree/main.cpp b/Bachelor/Prog2/person-tree/main.cpp new file mode 100644 index 0000000..c44a7ba --- /dev/null +++ b/Bachelor/Prog2/person-tree/main.cpp @@ -0,0 +1,47 @@ +// Tree with string objects +// Author: Sven Eisenhauer +// Date: 05.06.05 + +#include +using std::cout; +using std::cerr; +using std::cin; +using std::endl; + +#include +using std::ofstream; +using std::ifstream; +using std::ios; + +#include +using std::string; + +#include +#include + +#include "Tree.h" + +int main() +{ + int wordsInFile=0; + Tree< string > wordTree; + string word; + + ifstream inFile( "max.txt", ios::in ); + + if( !inFile ) { + cerr << "Input-Datei konnte nicht geoeffnet werden." << endl; + exit( 1 ); + } + + while( inFile >> word) { + wordTree.insertNode( *( new string( word ) ) ); + wordsInFile++; + } + + wordTree.inOrderTraversal(); + cout << "Words in input file: "<< wordsInFile << endl; + cout << "Different words: " << wordTree.gettreeElementCount() << endl; + + return 0; +} diff --git a/Bachelor/Prog2/person-tree/max.txt b/Bachelor/Prog2/person-tree/max.txt new file mode 100644 index 0000000..f6cd84a --- /dev/null +++ b/Bachelor/Prog2/person-tree/max.txt @@ -0,0 +1,67 @@ +Maonche held im Stall sisch Hinggel, +fittert se mit Waas un Dinggel +un mit Kleie - dodewäije, +dass se schaeine Aaije laeije. +Sundaogs hot me daonn im Dippche, +alsemol e Hinggelsippche, +un die Färren, zaart un foi, +stobbt me in die Pilwe noi, +daonn im Winde leit me haolt +liewe waarm im Bett wie kaolt +Sou waar sellemols des aa +bei dem Bolde soine Fraa: +Hinggel hatt se Sticke drei +un en Gickel noch debei. +Säigt de Max zum Moritz kaolt: +"Kumm, mer äijen jetz die Aolt!" - +-Hordisch nemme se e Broud, +schneires mirrem Messe noud +in vier Sticke, gaar nit grouß, +wie en klaone Finge blouß. + +Jede Mumbel werd vun unne +iwwes Kreiz daonn feschdgebunne, +un die läije se genaa +in de Houf vun sellre Fraa. - +Wie de Giggel guckt do druff, +sperrt e glei de Schnawwel uff, +kreeht un kreischt gickerigie, +un die Hinggel renne hie. + +Jede schlickt soin Brogge nunne- +äwwe daon, das is kao Wunne, +henggt des ao aom aonnen drou +un fengt glei ze ziehe ou. + +Riwwe, niwwe, hie un her +renne se die Kreiz un Quer, +gacken, fladden in die Häih - +äwwe lous kimmt kaone mäih! + +Aome laonge derre Ascht +hengge se, verstrumbt schun fascht; +mirrem Hals sou laong wie Mosse +misse se eer Läwe losse. +E letscht Aig noch - des is alles, +un daonn häwwe se de Dalles! + +De aold Bolden in de Stobb +häijet waos un häibt de Kobb. +Un schun sterzt se aus de Kaomme - +ach, waos is des fer en Jaomme! + + +"Ich arrm Witfraa bin geschlaoe - +issch kaonn´s jao kaom Mensche saoe! +Drowwe uffm Ebbelboam +henggt moin alleschäinschte Draom!" +Gaons vesteert un halwe kraonk +helt se´s Messe aus em Schaonk +schneid die Hinggel aob vum Ascht +groint sisch aus die Aache fascht, +dabbt ins Haus im diefschte Schmerz, +drickt des Veehzeig aon eer Herz. +Is de erschte Straasch vebei, +kimmt de zwatte siche glei. + +Quelle: Elisabeth Kunz: De Ourewälle Max un Moritz Odenwald-Verlag 2. Auflage 1996 \ No newline at end of file -- cgit v1.2.3