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/Prog1/Ascii_Table.htm | 197 +++++++++ Bachelor/Prog1/Codierungsstandard.htm | 319 +++++++++++++++ Bachelor/Prog1/Folien/chapter01.ppt | Bin 0 -> 201728 bytes Bachelor/Prog1/Folien/chapter02.ppt | Bin 0 -> 232448 bytes Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt | Bin 0 -> 251904 bytes Bachelor/Prog1/Folien/chapter03.ppt | Bin 0 -> 425984 bytes Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt | Bin 0 -> 194048 bytes Bachelor/Prog1/Folien/chapter04.ppt | Bin 0 -> 362496 bytes Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt | Bin 0 -> 100864 bytes Bachelor/Prog1/Folien/chapter05.ppt | Bin 0 -> 311296 bytes Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt | Bin 0 -> 73216 bytes Bachelor/Prog1/Folien/chapter06.ppt | Bin 0 -> 406528 bytes Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt | Bin 0 -> 230400 bytes Bachelor/Prog1/Folien/chapter07.ppt | Bin 0 -> 532480 bytes Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt | Bin 0 -> 768000 bytes Bachelor/Prog1/Folien/chapter08.ppt | Bin 0 -> 586752 bytes Bachelor/Prog1/Hinweise.pdf | Bin 0 -> 40832 bytes .../Klausur 'Programmieren I' am 10.02.05.eml | 84 ++++ Bachelor/Prog1/Literatur.htm | 105 +++++ Bachelor/Prog1/Op_Prec.htm | 219 +++++++++++ Bachelor/Prog1/PG1Klaus.htm | 227 +++++++++++ Bachelor/Prog1/PG1_inh.htm | 120 ++++++ Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp | 23 ++ Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp | 100 +++++ Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsw | 29 ++ Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp | 22 ++ Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp | 100 +++++ Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsw | 29 ++ Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp | 50 +++ Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsp | 100 +++++ Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsw | 29 ++ Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp | 40 ++ Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp | 100 +++++ Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsw | 29 ++ Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp | 25 ++ Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp | 100 +++++ Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsw | 29 ++ Bachelor/Prog1/Prakt2/index.htm | 156 ++++++++ Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp | 77 ++++ Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp | 100 +++++ Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsw | 29 ++ Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp | 86 ++++ Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp | 100 +++++ Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsw | 29 ++ Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp | 31 ++ Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsp | 100 +++++ Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsw | 29 ++ Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp | 51 +++ Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp | 100 +++++ Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsw | 29 ++ Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp | 73 ++++ Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp | 100 +++++ Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsw | 29 ++ Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp | 59 +++ Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp | 100 +++++ Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsw | 29 ++ Bachelor/Prog1/Prakt3/index.htm | 197 +++++++++ Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp | 65 +++ Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp | 100 +++++ Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsw | 29 ++ Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp | 81 ++++ Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp | 100 +++++ Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsw | 29 ++ Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp | 57 +++ Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp | 100 +++++ Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsw | 29 ++ Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp | 43 ++ Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsp | 100 +++++ Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsw | 29 ++ Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp | 67 ++++ Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp | 100 +++++ Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsw | 29 ++ Bachelor/Prog1/Prakt4/index.htm | 253 ++++++++++++ Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp | 148 +++++++ Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp | 100 +++++ Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsw | 29 ++ Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp | 123 ++++++ Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp | 100 +++++ Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsw | 29 ++ Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp | 102 +++++ Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp | 100 +++++ Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw | 29 ++ Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp | 122 ++++++ Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp | 100 +++++ Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw | 29 ++ Bachelor/Prog1/Prakt5/index.htm | 414 +++++++++++++++++++ Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp | 124 ++++++ Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsp | 100 +++++ Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsw | 29 ++ Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp | 178 +++++++++ Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp | 100 +++++ Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsw | 29 ++ Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp | 128 ++++++ Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsp | 100 +++++ Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsw | 29 ++ Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp | 438 +++++++++++++++++++++ Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsp | 100 +++++ Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsw | 29 ++ Bachelor/Prog1/Prakt6.zip | Bin 0 -> 15652 bytes Bachelor/Prog1/Prakt6/index.htm | 249 ++++++++++++ Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp | 30 ++ Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h | 31 ++ Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp | 25 ++ Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h | 30 ++ Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp | 41 ++ Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp | 116 ++++++ Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsw | 29 ++ Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp | 15 + Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp | 108 +++++ Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsw | 29 ++ Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp | 385 ++++++++++++++++++ Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.h | 36 ++ Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h | 55 +++ Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp | 344 ++++++++++++++++ Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp | 74 ++++ Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp | 108 +++++ Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw | 29 ++ Bachelor/Prog1/Vorlesung.htm | 31 ++ Bachelor/Prog1/Vorlesung_files/style.css | 54 +++ Bachelor/Prog1/chap1_8.zip | Bin 0 -> 959766 bytes Bachelor/Prog1/ex1_8.zip | Bin 0 -> 183647 bytes Bachelor/Prog1/examples/ch01/Fig01_02.cpp | 30 ++ Bachelor/Prog1/examples/ch01/Fig01_04.cpp | 30 ++ Bachelor/Prog1/examples/ch01/Fig01_05.cpp | 29 ++ Bachelor/Prog1/examples/ch01/Fig01_06.cpp | 41 ++ Bachelor/Prog1/examples/ch01/Fig01_14.cpp | 58 +++ Bachelor/Prog1/examples/ch02/Ex02_05.cpp | 43 ++ Bachelor/Prog1/examples/ch02/Ex02_08.cpp | 55 +++ Bachelor/Prog1/examples/ch02/Ex02_15.cpp | 44 +++ Bachelor/Prog1/examples/ch02/Ex02_24.cpp | 39 ++ Bachelor/Prog1/examples/ch02/Ex02_25.cpp | 47 +++ Bachelor/Prog1/examples/ch02/Ex02_42.cpp | 47 +++ Bachelor/Prog1/examples/ch02/Fig02_07.cpp | 54 +++ Bachelor/Prog1/examples/ch02/Fig02_09.cpp | 76 ++++ Bachelor/Prog1/examples/ch02/Fig02_11.cpp | 64 +++ Bachelor/Prog1/examples/ch02/Fig02_14.cpp | 44 +++ Bachelor/Prog1/examples/ch02/Fig02_16.cpp | 38 ++ Bachelor/Prog1/examples/ch02/Fig02_17.cpp | 36 ++ Bachelor/Prog1/examples/ch02/Fig02_20.cpp | 38 ++ Bachelor/Prog1/examples/ch02/Fig02_21.cpp | 60 +++ Bachelor/Prog1/examples/ch02/Fig02_22.cpp | 95 +++++ Bachelor/Prog1/examples/ch02/Fig02_24.cpp | 39 ++ Bachelor/Prog1/examples/ch02/Fig02_26.cpp | 46 +++ Bachelor/Prog1/examples/ch02/Fig02_27.cpp | 45 +++ Bachelor/Prog1/examples/ch03/Ex03_02.cpp | 41 ++ Bachelor/Prog1/examples/ch03/Ex03_03.cpp | 67 ++++ Bachelor/Prog1/examples/ch03/Ex03_10.cpp | 53 +++ Bachelor/Prog1/examples/ch03/Ex03_49.cpp | 36 ++ Bachelor/Prog1/examples/ch03/Ex03_50.cpp | 51 +++ Bachelor/Prog1/examples/ch03/Fig03_03.cpp | 45 +++ Bachelor/Prog1/examples/ch03/Fig03_04.cpp | 60 +++ Bachelor/Prog1/examples/ch03/Fig03_07.cpp | 46 +++ Bachelor/Prog1/examples/ch03/Fig03_08.cpp | 89 +++++ Bachelor/Prog1/examples/ch03/Fig03_09.cpp | 54 +++ Bachelor/Prog1/examples/ch03/Fig03_10.cpp | 111 ++++++ Bachelor/Prog1/examples/ch03/Fig03_12.cpp | 96 +++++ Bachelor/Prog1/examples/ch03/Fig03_14.cpp | 52 +++ Bachelor/Prog1/examples/ch03/Fig03_15.cpp | 56 +++ Bachelor/Prog1/examples/ch03/Fig03_18.cpp | 50 +++ Bachelor/Prog1/examples/ch03/Fig03_19.cpp | 50 +++ Bachelor/Prog1/examples/ch03/Fig03_20.cpp | 61 +++ Bachelor/Prog1/examples/ch03/Fig03_21.cpp | 37 ++ Bachelor/Prog1/examples/ch03/Fig03_22.cpp | 35 ++ Bachelor/Prog1/examples/ch03/Fig03_23.cpp | 54 +++ Bachelor/Prog1/examples/ch03/Fig03_24.cpp | 44 +++ Bachelor/Prog1/examples/ch03/Fig03_25.cpp | 50 +++ Bachelor/Prog1/examples/ch03/Fig03_26.cpp | 50 +++ Bachelor/Prog1/examples/ch03/Fig03_27.cpp | 76 ++++ Bachelor/Prog1/examples/ch04/Ex04_18.cpp | 49 +++ Bachelor/Prog1/examples/ch04/Ex04_21.cpp | 47 +++ Bachelor/Prog1/examples/ch04/Fig04_03.cpp | 44 +++ Bachelor/Prog1/examples/ch04/Fig04_04.cpp | 42 ++ Bachelor/Prog1/examples/ch04/Fig04_05.cpp | 46 +++ Bachelor/Prog1/examples/ch04/Fig04_06.cpp | 35 ++ Bachelor/Prog1/examples/ch04/Fig04_07.cpp | 29 ++ Bachelor/Prog1/examples/ch04/Fig04_08.cpp | 41 ++ Bachelor/Prog1/examples/ch04/Fig04_09.cpp | 49 +++ Bachelor/Prog1/examples/ch04/Fig04_10.cpp | 53 +++ Bachelor/Prog1/examples/ch04/Fig04_11.cpp | 58 +++ Bachelor/Prog1/examples/ch04/Fig04_12.cpp | 49 +++ Bachelor/Prog1/examples/ch04/Fig04_13.cpp | 82 ++++ Bachelor/Prog1/examples/ch04/Fig04_14.cpp | 87 ++++ Bachelor/Prog1/examples/ch04/Fig04_15.cpp | 46 +++ Bachelor/Prog1/examples/ch04/Fig04_16.cpp | 65 +++ Bachelor/Prog1/examples/ch04/Fig04_17.cpp | 193 +++++++++ Bachelor/Prog1/examples/ch04/Fig04_19.cpp | 63 +++ Bachelor/Prog1/examples/ch04/Fig04_20.cpp | 142 +++++++ Bachelor/Prog1/examples/ch04/Fig04_22.cpp | 57 +++ Bachelor/Prog1/examples/ch04/Fig04_23.cpp | 134 +++++++ Bachelor/Prog1/examples/ch05/Ex05_21.cpp | 49 +++ Bachelor/Prog1/examples/ch05/Ex05_22.cpp | 48 +++ Bachelor/Prog1/examples/ch05/Ex05_30.cpp | 49 +++ Bachelor/Prog1/examples/ch05/Fig05_04.cpp | 43 ++ Bachelor/Prog1/examples/ch05/Fig05_06.cpp | 45 +++ Bachelor/Prog1/examples/ch05/Fig05_07.cpp | 46 +++ Bachelor/Prog1/examples/ch05/Fig05_10.cpp | 53 +++ Bachelor/Prog1/examples/ch05/Fig05_11.cpp | 45 +++ Bachelor/Prog1/examples/ch05/Fig05_12.cpp | 38 ++ Bachelor/Prog1/examples/ch05/Fig05_13.cpp | 34 ++ Bachelor/Prog1/examples/ch05/Fig05_14.cpp | 39 ++ Bachelor/Prog1/examples/ch05/Fig05_15.cpp | 77 ++++ Bachelor/Prog1/examples/ch05/Fig05_16.cpp | 45 +++ Bachelor/Prog1/examples/ch05/Fig05_17.cpp | 55 +++ Bachelor/Prog1/examples/ch05/Fig05_20.cpp | 60 +++ Bachelor/Prog1/examples/ch05/Fig05_21.cpp | 58 +++ Bachelor/Prog1/examples/ch05/Fig05_24.cpp | 103 +++++ Bachelor/Prog1/examples/ch05/Fig05_25.cpp | 115 ++++++ Bachelor/Prog1/examples/ch05/Fig05_26.cpp | 76 ++++ Bachelor/Prog1/examples/ch05/Fig05_28.cpp | 44 +++ Bachelor/Prog1/examples/ch05/Fig05_29.cpp | 50 +++ Bachelor/Prog1/examples/ch05/Fig05_30.cpp | 50 +++ Bachelor/Prog1/examples/ch05/Fig05_31.cpp | 47 +++ Bachelor/Prog1/examples/ch05/Fig05_32.cpp | 40 ++ Bachelor/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp | 82 ++++ Bachelor/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp | 114 ++++++ Bachelor/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp | 58 +++ .../Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp | 57 +++ Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.cpp | 65 +++ Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.h | 40 ++ Bachelor/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp | 38 ++ Bachelor/Prog1/examples/ch06/Fig06_08/Time1.cpp | 65 +++ Bachelor/Prog1/examples/ch06/Fig06_08/Time1.h | 40 ++ .../Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp | 32 ++ .../Prog1/examples/ch06/Fig06_09_11/Salesp.cpp | 86 ++++ Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.h | 36 ++ .../Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp | 63 +++ Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.cpp | 65 +++ Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.h | 40 ++ .../Prog1/examples/ch06/Fig06_15_17/Create.cpp | 47 +++ Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.h | 34 ++ .../Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp | 68 ++++ .../Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp | 82 ++++ Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.cpp | 107 +++++ Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.h | 50 +++ .../Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp | 53 +++ Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.cpp | 55 +++ Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.h | 40 ++ Bachelor/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp | 72 ++++ .../Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp | 42 ++ Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.cpp | 107 +++++ Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.h | 49 +++ Bachelor/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp | 75 ++++ Bachelor/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp | 74 ++++ Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.cpp | 85 ++++ Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.h | 39 ++ .../Prog1/examples/ch07/Fig07_06_10/Employee1.cpp | 72 ++++ .../Prog1/examples/ch07/Fig07_06_10/Employee1.h | 42 ++ .../Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp | 40 ++ Bachelor/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp | 72 ++++ Bachelor/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp | 65 +++ Bachelor/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp | 66 ++++ .../Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp | 48 +++ Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.cpp | 114 ++++++ Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.h | 51 +++ .../Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp | 55 +++ .../Prog1/examples/ch07/Fig07_17_19/employee2.cpp | 88 +++++ .../Prog1/examples/ch07/Fig07_17_19/employee2.h | 41 ++ .../Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp | 39 ++ .../examples/ch07/Fig07_20_23/implementation.h | 48 +++ .../Prog1/examples/ch07/Fig07_20_23/interface.cpp | 48 +++ .../Prog1/examples/ch07/Fig07_20_23/interface.h | 34 ++ Bachelor/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp | 89 +++++ .../Prog1/examples/ch08/Fig08_04_06/Array1.cpp | 177 +++++++++ Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.h | 61 +++ .../Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp | 90 +++++ .../Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp | 101 +++++ .../Prog1/examples/ch08/Fig08_07_09/String1.cpp | 221 +++++++++++ Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.h | 85 ++++ Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.cpp | 137 +++++++ Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.h | 49 +++ .../Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp | 54 +++ Bachelor/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp | 104 +++++ Bachelor/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp | 134 +++++++ .../Prog1/examples/ch08/Fig08_15_17/Complex1.cpp | 54 +++ .../Prog1/examples/ch08/Fig08_15_17/Complex1.h | 35 ++ .../Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp | 57 +++ .../Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp | 51 +++ .../Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp | 121 ++++++ .../Prog1/examples/ch08/Fig08_18_20/Hugeint1.h | 47 +++ .../Prog1/examples/elevator/ElevatorSimulation.cpp | 45 +++ Bachelor/Prog1/examples/elevator/bell.cpp | 44 +++ Bachelor/Prog1/examples/elevator/bell.h | 30 ++ Bachelor/Prog1/examples/elevator/building.cpp | 65 +++ Bachelor/Prog1/examples/elevator/building.h | 42 ++ Bachelor/Prog1/examples/elevator/clock.cpp | 52 +++ Bachelor/Prog1/examples/elevator/clock.h | 34 ++ Bachelor/Prog1/examples/elevator/door.cpp | 81 ++++ Bachelor/Prog1/examples/elevator/door.h | 40 ++ Bachelor/Prog1/examples/elevator/elevator.cpp | 231 +++++++++++ Bachelor/Prog1/examples/elevator/elevator.h | 75 ++++ .../Prog1/examples/elevator/elevatorButton.cpp | 57 +++ Bachelor/Prog1/examples/elevator/elevatorButton.h | 40 ++ Bachelor/Prog1/examples/elevator/floor.cpp | 98 +++++ Bachelor/Prog1/examples/elevator/floor.h | 63 +++ Bachelor/Prog1/examples/elevator/floorButton.cpp | 62 +++ Bachelor/Prog1/examples/elevator/floorButton.h | 42 ++ Bachelor/Prog1/examples/elevator/light.cpp | 65 +++ Bachelor/Prog1/examples/elevator/light.h | 36 ++ Bachelor/Prog1/examples/elevator/person.cpp | 91 +++++ Bachelor/Prog1/examples/elevator/person.h | 42 ++ Bachelor/Prog1/examples/elevator/scheduler.cpp | 134 +++++++ Bachelor/Prog1/examples/elevator/scheduler.h | 53 +++ Bachelor/Prog1/probeklausur/lotto.h | 25 ++ Bachelor/Prog1/probeklausur/lottogenerator.cpp | 89 +++++ Bachelor/Prog1/probeklausur/main.cpp | 67 ++++ 305 files changed, 20854 insertions(+) create mode 100644 Bachelor/Prog1/Ascii_Table.htm create mode 100644 Bachelor/Prog1/Codierungsstandard.htm create mode 100644 Bachelor/Prog1/Folien/chapter01.ppt create mode 100644 Bachelor/Prog1/Folien/chapter02.ppt create mode 100644 Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt create mode 100644 Bachelor/Prog1/Folien/chapter03.ppt create mode 100644 Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt create mode 100644 Bachelor/Prog1/Folien/chapter04.ppt create mode 100644 Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt create mode 100644 Bachelor/Prog1/Folien/chapter05.ppt create mode 100644 Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt create mode 100644 Bachelor/Prog1/Folien/chapter06.ppt create mode 100644 Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt create mode 100644 Bachelor/Prog1/Folien/chapter07.ppt create mode 100644 Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt create mode 100644 Bachelor/Prog1/Folien/chapter08.ppt create mode 100644 Bachelor/Prog1/Hinweise.pdf create mode 100644 Bachelor/Prog1/Klausur 'Programmieren I' am 10.02.05.eml create mode 100644 Bachelor/Prog1/Literatur.htm create mode 100644 Bachelor/Prog1/Op_Prec.htm create mode 100644 Bachelor/Prog1/PG1Klaus.htm create mode 100644 Bachelor/Prog1/PG1_inh.htm create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsw create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsw create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsw create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsw create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp create mode 100644 Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsw create mode 100644 Bachelor/Prog1/Prakt2/index.htm create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsw create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsw create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsw create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsw create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsw create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsw create mode 100644 Bachelor/Prog1/Prakt3/index.htm create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsw create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsw create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsw create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsw create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsw create mode 100644 Bachelor/Prog1/Prakt4/index.htm create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsw create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsw create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw create mode 100644 Bachelor/Prog1/Prakt5/index.htm create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsw create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsw create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsw create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsp create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsw create mode 100644 Bachelor/Prog1/Prakt6.zip create mode 100644 Bachelor/Prog1/Prakt6/index.htm create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsw create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsw create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.h create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw create mode 100644 Bachelor/Prog1/Vorlesung.htm create mode 100644 Bachelor/Prog1/Vorlesung_files/style.css create mode 100644 Bachelor/Prog1/chap1_8.zip create mode 100644 Bachelor/Prog1/ex1_8.zip create mode 100644 Bachelor/Prog1/examples/ch01/Fig01_02.cpp create mode 100644 Bachelor/Prog1/examples/ch01/Fig01_04.cpp create mode 100644 Bachelor/Prog1/examples/ch01/Fig01_05.cpp create mode 100644 Bachelor/Prog1/examples/ch01/Fig01_06.cpp create mode 100644 Bachelor/Prog1/examples/ch01/Fig01_14.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Ex02_05.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Ex02_08.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Ex02_15.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Ex02_24.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Ex02_25.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Ex02_42.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_07.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_09.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_11.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_14.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_16.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_17.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_20.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_21.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_22.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_24.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_26.cpp create mode 100644 Bachelor/Prog1/examples/ch02/Fig02_27.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Ex03_02.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Ex03_03.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Ex03_10.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Ex03_49.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Ex03_50.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_03.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_04.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_07.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_08.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_09.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_10.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_12.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_14.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_15.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_18.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_19.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_20.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_21.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_22.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_23.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_24.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_25.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_26.cpp create mode 100644 Bachelor/Prog1/examples/ch03/Fig03_27.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Ex04_18.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Ex04_21.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_03.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_04.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_05.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_06.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_07.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_08.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_09.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_10.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_11.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_12.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_13.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_14.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_15.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_16.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_17.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_19.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_20.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_22.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_23.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Ex05_21.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Ex05_22.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Ex05_30.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_04.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_06.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_07.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_10.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_11.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_12.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_13.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_14.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_15.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_16.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_17.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_20.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_21.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_24.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_25.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_26.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_28.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_29.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_30.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_31.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_32.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.h create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_08/Time1.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_08/Time1.h create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.h create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.h create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.h create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.h create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.cpp create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.h create mode 100644 Bachelor/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.h create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.h create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.h create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.h create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.h create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_20_23/implementation.h create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.cpp create mode 100644 Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.h create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.h create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.h create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.h create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.h create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp create mode 100644 Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.h create mode 100644 Bachelor/Prog1/examples/elevator/ElevatorSimulation.cpp create mode 100644 Bachelor/Prog1/examples/elevator/bell.cpp create mode 100644 Bachelor/Prog1/examples/elevator/bell.h create mode 100644 Bachelor/Prog1/examples/elevator/building.cpp create mode 100644 Bachelor/Prog1/examples/elevator/building.h create mode 100644 Bachelor/Prog1/examples/elevator/clock.cpp create mode 100644 Bachelor/Prog1/examples/elevator/clock.h create mode 100644 Bachelor/Prog1/examples/elevator/door.cpp create mode 100644 Bachelor/Prog1/examples/elevator/door.h create mode 100644 Bachelor/Prog1/examples/elevator/elevator.cpp create mode 100644 Bachelor/Prog1/examples/elevator/elevator.h create mode 100644 Bachelor/Prog1/examples/elevator/elevatorButton.cpp create mode 100644 Bachelor/Prog1/examples/elevator/elevatorButton.h create mode 100644 Bachelor/Prog1/examples/elevator/floor.cpp create mode 100644 Bachelor/Prog1/examples/elevator/floor.h create mode 100644 Bachelor/Prog1/examples/elevator/floorButton.cpp create mode 100644 Bachelor/Prog1/examples/elevator/floorButton.h create mode 100644 Bachelor/Prog1/examples/elevator/light.cpp create mode 100644 Bachelor/Prog1/examples/elevator/light.h create mode 100644 Bachelor/Prog1/examples/elevator/person.cpp create mode 100644 Bachelor/Prog1/examples/elevator/person.h create mode 100644 Bachelor/Prog1/examples/elevator/scheduler.cpp create mode 100644 Bachelor/Prog1/examples/elevator/scheduler.h create mode 100644 Bachelor/Prog1/probeklausur/lotto.h create mode 100644 Bachelor/Prog1/probeklausur/lottogenerator.cpp create mode 100644 Bachelor/Prog1/probeklausur/main.cpp (limited to 'Bachelor/Prog1') diff --git a/Bachelor/Prog1/Ascii_Table.htm b/Bachelor/Prog1/Ascii_Table.htm new file mode 100644 index 0000000..512ae95 --- /dev/null +++ b/Bachelor/Prog1/Ascii_Table.htm @@ -0,0 +1,197 @@ + + +Reference Material-ASCII Character Set + + + +
ASCII Character Set +


+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
0 1 2 3 4 5 6 7 8 9
0nulsohstxetxeotenqackbelbsht
1nlvtffcrsosidledc1dc2dc3
2dc4naksynetbcanemsubescfsgs
3rsussp!"#$%&`
4()*+,-./01
523456789:;
6<=>?@ABCDE
7FGHIJKLMNO
8PQRSTUVWXY
9Z[\]^_'abc
10defghijklm
11nopqrstuvw
12xyz{|}~del
+

+
The ASCII character +set.
+

+



+

+

The digits at the left of the table are the left digits of the decimal +equivalent (0-127) of the character code, and the digits at the top of the table +are the right digits of the character code. For example, the character code for +`F' is 70, and the character code for `&' is 38.

+

Note: Most users of this book are interested in the ASCII character set used +to represent English characters on many computers. The ASCII character set is a +subset of the Unicode character set used to represent characters from most of +the world's languages. For more information on the Unicode character set, visit +the World Wide Web site:

+
+

     http://unicode.org/

+
+
diff --git a/Bachelor/Prog1/Codierungsstandard.htm b/Bachelor/Prog1/Codierungsstandard.htm new file mode 100644 index 0000000..844c06d --- /dev/null +++ b/Bachelor/Prog1/Codierungsstandard.htm @@ -0,0 +1,319 @@ + + + + + +Codierungs-Standard + + + +

+Codierungs-Standard

+

+ 

+

+Der hier angeführte +Codierungs-Standard ist im wesentlichen aus dem Buch von Schmaranz (s. +Literaturliste) übernommen. Er ist in einigen wenigen Punkten modifiziert, so +dass er mit den in der Vorlesung verwendeten Beispielen konform ist. Es sind +natürlich auch andere Standards denkbar und sinnvoll, für die Praktikumsaufgaben +und in der Klausur ist jedoch dieser Standard einzuhalten!

+

+ 

+

+1   Generelle Regeln

+

+ 

+

+Die folgenden Prinzipien sind +essentiell für die Lesbarkeit, Wartbarkeit und Erweiterbarkeit eines Programms:

+

+ 

+

+Einfachheit: +Das Prinzip der Einfachheit ist auch als das KISS-Prinzip (Keep It +Small and Simple) bekannt. Kurz gesagt sollen Methoden, Funktionen +und natürlich auch Operatoren genau eine, für ihren Abstraktionslevel adäquate, +atomare Aufgabe erfüllen. Niemals sollen mehrere Aufgaben auf einmal erledigt +werden, genauso wenig, wie Aufgaben erledigt werden sollen, die in ein anderes +Abstraktionslevel gehören (=Durchgriff nach unten oder oben). Parameterlisten +sollen so kurz und übersichtlich wie möglich gehalten werden. Methoden, +Operatoren und Funktionen sollen als Faustregel nicht mehr als 60 Zeilen lang +sein. Eine durchschnittliche Länge von ca. 30 Zeilen ist zu bevorzugen. +Seiteneffekte sind absolut zu vermeiden!

+

+ 

+

+Intuitivität: +Das Prinzip der Intuitivität +bedeutet, dass man den geschriebenen Source-Code "wie ein Buch" lesen und +verstehen können muss, und zwar ohne Kommentare im Source-Code und ohne +Erklärungen des Programmierers! Damit ist impliziert, dass Variablen-, Methoden- +und Funktionsnamen sprechend (=selbsterklärend) und genau ihrer Funktionalität +entsprechend benannt sein müssen. Einbuchstabenvariablen, wie z.B. i, sind nur +in Sonderfällen wie Schleifenzähler erlaubt. Unnötige Kommentare werden als +störend erachtet und sollen dementsprechend weggelassen werden. Ein typisches +Beispiel für solche unnötigen Kommentare wäre:

+

+count++; +// and here the counter is incremented

+

+ 

+

+Einheitlichkeit: Verwandte Teile im Source-Code müssen denselben Prinzipien folgen. Wenn +z.B. eine Funktion +copy +als ersten Parameter den Zielort und als zweiten Parameter den Ursprungsort +nimmt, dann müssen verwandte Funktionen, wie z.B. +move, +sich an dieselben Konventionen halten. Genauso gilt dies auch für Klassen und +ihre Methoden. Nehmen wir z.B. eine Klasse die einen Knoten für z.B. eine +einfach verkettete Liste repräsentiert. Wenn in dieser Klasse der nachfolgende +Knoten über Aufruf von +next() +erreichbar ist, dann darf er nicht in einem Knoten für eine doppelt verkettete +Liste auf einmal über Aufruf von +successor() +erreichbar sein.

+

+ 

+

+ 

+

+2   Codierungs-Regeln

+

+ 

+

+Die hier angeführten Regeln +helfen, den Source-Code so weit wie möglich zu vereinheitlichen und damit die +Arbeit in einem Team zu erleichtern:

+ +

+-      +Jedes File muss +einen Header besitzen, in dem zumindest der Filename, und eine kurze +Beschreibung des Inhalts zu finden sind. In der Praxis hat es sich eingebürgert, +dass außerdem der Name des Autors, das Erstellungsdatum, das letzte +Änderungsdatum, eine Versionsnummer und ein Copyright-Statement im Header +stehen.

+

+-      +Geschwungene +Klammern für Code-Blöcke müssen in einer eigenen Zeile stehen. Ausnahme hiervon +sind Codeblöcke, die zu Kontrollstrukturen (Auswahl, Wiederholung) gehören. Bei +diesen steht die öffnende geschwungene Klammer in derselben Zeile wie das +Schlüsselwort der Kontrollstruktur (if, +while, +for, …). Die Einrückung der Klammern entspricht genau dem +umschließenden Block. Der eingeschlossene Block selbst muss genau um 3 Spaces +eingerückt sein (hier sind in der Praxis Werte zwischen 2 und 4 gängig). +Einrückungen dürfen ausschließlich mit Spaces gemacht werden, Tabs sind +verboten, denn sonst kann es mit verschiedenen Editor-Einstellungen und beim +Drucken Probleme geben.

+

+-      +Vor jeder +Operator-, Methoden- oder Funktionsdefinition muss in kurzen Worten beschrieben +werden, wozu diese Funktion dient. Bei größeren Projekten muss auch beschrieben +sein, was bei den einzelnen Parametern erwartet wird, welche Randbedingungen +gelten, welche Return-Values zu erwarten sind und wie diese zu interpretieren +sind.

+

+ 

+

+ 

+

+3   Design Guidelines

+

+ 

+

+Dieser Abschnitt enthält einige +generelle Richtlinien, die helfen sollen, sauberen und robusten Code zu +schreiben.

+ +

 

+ + \ No newline at end of file diff --git a/Bachelor/Prog1/Folien/chapter01.ppt b/Bachelor/Prog1/Folien/chapter01.ppt new file mode 100644 index 0000000..e40e68c Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter01.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter02.ppt b/Bachelor/Prog1/Folien/chapter02.ppt new file mode 100644 index 0000000..97e0c0c Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter02.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt new file mode 100644 index 0000000..376ef1b Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter03.ppt b/Bachelor/Prog1/Folien/chapter03.ppt new file mode 100644 index 0000000..ecc78ac Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter03.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt new file mode 100644 index 0000000..f286397 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter04.ppt b/Bachelor/Prog1/Folien/chapter04.ppt new file mode 100644 index 0000000..0166fba Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter04.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt new file mode 100644 index 0000000..3fe5dd6 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter05.ppt b/Bachelor/Prog1/Folien/chapter05.ppt new file mode 100644 index 0000000..a9c8bb9 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter05.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt new file mode 100644 index 0000000..d750294 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter06.ppt b/Bachelor/Prog1/Folien/chapter06.ppt new file mode 100644 index 0000000..1faff91 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter06.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt new file mode 100644 index 0000000..5c67b11 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter07.ppt b/Bachelor/Prog1/Folien/chapter07.ppt new file mode 100644 index 0000000..fe27bec Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter07.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt new file mode 100644 index 0000000..99992a6 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt differ diff --git a/Bachelor/Prog1/Folien/chapter08.ppt b/Bachelor/Prog1/Folien/chapter08.ppt new file mode 100644 index 0000000..e236968 Binary files /dev/null and b/Bachelor/Prog1/Folien/chapter08.ppt differ diff --git a/Bachelor/Prog1/Hinweise.pdf b/Bachelor/Prog1/Hinweise.pdf new file mode 100644 index 0000000..0fd297c Binary files /dev/null and b/Bachelor/Prog1/Hinweise.pdf differ diff --git a/Bachelor/Prog1/Klausur 'Programmieren I' am 10.02.05.eml b/Bachelor/Prog1/Klausur 'Programmieren I' am 10.02.05.eml new file mode 100644 index 0000000..068b100 --- /dev/null +++ b/Bachelor/Prog1/Klausur 'Programmieren I' am 10.02.05.eml @@ -0,0 +1,84 @@ +Return-Path: +Received: from murder ([unix socket]) + by ns1 (Cyrus v2.2.10-Gentoo) with LMTPA; + Fri, 28 Jan 2005 10:33:05 +0100 +X-Sieve: CMU Sieve 2.2 +Received: from localhost (localhost [127.0.0.1]) + by ns1.eisy.net.eu.org (eisy's SMTP Server READY) with ESMTP id 73892625E1 + for ; Fri, 28 Jan 2005 10:33:04 +0100 (CET) +Received: from ns1.eisy.net.eu.org ([127.0.0.1]) + by localhost (ns1 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP + id 08412-04 for ; + Fri, 28 Jan 2005 10:32:50 +0100 (CET) +Received: from localhost (localhost [127.0.0.1]) + by ns1.eisy.net.eu.org (eisy's SMTP Server READY) with ESMTP id EE7D1625B0 + for ; Fri, 28 Jan 2005 10:32:49 +0100 (CET) +Delivery-Date: Fri, 28 Jan 2005 10:32:16 +0100 +Received: from pop.kundenserver.de [212.227.15.149] + by localhost with POP3 (fetchmail-6.2.5) + for sven@localhost (single-drop); Fri, 28 Jan 2005 10:32:50 +0100 (CET) +Received: from [213.165.64.20] (helo=mail.gmx.net) + by mxeu5.kundenserver.de with ESMTP (Nemesis), + id 0MKqpg-1CuSUB2ep0-00060g; Fri, 28 Jan 2005 10:32:15 +0100 +Received: (qmail 19885 invoked by uid 0); 28 Jan 2005 09:25:35 -0000 +Received: from 141.100.244.48 by www37.gmx.net with HTTP; + Fri, 28 Jan 2005 10:25:35 +0100 (MET) +Date: Fri, 28 Jan 2005 10:25:35 +0100 (MET) +From: "Hans-Peter Weber" +To: Leistungsnachweis "Programmieren I" +MIME-Version: 1.0 +Subject: Klausur "Programmieren I" am 10.02.05 +X-Priority: 3 (Normal) +X-Authenticated: #3431627 +Message-ID: <30230.1106904335@www37.gmx.net> +X-Mailer: WWW-Mail 1.6 (Global Message Exchange) +X-Flags: 0001 +Content-Type: text/plain; charset="iso-8859-1" +Content-Transfer-Encoding: 8bit +Envelope-To: info@sven-eisenhauer.net +X-SpamScore: 0.000 +X-Virus-Scanned: by amavisd-new at ns1 + +An alle zur Klausur "Programmieren I" am 10.02.05 angemeldeten +Studierenden, + +einige Hinweise zur Klausur: + +- Alle Studierenden, die das Praktikum nicht in einer meiner Veranstaltungen +(in diesem Semester also bei Herrn Wolf oder mir) +gemacht haben, müssen spätestens beim Betreten des Klausurraumes die +Bestätigung ('grüner Schein' o.ä.) über die erfolgreiche Teilnahme am +Praktikum 'Programmieren 1' bei mir abgeben. Fehlt diese Bestätigung, ist +eine Klausurteilnahme nicht möglich. + +- Bringen Sie Ihren Studentenausweis mit und zeigen Sie ihn mir beim +Betreten des Klausurraumes. + +- Alle Studenten, die nicht an meiner Vorlesung teilgenommen haben, weise +ich hiermit auf den benutzten Codierungsstandard hin (s. +http://www.fbi.fh-darmstadt.de/~h.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/Codierungsstandard.htm +). Bei grober Missachtung dieses Standards kann ein Punktabzug erfolgen. + +- Aus gegebenem Anlass noch folgender Hinweis: Dies ist die PG I - Klausur +von Hans-Peter Weber, nicht Wolfgang Weber. Die Klausur des Kollegen +Wolfgang Weber findet am Do, 03.02.05 - also eine Woche vor meiner - statt. + +- Wenn Sie doch nicht an dieser (meiner) Klausur teilnehmen möchten, melden +Sie sich im Online-Belegsystem wieder ab. Dies ist noch bis zum 06.02.05 +möglich. + + +Eine gute Klausurvorbereitung und bis zum 10.02. +Hans-Peter Weber + +-- +Prof.Dr.Hans-Peter Weber +Fachhochschule Darmstadt +Fachbereich Informatik, Standort Dieburg +Max-Planck-Str.2 +64807 Dieburg + +Telefon: +49 6071 829-240 +Telefax: +49 6071 829-340 +e-mail: h.p.weber@fbi.fh-darmstadt.de + diff --git a/Bachelor/Prog1/Literatur.htm b/Bachelor/Prog1/Literatur.htm new file mode 100644 index 0000000..849e40c --- /dev/null +++ b/Bachelor/Prog1/Literatur.htm @@ -0,0 +1,105 @@ + + + + + + + Literatur + + + +empfohlene Literatur +
  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Autor & TitelBemerkungen
H.M.Deitel,P.J.Deitel: C++ How To Program, 4th ed; + Prentice-Hall; 2003; EUR ca 60Basistext der Vorlesung, deshalb primär empfohlen. Enthält auf CD die im Praktikum benutzte +Entwicklungsumgebung MS Visual C++ 6.0 (Introductory Edition, englisch). +
P.Prinz,U.Kirch-Prinz: C++, Lernen und professionell + anwenden, 2.Auflage; MITP-Verlag; 2002; EUR 44.95Gut zum Nachschlagen geeignet. Enthält auf CD die im Praktikum benutzte +Entwicklungsumgebung MS Visual C++ 6.0 (Autorenversion, deutsch). +
Vorsicht: Das ansonsten ähnliche Buch der gleichen +Autoren 'Objektorientiert programmieren mit ANSI C++' enthält kein MS Visual C++ 6.0 +, sondern den GNU-C++ Compiler.
P.Prinz,U.Kirch-Prinz: C++, Das Übungsbuch; MITP-Verlag; 2003; EUR +18.9525 Abschnitte zu den wichtigsten Themen der Vorlesung (außer STL) mit +jeweils 20 Verständnisfragen (!) und 10 Programmieraufgaben zum Üben. Unbedingt +empfehlenswert!
U.Breymann: C++. Eine Einführung, 7.Auflage; Hanser; + 2003; EUR 39,90.Deutschsprachiges Standardwerk zu Sprachsyntax und Objektorientierung.
K.Schmaranz: Softwareentwicklung in C++; Springer-Verlag; 2003; EUR 49,95Viele für das Verständnis förderliche Details. Fachlich wird der +fortgeschrittene erwachsene Entwickler angesprochen, stilistisch leider eher der +jugendliche Anfänger :-)
N.Josuttis: Objektorientiertes Programmieren in C++ , + 2.Auflage; Addison-Wesley; 2001; EUR 39,95Anderen deutschsprachigen C++-Lehrbüchern voraus, da + es  konsequent die Möglichkeiten der Standardbibliothek nutzt. Eher für + Fortgeschrittene geeignet.
A.Koenig, B.Moo: +Intensivkurs C++; +Addison-Wesley; 2003; EUR 34.95Übersetzung eines englischsprachigen Standardwerkes. Moderne, an den + Möglichkeiten der STL orientierte Einführung in + C++. Eher für Fortgeschrittene geeignet.
T.Erler: UML; bhv-Verlag; 2000; EUR 10,12Kompakte und gut lesbare Einführung zu Grundbegriffen und Anwendung der + UML.
+ \ No newline at end of file diff --git a/Bachelor/Prog1/Op_Prec.htm b/Bachelor/Prog1/Op_Prec.htm new file mode 100644 index 0000000..3e0b1b1 --- /dev/null +++ b/Bachelor/Prog1/Op_Prec.htm @@ -0,0 +1,219 @@ + + +Reference Material-Operator Precedence Chart + + + +
Operator Precedence Chart +


Operators are shown in decreasing order of precedence from top to bottom. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Operator

+

Type

+

Associativity +

+

:: +

+

:: +

+

binary scope resolution

+

unary scope resolution

+

left to right

+

()
[]
.

+

->

+

++

+

--

+

typeid

+

dynamic_cast<  type  >

+

static_cast<  type  >

+

reinterpret_cast<  type  >

+

const_cast<  type  >

+

parentheses
array + subscript
member selection via object

+

member selection via pointer

+

unary postincrement

+

unary postdecrement

+

run-time type information

+

run-time type-checked cast

+

compile-time type-checked + cast

+

cast for non-standard + conversions

+

cast away const-ness

+

left to right

+

++
--
+
-
!
~
(
type )

+

sizeof

+

&

+

*

+

new

+

new[]

+

delete

+

delete[]

+

unary preincrement
unary + predecrement
unary plus
unary minus
unary logical + negation
unary bitwise complement
C-style unary cast

+

determine size in bytes

+

address

+

dereference

+

dynamic memory allocation

+

dynamic array allocation

+

dynamic memory deallocation

+

dynamic array +deallocation

+

right to left

+

.*

+

->*

+

pointer to member via object +

+

pointer to member via + pointer

+

left to right

+

*
/
%

+

multiplication
division
modulus

+

left to right

+

+
-

+

addition
subtraction

+

left to right

+

<<
>>

+

bitwise left shift
bitwise + right shift

+

left to right

+

<
<=
>
>=

+

relational less + than
relational less than or equal to
relational greater + than
relational greater than or equal to

+

left to right

+

==
!=

+

relational is equal + to
relational is not equal to

+

left to right

+

&

+

bitwise AND

+

left to right

+

^ +

+

bitwise exclusive OR

+

left to right

+

| +

+

bitwise inclusive OR

+

left to right

+

&&

+

logical AND

+

left to right

+

|| +

+

logical OR

+

left to right

+

?: +

+

ternary conditional

+

right to left

+

=
+=
-=
*=
/=
%=
&=
^=
|=
<<=
>>=
+

+

assignment
addition + assignment
subtraction assignment
multiplication + assignment
division assignment
modulus assignment
bitwise AND + assignment
bitwise exclusive OR assignment
bitwise inclusive OR + assignment
bitwise left shift assignment
bitwise right shift with + sign

+

right to left

+

,

+

comma

+

left to +right

+
+
+
diff --git a/Bachelor/Prog1/PG1Klaus.htm b/Bachelor/Prog1/PG1Klaus.htm new file mode 100644 index 0000000..38229c2 --- /dev/null +++ b/Bachelor/Prog1/PG1Klaus.htm @@ -0,0 +1,227 @@ + + + + + + +Praktikum 6 + + + + + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren I  +
Klausur
+
+
+

20.01.04

+
+
+ +
+ + + + + + + + +
Name:

 

MatNr.:

 

USER:

 

+ +
+ + + + + + + + + + + + +
+

+Lottozahlen

+ +Definieren Sie eine Klasse LottoGenerator wie im folgenden +Klassendiagramm beschrieben:
+ + + + + + + + + + + + +
+
LottoGenerator
+
- ARRAY_SIZE : const int
+
- sixNumbers : int*
- seventhNumber : int +
- numberOf Draws : long
Constructor( )  +
Destructor( ) +
+ drawAllNumbers( ) : void
++ printAllNumbers( ) : void
++ sortSixNumbers( ) : void  +
+ getAllNumbers( int* ) : int
+ getNumberOfDraws( ) : long
+
+
+Besonderheiten der Methoden sind: +
    +
  • +Der Konstruktor soll ein int-Array für die sechs Gewinnzahlen dynamisch +erzeugen, das dann über das Attribut sixNumbers +angesprochen wird. Dieses Array und die restlichen Attribute sollen sinnvoll +initialisiert werden. Die Konstante ARRAY_SIZE +gibt die Anzahl der Elemente des dynamischen int-Arrays an.
  • +
  • +Durch drawAllNumbers sollen sechs +zufällig gezogene Zahlen im int-Array sixNumbers und eine siebte zufällige Zahl +(die Zusatzzahl) im Attribut seventhNumber abgelegt werden. Es gelten die +üblichen Lottoregeln: Die Zahlen sind aus dem Bereich 1 bis 49 und natürlich +alle verschieden. (Die 'Superzahl' soll nicht berücksichtigt werden.)
  • +
  • +Im Attribut numberOfDraws soll über die +Zahl der Ziehungen (d.h. die Zahl der Aufrufe von  +drawAllNumbers) seit der Erzeugung eines +LottoGenerator-Objekts Buch geführt werden.
  • + +
  • +printAllNumbers soll die Nummer der +Ziehung, die sechs gezogenen +Zahlen und die Zusatzzahl in einer geeigneten Formatierung auf dem Bildschirm +ausgeben.
  • + +
  • +sortSixNumbers soll die sechs +Gewinnzahlen im Array sixNumbers aufsteigend sortieren: Nach Aufruf von +sortSixNumbers steht die kleinste Zahl im +ersten Platz des Arrays, die größte im sechsten. Sie können ein Sortierverfahren +Ihrer Wahl benutzen.
  • + +
  • +getAllNumbers soll alle sieben gezogenen +Zahlen in das Anwendungsprogramm (main) für eine Weiterverarbeitung übergeben: +Die Zusatzzahl als Rückgabewert und die sechs Gewinnzahlen in ein vom +Anwendungsprogramm zur Verfügung gestelltes int-Array.
  • + +
  • +Der Destruktor soll (neben seiner Hauptaufgabe!) numberOfDraws am Bildschirm +ausgeben.
    +
    +
    +
  • +
+

Das Anwendungsprogramm (main) soll ein + LottoGenerator-Objekt +erzeugen und dann folgende Aktivitäten durchführen: +

    +
  • +Durchführung von 10 Ziehungen und Ausgabe der Ziehungsergebnisse (einschließlich +Zusatzzahl), wobei die sechs Gewinnzahlen aufsteigend sortiert sein sollen.  +
  • + +
  • +Durchführung von einer Million Ziehungen und Ermitteln, wie oft eine einstellige +Zusatzzahl auftrat.
  • + +
  • +Führen Sie eine Million Ziehungen durch und übergeben Sie jeweils die sechs +Gewinnzahlen an eine (globale) Funktion average. +Diese Funktion soll den ganzzahligen (also auf- bzw. abgerundeten) Mittelwert +der übergebenen Gewinnzahlen berechnen und zurückgeben. Für die zurückgegebenen +Mittelwerte soll in main eine +Häufigkeitsverteilung erstellt werden. Auf den Bildschirm auszugeben sind dann +alle vorkommenden Mittelwerte zusammen mit ihrer Häufigkeit. (Die absoluten +Zahlenwerte genügen, keine graphische Darstellung!)
  • +
+

 

+

 

+

 

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Bewertung (Punkte):maximalerreicht
Klassendeklaration12 
Konstruktor8 
drawAllNumbers12 
printAllNumbers8 
sortSixNumbers8 
getAllNumbers8 
getNumberOfDraws2 
Destruktor5 
main27 
average10 
+


+Gesamtpunkte:

+

 

+

Note:

+ + + + \ No newline at end of file diff --git a/Bachelor/Prog1/PG1_inh.htm b/Bachelor/Prog1/PG1_inh.htm new file mode 100644 index 0000000..d24bc55 --- /dev/null +++ b/Bachelor/Prog1/PG1_inh.htm @@ -0,0 +1,120 @@ + + + + + + + + Programmieren I + + +

+Prof. Dr. Hans-Peter Weber : Programmieren I  WS 04/05
  +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VorlesungPraktikum
   +

1 Einführung in die Programmierung mit C++

1
+
1a  Einführung in Objekttechnologie und UML
+
 

2 Kontrollstrukturen

2
+
2a  [Fallstudie] Identifizieren der Klassen in einer Problemstellung
+
 

3 Funktionen

3
3a  [Fallstudie] Identifizieren der Attribute einer Klasse
+
 

4 Arrays

4
4a  [Fallstudie] Identifizieren der Methoden einer Klasse
+
 

5 Zeiger und Strings

5
5a  [Fallstudie] Kollaborationen unter Objekten
+
 

6 Klassen und Datenabstraktion

6
6a  [Fallstudie] Beginn der Programmierung der Klassen für die Aufzug-Simulation
+
 

7 Klassen: Teil II

 
7a  [Fallstudie] Programmierung der Klassen für die Aufzug-Simulation
+
 

8 Überladen von Operatoren
+

 
+
+
+ + \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp new file mode 100644 index 0000000..398c0e4 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp @@ -0,0 +1,23 @@ +// Programmieren 1, Praktikum 1, Aufgabe 1 +// Sven Eisenhauer +// 27.10.2004 + +#include +using std::cout; +using std::endl; + +int main() +{ + int number = 7; + + cout << number%2; + number = number/2; + cout << number%2; + number = number/2; + cout << number%2; + number = number/2; + + cout << endl; + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp new file mode 100644 index 0000000..9a86bbf --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1pr1_1 - 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 "prg1pr1_1.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 "prg1pr1_1.mak" CFG="prg1pr1_1 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1pr1_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1pr1_1 - 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)" == "prg1pr1_1 - 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)" == "prg1pr1_1 - 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 "prg1pr1_1 - Win32 Release" +# Name "prg1pr1_1 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1pr1_1.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/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsw new file mode 100644 index 0000000..0d797df --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.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: "prg1pr1_1"=.\prg1pr1_1.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp new file mode 100644 index 0000000..b8467f1 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp @@ -0,0 +1,22 @@ +// Programmieren 1, Praktikum 1, Aufgabe 2 +// Sven Eisenhauer +// 27.10.2004 + +#include +#include + +int main() +{ + cout << "Draußen brüllen Bären und Löwen!"; + + system( "cls" ); // clear screen + + cout << "Drau\xe1\x65n br\x81llen B\x84ren und L\x94wen!"; + //cout << "Drau\x00e1en br\x81llen B\x84ren und L\x94wen!"; + cout << endl; + + cout << "B\x8eREN UND L\x99WEN BR\x9aLLEN."; + cout << endl << endl; + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp new file mode 100644 index 0000000..ed33848 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1pr1_2 - 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 "prg1pr1_2.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 "prg1pr1_2.mak" CFG="prg1pr1_2 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1pr1_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1pr1_2 - 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)" == "prg1pr1_2 - 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)" == "prg1pr1_2 - 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 "prg1pr1_2 - Win32 Release" +# Name "prg1pr1_2 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1pr1_2.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/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsw new file mode 100644 index 0000000..6104bf5 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.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: "prg1pr1_2"=.\prg1pr1_2.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp new file mode 100644 index 0000000..880b7b9 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp @@ -0,0 +1,50 @@ +// Programmieren 1, Praktikum 1, Aufgabe 3 +// Sven Eisenhauer +// 27.10.2004 + +#include + +int main() +{ + int iInOp1,iInOp2,iInOp3; // 3 operants, user input + int iMin,iMax; + + std::cout << "Bitte drei unterschiedliche ganze Zahlen eingeben:\n"; + std::cin >> iInOp1; + std::cin >> iInOp2; + std::cin >> iInOp3; + std::cout << "\nDie Summe ist " << iInOp1 + iInOp2 + iInOp3; + std::cout << "\nDer Mittelwert ist "<< (static_cast (iInOp1 + iInOp2 + iInOp3))/3; + std::cout << "\nDas Produkt ist " << (iInOp1 * iInOp2 * iInOp3); + + if (iInOp1iInOp2 && iInOp1>iInOp3) + { + iMax=iInOp1; + } + if (iInOp2>iInOp1 && iInOp2>iInOp1) + { + iMax=iInOp2; + } + if (iInOp3>iInOp1 && iInOp3>iInOp1) + { + iMax=iInOp3; + } + + std::cout << "\nDer kleinste Wert ist "< +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p1_3 - 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 "prg1pr1_3.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 "prg1pr1_3.mak" CFG="prg1p1_3 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p1_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p1_3 - 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)" == "prg1p1_3 - 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)" == "prg1p1_3 - 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 "prg1p1_3 - Win32 Release" +# Name "prg1p1_3 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1pr1_3.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/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsw new file mode 100644 index 0000000..59d5b79 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.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: "prg1p1_3"=.\prg1p1_3.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp new file mode 100644 index 0000000..8536977 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp @@ -0,0 +1,40 @@ +// Programmieren 1, Praktikum 1, Aufgabe 4 +// Sven Eisenhauer +// 27.10.2004 + +#include +//#include + +using std::cout; +using std::cin; +using std::endl; + +int main () +{ + // const iDigits=6; // number of digits entered + int iZahl; // user input + // int iCounter=iDigits-1; // use digits from iDigits-1 to 0 of iZahl + + // cout << "Bitte eine "<> iZahl; + + /* for (iCounter;iCounter>=0;iCounter--) + { + cout << static_cast (iZahl / pow(10,iCounter)) << "\n"; + iZahl=iZahl%static_cast (pow(10,iCounter)); + } + */ + + cout << iZahl/10000 << endl; + iZahl=iZahl%10000; + cout << iZahl/1000 << endl; + iZahl=iZahl%1000; + cout << iZahl/100 << endl; + iZahl=iZahl%100; + cout << iZahl/10 << endl; + iZahl=iZahl%10; + cout << iZahl << endl; + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp new file mode 100644 index 0000000..decf90b --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_4" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1pr1_4 - 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 "prg1pr1_4.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 "prg1pr1_4.mak" CFG="prg1pr1_4 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1pr1_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1pr1_4 - 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)" == "prg1pr1_4 - 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)" == "prg1pr1_4 - 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 "prg1pr1_4 - Win32 Release" +# Name "prg1pr1_4 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1pr1_4.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/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsw new file mode 100644 index 0000000..d1654c2 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.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: "prg1pr1_4"=.\prg1pr1_4.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp new file mode 100644 index 0000000..e17a0bc --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp @@ -0,0 +1,25 @@ +// Programmieren 1, Praktikum 1, Aufgabe 5 +// Sven Eisenhauer +// 27.10.2004 + +#include + +int main () +{ + char cInput; + + do + { + system( "cls" ); + std::cout << "Bitte ein Zeichen eingeben: "; + std::cin >> cInput; + std::cout << "ASCII Code der Eingabe: "<< static_cast< int >(cInput) << "\n"; + std::cout << "Hex ASCII Code der Eingabe: "<< std::hex << static_cast< int >(cInput) << "\n"; + std::cout << "\nWeiter mit beliebiger Taste, Abbruch mit \"0\"\n"; + std::cin >> cInput; + + } + while (cInput != 0x30); + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp new file mode 100644 index 0000000..820b122 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_5" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1pr1_5 - 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 "prg1pr1_5.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 "prg1pr1_5.mak" CFG="prg1pr1_5 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1pr1_5 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1pr1_5 - 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)" == "prg1pr1_5 - 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)" == "prg1pr1_5 - 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 "prg1pr1_5 - Win32 Release" +# Name "prg1pr1_5 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1pr1_5.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/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsw new file mode 100644 index 0000000..ca1dd2a --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.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: "prg1pr1_5"=.\prg1pr1_5.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt2/index.htm b/Bachelor/Prog1/Prakt2/index.htm new file mode 100644 index 0000000..872f2ac --- /dev/null +++ b/Bachelor/Prog1/Prakt2/index.htm @@ -0,0 +1,156 @@ + + + + +Praktikum 2 + + + +  + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren I  +
Praktikum
+
+
2
+
+ +
+ + + + +
Ziel: +Sie sollen einfache und komplexere Kontrollstrukturen üben. +
+
+ + + + + + +
1    Einfaches Histogramm erstellen + +
    +
  • +Schreiben Sie ein Programm, das fünf Zahlen (jede zwischen 1 und 80) von der + Konsole einliest. Für jede eingegebene Zahl soll Ihr Programm eine Zeile mit + entsprechend vielen aneinander hängenden Sternchen (*) ausgeben. Zum Beispiel + soll für eine eingegebene Zahl 7 folgende Zeile ausgegeben werden:
    +
    *******
  • + +
+ +
+ + + + + + + +
2    Binär-Dezimalwandlung +
    +
  • +Schreiben Sie ein Programm, das eine binäre Zahl (also eine +ganze Zahl, die als Ziffern nur 0 oder 1 enthält) einliest und ihr dezimales +Äquivalent ausgibt. Die eingegebene binäre Zahl soll maximal 10-stellig +sein.
  • +
  • +Hinweis: Nutzen Sie modulo- und Divisionsoperator, um die binären Ziffern eine +nach der anderen von rechts nach links abzuspalten. Bauen Sie aus den binären +Ziffern zusammen mit ihrer jeweiligen Wertigkeit die dezimale Zahl auf
  • + +
  • +Realisieren Sie auch die umgekehrte Operation: Das Programm soll eine +eingegebene Dezimalzahl in ihre binäre Darstellung umwandeln. 
  • + +
+
+ + + + + + + +
3    Ganzzahlige rechtwinklige Dreiecke +
    +
  • +Es gibt rechtwinklige Dreiecke (d.h. Dreiecke für die der Satz des Pythagoras +gilt), deren Seitenlängen alle ganze Zahlen sind.  
  • +
  • +Schreiben Sie ein Programm, das alle diese Dreiecke in Form der Längen ihrer +drei Seiten findet. Hierbei sollen nur Seitenlängen, die nicht größer als 500 +sind, berücksichtigt werden. Geben Sie zusätzlich die Anzahl der gefundenen +Dreiecke aus.
  • + +
  • +Hinweis: Nutzen Sie eine dreifach geschachtelte for-Schleife, die alle +Möglichkeiten ausprobiert. Diese Vorgehensweise ist ein Beispiel für eine +sogenannte "Brute Force"-Methode.
  • + +
+
+ + + + + + +
4    Primzahlen
    +
  • +Schreiben Sie ein Programm, das eine positive ganze Zahl von der Tastatur +einliest und alle Primzahlen, die kleiner als diese Zahl sind, ausgibt. + +
+
+ + + + + + +
5    Primzahlzwillinge (fakultativ) + +
    +
  • +Schreiben Sie ein Programm, das zwei positive ganze Zahlen von der Tastatur +einliest und alle Primzahlzwillinge, die zwischen diesen beiden Zahlen liegen, ausgibt. +
  • +Als Primzahlzwillinge bezeichnet man zwei Primzahlen, die 'direkt' benachbart +sind, also nur durch die zwischen ihnen liegende gerade Zahl getrennt sind. +Beispiele sind 3 und 5 oder 17 und 19. + +
+
+ + + + + + +
6    Binär-, +Oktal- und Hexadezimaldarstellung (fakultativ) + +
    +
  • +Schreiben Sie ein Programm, das eine Tabelle der binären, oktalen und +hexadezimalen Darstellung der ganzen Dezimalzahlen von 1 bis 256 ausgibt. + +
+
+ + \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp new file mode 100644 index 0000000..98036aa --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp @@ -0,0 +1,77 @@ +// Programmieren 1, Praktikum 2, Aufgabe 1 +// Sven Eisenhauer +// 29.10.2004 +// +// file: prg1p2_1.cpp +// +// purpose: program to read 5 integer numbers (between 1 and 80) from keyboard and for each +// number to draw the amount of "*"-characters in one line on the screen. +// +#include +using std::cin; +using std::cout; +using std::endl; + +int main() +{ + int iNumber1,iNumber2,iNumber3,iNumber4,iNumber5; + + cout << "Please enter number 1: "; + cin >> iNumber1; + cout << "Please enter number 2: "; + cin >> iNumber2; + cout << "Please enter number 3: "; + cin >> iNumber3; + cout << "Please enter number 4: "; + cin >> iNumber4; + cout << "Please enter number 5: "; + cin >> iNumber5; + + for (int iCounter=1;iCounter<=iNumber1;iCounter++) + cout << "*"; + cout << endl; + for (iCounter=1;iCounter<=iNumber2;iCounter++) + cout << "*"; + cout << endl; + for (iCounter=1;iCounter<=iNumber3;iCounter++) + cout << "*"; + cout << endl; + for (iCounter=1;iCounter<=iNumber4;iCounter++) + cout << "*"; + cout << endl; + for (iCounter=1;iCounter<=iNumber5;iCounter++) + cout << "*"; + cout << endl; +/* + + int iInput[5]; + + //input repitition + for (int iCounter=1;iCounter<=5;iCounter++) + { + cout << "Please enter " << iCounter << ". number (between 1 and 80): "; + cin >> iInput[iCounter-1]; + + // check input + while (iInput[iCounter-1]<1 || iInput[iCounter-1]>80) + { + cout<<"\nNumber not between 1 and 80, please enter a new one: "; + cin >> iInput[iCounter-1]; + }// end while + + + }// end for input repitition + + //output repition + for (iCounter=1;iCounter<=5;iCounter++) + { + // draw star characters + for (int iStarCounter=1;iStarCounter<=iInput[iCounter-1];iStarCounter++) + cout <<"*"; + + // new line for next number + cout << endl; + }// end output +*/ + return 0; // everything ok +}// end main diff --git a/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp new file mode 100644 index 0000000..bf231f2 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p2_1 - 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 "prg1p2_1.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 "prg1p2_1.mak" CFG="prg1p2_1 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p2_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p2_1 - 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)" == "prg1p2_1 - 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)" == "prg1p2_1 - 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 "prg1p2_1 - Win32 Release" +# Name "prg1p2_1 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1p2_1.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/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsw b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsw new file mode 100644 index 0000000..9a01f06 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.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: "prg1p2_1"=.\prg1p2_1.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp new file mode 100644 index 0000000..1ac93e1 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp @@ -0,0 +1,86 @@ +// Programmieren 1, Praktikum 2, Aufgabe 2 +// Sven Eisenhauer +// 29.10.2004 +// +// file: prg1p2_2.cpp +// +// purpose: convert bin to dec numbers or dec numbers to bin +// 10 digits mean 2exp9 to 2exp0 +// +#include +#include +using std::cin; +using std::cout; +using std::endl; + +int main() +{ + const iBit=10; //define how large the binary output should be. + + int iMode; + int iBin=0; + int iActualFactor=0; + int iDec=0; + int iCounter=0; + int iCounter2=0; + //int iBinOut[iBit]; + int iBinOut=0; + + + do + { + system("cls"); + cout << "Please select Converter:\n1) Bin -> Dec\n2) Dec -> Bin\n\n0) End\n\n" + "Your selection: "; + cin >> iMode; + switch (iMode) { + case 1: + cout << "\nPlease enter a binary number (max 10 characters): "; + cin >> iBin; + for (iCounter = 9;iCounter>=0;iCounter--) + { + iActualFactor=iBin/pow(10,iCounter); + iDec+=(iActualFactor * static_cast (pow(2,iCounter))); + iBin=iBin%static_cast (pow(10,iCounter)); + } + cout << "\nDecimal: " << iDec; + cout << endl; + system ("pause"); + break; // end bin2dec + case 2://dec2bin + cout << "\nPlease enter a decimal number: "; + cin >> iDec; + cout << "\n"<=0;iCounter--) + { + iBinOut[iCounter]=iDec%2; + iDec=iDec/2; + } + // print array in reverse order + for (iCounter=0;iCounter<=iBit-1;iCounter++) + { + cout << iBinOut[iCounter]; + if (0==((iCounter+1)%4)) // space separator after 4 bit + cout <<" "; + } + */ + iBinOut=0; + for (iCounter2=iBit;iCounter2>=0;iCounter2--) + { + iBin=iDec%2; + iDec=iDec/2; + iBinOut += iBin * static_cast (pow(10,iBit-iCounter2)); + } + cout << iBinOut << endl; + system ("pause"); + break; // end dec2bin + case 0: // end selected... we are leaving... + break; + default: // wrong selection + cout << "\n !! No functon selected !!"; + } // end switch + } // end while + while (iMode != 0); + return 0; // so far, we are ok +}// end main \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp new file mode 100644 index 0000000..63ba0bc --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p2_2 - 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 "prg1p2_2.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 "prg1p2_2.mak" CFG="prg1p2_2 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p2_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p2_2 - 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)" == "prg1p2_2 - 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)" == "prg1p2_2 - 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 "prg1p2_2 - Win32 Release" +# Name "prg1p2_2 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1p2_2.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/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsw b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsw new file mode 100644 index 0000000..8fa2314 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.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: "prg1p2_2"=.\prg1p2_2.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp new file mode 100644 index 0000000..259648e --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp @@ -0,0 +1,31 @@ +// Programmieren 1, Praktikum 2, Aufgabe 3 +// Sven Eisenhauer +// 29.10.2004 +// +// file: prg1p2_3.cpp +// +// purpose: find triangles, which fit a*a + b*b = c*c, for integer a,b,c < 500 +// +// +#include +#include + +using std::cin; +using std::cout; +using std::endl; +using std::setw; + +int main() +{ + int a,b,c=1; + + cout < +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p2_3 - 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 "prg1p2_3.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 "prg1p2_3.mak" CFG="prg1p2_3 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p2_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p2_3 - 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)" == "prg1p2_3 - 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)" == "prg1p2_3 - 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 "prg1p2_3 - Win32 Release" +# Name "prg1p2_3 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1p2_3.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/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsw b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsw new file mode 100644 index 0000000..6045ba4 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.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: "prg1p2_3"=.\prg1p2_3.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp new file mode 100644 index 0000000..b649a6a --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp @@ -0,0 +1,51 @@ +// Programmieren 1, Praktikum 2, Aufgabe 4 +// Sven Eisenhauer +// 05.11.2004 +// +// file: prg1p2_4.cpp +// +// purpose: Program to find all prime numbers, which are smaller than the entered positive number +// + +#include +#include + +using std::cin; +using std::cout; +using std::endl; + +int main() +{ + int iNumber=0; + int iIsPrime=0; + + system ("cls"); + cout << "Please enter a positive number: "; + cin >> iNumber; + if (0 >= iNumber) // handle wrong input in some way + { + cout << "Not a positive number!!!"; + system ("pause"); + } + else // end error handler + { // let's begin + for (int iOuterCounter=iNumber;iOuterCounter>1;iOuterCounter--) + { // decrement the number and check, if it is a prime (modulo any number is 0) + iIsPrime=0; // we asume actual number is a prime + for (int iInnerCounter=iOuterCounter-1;iInnerCounter>1;iInnerCounter--) + { + if ( 0 == iOuterCounter%iInnerCounter) + { + iIsPrime=1; // actual number is NOT a prime + } + }// end inner for routine + if (0 == iIsPrime) + cout << endl << iOuterCounter; + + } // end outer for routine + cout << endl; + system ("pause"); // wait a moment for user to read + + } // end else + return 0; +}// end main \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp new file mode 100644 index 0000000..b3ac1d9 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_4" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p2_4 - 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 "prg1p2_4.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 "prg1p2_4.mak" CFG="prg1p2_4 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p2_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p2_4 - 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)" == "prg1p2_4 - 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)" == "prg1p2_4 - 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 "prg1p2_4 - Win32 Release" +# Name "prg1p2_4 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1p2_4.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/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsw b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsw new file mode 100644 index 0000000..1d4963a --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.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: "prg1p2_4"=.\prg1p2_4.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp new file mode 100644 index 0000000..0691d20 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp @@ -0,0 +1,73 @@ +// Programmieren 1, Praktikum 2, Aufgabe 5 +// Sven Eisenhauer +// 06.11.2004 +// +// file: prg1p2_5.cpp +// +// purpose: program to reads 2 integers from keyboard and finds all prime number twins +// between them, like 3 and 5 or 17 and 19 +// + +#include +using std::cin; +using std::cout; +using std::endl; + +int main() +{ + int iNumberA, iNumberB; + int iMin, iMax; + int iIsPrime1=0; + int iIsPrime2=0; + int iPrime1=0; + int iPrime2=0; + int iToTest=0; + + cout << "Please enter 1st number: "; + cin >> iNumberA; + cout << "Please enter 2nd number: "; + cin >> iNumberB; + cout << endl; + + // first find out, which is the bigger value. + iMax=iNumberA; + iMin=iNumberB; + + if (iNumberB > iNumberA) + { + iMax=iNumberB; + iMin=iNumberA; + } + // First loop: Get all numbers between the 2 entered + for (int iOuterCounter=iMax-1;iOuterCounter>iMin;iOuterCounter--) + { + iIsPrime1=0; + for (int iInnerCounter=iOuterCounter-1;iInnerCounter>1;iInnerCounter--) + { + if ( 0 == iOuterCounter%iInnerCounter) + iIsPrime1=1; // actual number is NOT a prime + }// end inner for routine + if (0 == iIsPrime1) + { + iPrime1=iOuterCounter; + // now test, if iPrime1 - 2 is a prime + iIsPrime2 = 0; + iToTest = iOuterCounter - 2; + for (int iInnerCounter2=iToTest-1;iInnerCounter2>1;iInnerCounter2--) + { + if (0 == iToTest%iInnerCounter2) + iIsPrime2=1; + } + if (0 == iIsPrime2) + iPrime2=iToTest; + + if ((0 == iIsPrime1) && (0 == iIsPrime2) && (iPrime2 > iMin)) + cout << iPrime1 << "\t" << iPrime2 << endl; + } + // if (iIsPrime1 && iIsPrime2) + // cout << iPrime1 << "\t" << iPrime2 << endl; + } +// system ("pause"); + + return 0; +}// end main diff --git a/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp new file mode 100644 index 0000000..7ad88a6 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_5" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p2_5 - 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 "prg1p2_5.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 "prg1p2_5.mak" CFG="prg1p2_5 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p2_5 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p2_5 - 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)" == "prg1p2_5 - 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)" == "prg1p2_5 - 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 "prg1p2_5 - Win32 Release" +# Name "prg1p2_5 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1p2_5.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/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsw b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsw new file mode 100644 index 0000000..d819093 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.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: "prg1p2_5"=.\prg1p2_5.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp new file mode 100644 index 0000000..70abc04 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp @@ -0,0 +1,59 @@ +// Programmieren 1, Praktikum 2, Aufgabe 6 +// Sven Eisenhauer +// 06.11.2004 +// +// file: prg1p2_6.cpp +// +// purpose: generate a table of bin, oct and hex presentation of the numbers from 1 to 256 +// +// + +#include +#include +#include + +using std::cin; +using std::cout; +using std::endl; +using std::setw; +using std::hex; +using std::dec; + +const int iBit=8; // 256 is 8 bit + +int iDec,iOct,iHex,iBin,iTemp; + +int main() +{ + cout << setw(5) << "Dec" << setw (11) << "Binary" << setw(7) << "Octal" << setw(5) << "Hex" << endl; + + for (int iCounter=1;iCounter<=256;iCounter++) + { + iDec=iCounter; + iTemp=0; + iBin=0; + iOct=0; + // generate binary + for (int iBinC=iBit;iBinC>=0;iBinC--) + { + iTemp = iDec % 2; + iDec = iDec / 2; + iBin += iTemp * static_cast (pow(10,iBit-iBinC)); + + } + // generate octal + iDec=iCounter; + for ( int iOctC=3;iOctC>=0;iOctC--) + { + iTemp = iDec % 8; + iDec = iDec / 8; + iOct += iTemp * static_cast (pow(10,3-iOctC)); + } + cout << setw(5) << dec << iCounter << setw (11) << iBin << setw(7) << iOct << setw(5) << hex << iCounter << endl; + if (!(iCounter%23)) + cout << endl << setw(5) << "Dec" << setw (11) << "Binary" << setw(7) << "Octal" << setw(5) << "Hex" << endl; + } + + + return 0; +}// end main diff --git a/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp new file mode 100644 index 0000000..5958ba3 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_6" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p2_6 - 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 "prg1p2_6.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 "prg1p2_6.mak" CFG="prg1p2_6 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p2_6 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p2_6 - 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)" == "prg1p2_6 - 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)" == "prg1p2_6 - 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 "prg1p2_6 - Win32 Release" +# Name "prg1p2_6 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\prg1p2_6.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/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsw b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsw new file mode 100644 index 0000000..6de9111 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.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: "prg1p2_6"=.\prg1p2_6.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt3/index.htm b/Bachelor/Prog1/Prakt3/index.htm new file mode 100644 index 0000000..367abf1 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/index.htm @@ -0,0 +1,197 @@ + + + + +Praktikum 3 + + + +  + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren I  +
Praktikum
+
+
3
+
+ +
+ + + + +
Ziel: Sie sollen den modularen Programmaufbau mit +Funktionen, die Simulation von Zufallsereignissen und einfache +Rekursion üben.  +
+ +
+ + + + +
+

+1    Verwenden einer einfachen Funktion

+ +
    +
  • +Schreiben Sie eine Funktion, die die Uhrzeit als drei +integer-Argumente übernimmt (hour, +minute, +second) und die Anzahl der Sekunden seit 0 Uhr zurückgibt.
  • + +
  • +Benutzen Sie diese Funktion, um die Zeitspanne in Sekunden zwischen zwei +Zeitpunkten (am gleichen Tag) zu berechnen.
  • +
+
+ +
+ + + + +
+

+2    Einfache Simulation und Analyse von Zufallsereignissen

+ +
    +
  • +Schreiben Sie ein Programm, das simuliert, zwei Würfel 6000mal +zu werfen. 
  • + +
  • +Ergänzen Sie die Simulation um eine Häufigkeitstabelle, die angibt, +wie oft die möglichen Augenzahlen eines Wurfes (2 bis 12) gefallen sind. 
  • +
+
+ +
+ + + + + +
+

+3    Vollkommene Zahlen 

+ +
    +
  • +Eine ganze Zahl wird eine vollkommene Zahl genannt, falls die Summe ihrer +Faktoren (also der Zahlen, durch die die Zahl ohne Rest teilbar ist) gleich der Zahl selbst +ist. Bei der Bildung der Summe wird die 1 eingeschlossen, aber nicht die Zahl +selbst. Zum Beispiel ist 6 eine vollkommene Zahl, denn es gilt 6 = 1 + 2 + 3.
  • + +
  • +Schreiben Sie eine Funktion isPerfect, +die bestimmt, ob ihr Parameter number eine +vollkommene Zahl ist.
  • + +
  • +Benutzen Sie diese Funktion in einem Programm, das alle vollkommenen Zahlen +zwischen 1 und 1000 bestimmt und ausgibt. Geben Sie die Faktoren jeder +vollkommenen Zahl mit aus, damit Ihr Ergebnis besser überprüft werden kann.
  • + +
  • +Fordern Sie die Rechenleistung Ihres Computers, indem Sie Zahlen testen, die +deutlich größer als 1000 sind. 
  • +
+
+ + + +
+ + + + +
+

4    Größter gemeinsamer Teiler - rekursiv

+ +
    +
  • +Der größte gemeinsame Teiler (greatest common divisor: gcd) zweier ganzer Zahlen +x und y ist die größte ganze Zahl, die x und y ohne Rest teilt.
  • + +
  • +Schreiben Sie eine rekursive Funktion gcd, +die den größten gemeinsamen Teiler von x und y zurückgibt. Nutzen Sie +dabei folgende rekursive Beziehung:
  • + +
  • +Falls y gleich 0 ist, dann ist gcd(x,y) +gleich x.
    +Sonst gilt: gcd(x,y) ist +gcd(y,x%y).
  • + +
  • +Testen Sie Ihre Funktion, indem Sie Werte für x und y einlesen und den +zugehörigen größten gemeinsamen Teiler ausgeben.
  • + +
+
+ +
+ + + + +
+

5    Ägyptische Multiplikation (fakultativ)

+ +
    +
  • +Schreiben Sie eine Funktion multIterative, +die das Produkt zweier ganzer Zahlen a und b auf folgende Weise berechnet.
    +Ausgehend von den der Funktion übergebenen Werten a und b wird eine +Reihe von gleichartigen Schritten durchgeführt: +
      +
    • +Falls b ungeradzahlig ist, wird der Wert von a zur Variablen +product +addiert. +
    • +
    • +Danach wird der Wert von +a verdoppelt und der Wert von b halbiert (ohne Rest und +ohne Rundung). +
    • +
    +Diese beiden Schritte werden solange wiederholt, bis b durch die fortlaufende Halbierung den Wert 0 +annimmt. Die in product gebildete Summe +ist dann gleich dem Produkt von a +und b.
  • + +
  • +Hinweis: Realisieren Sie die Verdoppelung von a durch den Operator zur bitweisen +Linksverschiebung << und die Halbierung von b ohne Rest und Rundung durch +den Operator zur bitweisen Rechtsverschiebung >>.
  • + +
  • +Schreiben Sie ein Programm, das zwei ganze Zahlen von der Tastatur einliest und +das mit der Funktion multIterative +berechnete Produkt ausgibt.
  • + +
  • +Schreiben Sie eine zweite Funktion multRecursive, +die die oben beschriebene Verdopplung, Halbierung und Summation durch rekursive +Aufrufe von sich selbst realisiert. Testen Sie auch diese Funktion mit von der +Tastatur eingegebenen Werten.
  • + +
+
+ + \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp new file mode 100644 index 0000000..9c84841 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp @@ -0,0 +1,65 @@ +// Programmieren 1, Praktikum 3, Aufgabe 1 +// Sven Eisenhauer +// 12.11.2004 +// +// file: main.cpp +// +// purpose: read 2 times (hours, minutes, seconds) from keyboard +// calculate seconds between this two times +// uses a function to convert times to seconds +// +// +#include +using std::cin; +using std::cout; +using std::endl; + +int seconds(int, int, int); + +int main() +{ + int hours1, + minutes1, + seconds1, + totalSeconds1, + hours2, + minutes2, + seconds2, + totalSeconds2; + + // read times from keyboard + cout << "Please enter 1st hours (0-24): "; + cin >> hours1; + cout << "Please enter 1st minutes (0-60): "; + cin >> minutes1; + cout << "Please enter 1st seconds (0-60): "; + cin >> seconds1; + + cout << "Please enter 2nd hours (0-24): "; + cin >> hours2; + cout << "Please enter 2nd minutes (0-60): "; + cin >> minutes2; + cout << "Please enter 2nd seconds (0-60): "; + cin >> seconds2; + + // convert to seconds + totalSeconds1=seconds(hours1,minutes1,seconds1); + totalSeconds2=seconds(hours2,minutes2,seconds2); + + cout << endl << "Difference in seconds is: "; + // which is the bigger value and substract the lower one + if (totalSeconds1 > totalSeconds2) + cout << totalSeconds1 - totalSeconds2; + else + cout << totalSeconds2 - totalSeconds1; + + cout << endl; + + return 0; +}// end main + +// function seconds +int seconds (int h, int min, int sec) +{ + return h*3600+min*60+sec; +} // end function seconds \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp new file mode 100644 index 0000000..fc5a7cf --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p3_1 - 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 "prg1p3_1.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 "prg1p3_1.mak" CFG="prg1p3_1 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p3_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p3_1 - 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)" == "prg1p3_1 - 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)" == "prg1p3_1 - 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 "prg1p3_1 - Win32 Release" +# Name "prg1p3_1 - 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/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsw b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsw new file mode 100644 index 0000000..4d304d8 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.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: "prg1p3_1"=.\prg1p3_1.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp new file mode 100644 index 0000000..35796d5 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp @@ -0,0 +1,81 @@ +// Programmieren 1, Praktikum 3, Aufgabe 2 +// Sven Eisenhauer +// 12.11.2004 +// +// file: main.cpp +// +// purpose: roll 2 dice 6000 times and build a table, how often each possible sum occured +// +// +// +// +#include +using std::cin; +using std::cout; +using std::endl; + +#include +#include + +int rollDice(void); + +int main () +{ + int stats[13] = {0}; + + srand(time(0)); + + for (int Counter=0;Counter <= 6000;Counter++) + { + /* switch (rollDice()) + { + case 2: + stats[0]++; + break; + case 3: + stats[1]++; + break; + case 4: + stats[2]++; + break; + case 5: + stats[3]++; + break; + case 6: + stats[4]++; + break; + case 7: + stats[5]++; + break; + case 8: + stats[6]++; + break; + case 9: + stats[7]++; + break; + case 10: + stats[8]++; + break; + case 11: + stats[9]++; + break; + case 12: + stats[10]++; + break; + default: + cout << "Uuups... we should never get here..."; + }*/ + ++stats[rollDice()]; + } + for (int i=2;i<=12;i++) + { + cout << endl << i << ": " << stats[i]; + } + cout << endl; + return 0; +} + +int rollDice(void) +{ + return (( 1 + (rand() % 6)) + ( 1 + (rand() % 6))); +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp new file mode 100644 index 0000000..2d4b338 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p3_2 - 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 "prg1p3_2.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 "prg1p3_2.mak" CFG="prg1p3_2 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p3_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p3_2 - 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)" == "prg1p3_2 - 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)" == "prg1p3_2 - 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 "prg1p3_2 - Win32 Release" +# Name "prg1p3_2 - 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/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsw b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsw new file mode 100644 index 0000000..332d7bf --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.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: "prg1p3_2"=.\prg1p3_2.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp new file mode 100644 index 0000000..c0c9cfc --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp @@ -0,0 +1,57 @@ +// Programmieren 1, Praktikum 3, Aufgabe 3 +// Sven Eisenhauer +// 17.11.2004 +// +// file: main.cpp +// +// purpose: find "perfect numbers": The sum of all integer factors of a number is the number. +// +// +#include +using std::cin; +using std::cout; +using std::endl; + +int isPerfect(int); + +int main() +{ + // how far to search + const int maxNumbers=1000; + + for (int j=1;j<=maxNumbers;j++) + { + if (0 == isPerfect(j)) + { + cout << ": " << j << endl; + } + } + + cout << "\n"; + + return 0; +} + +int isPerfect(int number) +{ + int sum=0; + // check for all numbers between the number, exclusive the number itself and 1 inclusive + for (int i=number-1;i>=1;i--) + { + // is the actual number a factor??? + if (0 == number%i) + // if it is, add it + sum+=i; + } + // the sum of all factors... and so on + if (sum == number) + { + // so we have a perfect number here... fine... find the factors again and cout them + for (int k=number-1;k>=1;k--) + if (0 == number%k) + cout << k << " "; + return 0; + } + else + return 1; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp new file mode 100644 index 0000000..0a8d693 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_3" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p3_3 - 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 "prg1p3_3.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 "prg1p3_3.mak" CFG="prg1p3_3 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p3_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p3_3 - 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)" == "prg1p3_3 - 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)" == "prg1p3_3 - 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 "prg1p3_3 - Win32 Release" +# Name "prg1p3_3 - 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/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsw b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsw new file mode 100644 index 0000000..fd4519a --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.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: "prg1p3_3"=.\prg1p3_3.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp new file mode 100644 index 0000000..d66c34c --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp @@ -0,0 +1,43 @@ +// Programmieren 1, Praktikum 3, Aufgabe 4 +// Sven Eisenhauer +// 17.11.2004 +// +// file: main.cpp +// +// purpose: find the greatest common divisor of two numbers, recursive... +// +// + +#include +using std::cin; +using std::cout; +using std::endl; + +int gcd(int,int); + +int main() +{ + int number1, + number2; + + cout << "1st number: "; + cin >> number1; + cout << "2nd number: "; + cin >> number2; + + cout < +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p3_4 - 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 "prg1p3_4.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 "prg1p3_4.mak" CFG="prg1p3_4 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p3_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p3_4 - 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)" == "prg1p3_4 - 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)" == "prg1p3_4 - 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 "prg1p3_4 - Win32 Release" +# Name "prg1p3_4 - 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/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsw b/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsw new file mode 100644 index 0000000..3b1991e --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.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: "prg1p3_4"=.\prg1p3_4.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp new file mode 100644 index 0000000..03c35e7 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp @@ -0,0 +1,67 @@ +// Programmieren 1, Praktikum 3, Aufgabe 5 +// Sven Eisenhauer +// 17.11.2004 +// +// file: main.cpp +// +// purpose: egypt multiplication +// +// +#include +using std::cin; +using std::cout; +using std::endl; + +int multIterative(int,int); +void multRecursive(int,int, int &); + +int main() +{ + int number1, + number2, + erg; + + cout << "1st number: "; + cin >> number1; + cout << "2nd number: "; + cin >> number2; + + cout << "Product: " << multIterative(number1,number2) << endl; + multRecursive(number1,number2,erg); + cout << "Product: " << erg << endl; + + return 0; +} + +int multIterative(int a,int b) +{ + int product=0; + while (b>0) + { + if (0 != b%2) + product+=a; + + a = a << 1; + b = b >> 1; + } + return product; +} + +void multRecursive(int a,int b, int &product) +{ + int x,y; + + if (b<=1) + product=a; + + else + { + x=a<<1; + y=b>>1; + multRecursive(x,y,product); + if (0!=b%2) + product+=a; + + } + +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp new file mode 100644 index 0000000..5344ee4 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_5" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p3_5 - 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 "prg1p3_5.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 "prg1p3_5.mak" CFG="prg1p3_5 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p3_5 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p3_5 - 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)" == "prg1p3_5 - 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)" == "prg1p3_5 - 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 "prg1p3_5 - Win32 Release" +# Name "prg1p3_5 - 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/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsw b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsw new file mode 100644 index 0000000..6fd9859 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.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: "prg1p3_5"=.\prg1p3_5.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt4/index.htm b/Bachelor/Prog1/Prakt4/index.htm new file mode 100644 index 0000000..6989787 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/index.htm @@ -0,0 +1,253 @@ + + + + + + +Praktikum 4 + + + + +  + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren I  +
Praktikum
+
+
4
+
+ +
+ + + + +
Ziel: + Sie sollen die Verwendung von Arrays, Funktionen und Rekursion üben sowie + grundlegende Sortierverfahren kennen.  +
+ +
+ + + + +
+

+1    Analyse von Craps

+ +
    +
  • +Schreiben Sie ein Programm, das 1000000-mal das Würfelspiel Craps simuliert. +Ihr Programm soll folgende Fragen beantworten:
  • +
      +
    • +Wieviele Spiele werden gewonnen beim ersten Wurf, beim zweiten Wurf, +...(usw)..., beim 20. +Wurf und nach dem 20.Wurf?
    • + +
    • +Wieviele Spiele werden verloren beim ersten Wurf, beim zweiten Wurf, +...(usw)..., beim 20. +Wurf und nach dem 20.Wurf?
    • + +
    • +Wie groß sind die Chancen Craps zu gewinnen? (Sie sollten herausfinden, dass +Craps eines der fairsten in Spielkasinos gespielten Spiele ist. Was bedeutet +diese Aussage?)
    • + +
    • +Wie lang dauert ein Craps-Spiel im Durchschnitt?
    • + +
    • +Erhöhen sich die Gewinnchancen mit der Dauer eines Craps-Spieles?
    • +
    +
+
+ +
+ + + + +
+

+2    Sortierverfahren 'Direkte Auswahl (Selection Sort)' und +'Direktes Einfügen +(Insertion Sort)' 

+ +
    +
  • +Das Sortierverfahren 'Direkte Auswahl' durchsucht ein unsortiertes Array nach dem kleinsten +Element in dem Array. Danach wird das kleinste Element mit dem ersten Element +des Arrays ausgetauscht. Dieser Prozess wird für das unsortierte Teilarray, das mit dem +zweiten Element des Arrays beginnt, wiederholt. Jeder derartige Durchlauf durch +das Array bewirkt, dass ein weiteres Element an die Stelle kommt, an die es +gehört. Sobald das unsortierte Teilarray nur noch ein Element enthält, ist das Array +sortiert.
  • + +
  • +Schreiben Sie eine iterative Funktion selectionSort +für diesen Algorithmus.
  • + +
  • +Das Sortierverfahren 'Direktes Einfügen' fasst das erste Element eines +unsortierten Arrays als bereits sortiertes Teilarray auf, in das sukzessive die +weiteren Elemente eingefügt werden. Bei diesem Einfügeprozess muss das immer +größer werdende Teilarray zu jedem Zeitpunkt sortiert bleiben. Jedes weitere +Element muss also an die richtige Stelle eingefügt werden. Damit dies möglich +ist, müssen alle Elemente, die größer sind als das Einfügeelement, jeweils +um einen Platz verschoben werden. Sobald das sortierte Teilarray alle Elemente enthält, ist das Array +sortiert.
  • + +
  • +Schreiben Sie eine iterative Funktion insertionSort +für diesen Algorithmus.
  • + +
+
+ +
+ + + + +
+

3    Verteilung der Augenzahlen bei Würfen mit vielen +Würfeln 

+ +
    +
  • +Entwickeln Sie ein Programm, das es dem Benutzer ermöglicht, Würfe mit mehreren Würfeln zu simulieren. Das Simulationsergebnis +ist dann eine Gesamt-Augenzahl, die sich als Summe der Augenzahlen der +einzelnen Würfel ergibt. Werden viele dieser Würfe mit mehreren +Würfeln durchgeführt, ergibt sich eine Häufigkeitsverteilung +für die Gesamt-Augenzahlen. Diese Häufigkeitsverteilung soll +im Konsolenfenster in Form einer Tabelle und als einfache Übersichtsgraphik +ausgegeben werden.
  • + +
  • +Zu Beginn sollen vom Benutzer folgende Eingaben abgefragt werden:
  • + +
      +
    • +Die Zahl der Würfel, die er bei einem Wurf werfen möchte.
    • + +
    • +Die Zahl der Würfe, die er mit der gewählten Anzahl von Würfeln +durchführen möchte.
    • +
    + +
  • +Die Häufigkeitsverteilung für die erzielten Gesamt-Augenzahlen +soll auf zwei verschiedene Arten dargestellt werden:
  • + +
      +
    • +Tabellarische Darstellung als Gegenüberstellung von erzielter Augenzahl +und zugehöriger Häufigkeit. Dabei sollen sowohl die Absolutwerte +der Häufigkeit als auch normierte Werte, die sich bei Division der +Absolutwerte durch die Gesamtzahl der Würfe ergeben, ausgegeben werden.
    • + +
    • +Graphische Darstellung als ein einfaches (um 90 Grad gekipptes) Säulendiagramm +(z.B. entsprechende Anzahl von *).
    • +
    + +
  • +Strukturieren Sie Ihr Programm mit Hilfe von geeignet gewählten Funktionen +für einzelne Teilaufgaben. 
  • +
+
+ +
+ + + + +
+

4    Galton-Brett (fakultativ)

+ Entwickeln Sie ein Programm, das ein "Galton-Brett" und dessen Benutzung simuliert. Das + Simulationsergebnis soll im Konsolenfenster in Form von Zahlenkolonnen und als einfache Übersichtsgraphik ausgegeben werden. +

Funktionsprinzip des Galton-Bretts

+ + + + + +
+

Mit Hilfe eines Galton-Bretts (nach Sir Francis + Galton, 1822-1911) lassen sich wichtige Verteilungen aus der + Statistik experimentell erzeugen. Dabei laufen auf einem geneigt + aufgestellten Nagelbrett Kugeln durch die Nagelreihen. In Sammelbehältern am Fuß des Nagelbretts werden die + Kugeln aufgefangen. Sind die Nägel im Brett so angeordnet, daß + der Abstand zweier nebeneinander liegender Nägel durch den darüberliegenden + Nagel genau halbiert wird, so ist als Verteilung der Kugeln in den + Sammelbehältern die Normalverteilung (Gaußsche Glockenkurve) zu + erwarten.

+
+

+

+
+

Darstellung des Simulationsergebnisses

+

Das Ergebnis der Simulation soll durch Angabe der + Anzahl von Kugeln, die in 25 Sammelbehältern jeweils aufgefangen werden, + ausgegeben werden (Funktion textOutput). + Dabei sollen sowohl die Absolutwerte als auch normierte Werte, die sich + bei Division der Absolutwerte durch die Gesamtanzahl der Kugeln ergeben, + ausgegeben werden. Zusätzlich soll durch eine Funktion + graphicalOutput ein + einfaches (um 90 Grad gekipptes) Säulendiagramm (z.B. entsprechende + Anzahl von *) + im Konsolenfenster ausgegeben werden können. + +

+

Die Bedienung des Programms erfolgt im + Konsolenfenster durch Angabe der gewünschten Anzahl von Kugeln und der + gewünschten Darstellungsart des Ergebnisses. Wenn Sie wollen, können Sie + natürlich auch die Anzahl der Sammelbehälter nicht auf genau 25 + beschränken, sondern vom Benutzer des Programms vorgeben lassen.

+
+

Implementierungshinweis

+
+ + + + + +

Es ist Zufall, ob eine + Kugel an einem Nagel nach links oder rechts rollt. Deshalb sollen + Zufallszahlen, die die Funktion + + rand liefert, verwendet werden. Bedenken Sie, dass an jedem Nagel (d.h. auf + jeder Ebene) nur eine Entscheidung (links oder rechts) zu + treffen ist. Mit jeder Ebene, die die Kugel passiert, wird dadurch die + Menge der noch erreichbaren Sammelbehälter sukzessive eingeschränkt. + Dieses Verhalten soll in eine rekursive Funktion abgebildet werden.

+  
+
+

+ +

+
+
+ + + + \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp new file mode 100644 index 0000000..f9e3e90 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp @@ -0,0 +1,148 @@ +// Programmieren 1, Praktikum 4, Aufgabe 1 +// Sven Eisenhauer +// 08.12.2004 +// +// file: main.cpp +// +// purpose: Play craps and analyse results +// +// +// +// + +#include + +using std::cout; +using std::endl; + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include + +#include // contains prototype for function time + +int rollDice( void ); // function prototype + +int main() +{ + // enumeration constants represent game status + enum Status { CONTINUE, WON, LOST }; + + int sum; + int myPoint; + + const int maxGames=1000000; + const int maxRounds=22; + + int round=1, + sumWon=0, + sumLost=0, + wRounds=0; + + int nrLost[maxRounds]={0}, + nrWon[maxRounds]={0}; + + Status gameStatus; // can contain CONTINUE, WON or LOST + + // randomize random number generator using current time + srand( time( 0 ) ); + + for (int i=1;i<=maxGames;i++) + { + round=1; + sum = rollDice(); // first roll of the dice + + // determine game status and point based on sum of dice + switch ( sum ) { + + // win on first roll + case 7: + case 11: + gameStatus = WON; + break; + + // lose on first roll + case 2: + case 3: + case 12: + gameStatus = LOST; + break; + + // remember point + default: + gameStatus = CONTINUE; + myPoint = sum; + // cout << "Point is " << myPoint << endl; + break; // optional + + } // end switch + + // while game not complete ... + while ( gameStatus == CONTINUE ) { + sum = rollDice(); // roll dice again + round++; + + // determine game status + if ( sum == myPoint ) // win by making point + gameStatus = WON; + else + if ( sum == 7 ) // lose by rolling 7 + gameStatus = LOST; + + } // end while + + // display won or lost message + if ( gameStatus == WON ) + //cout << "Player wins" << endl; + if (round (sumWon)/maxGames)*100 << "%" << endl; + cout << "Average Game length: "<< setprecision(2) << static_cast (wRounds)/maxGames << " Rounds" << endl; + + return 0; // indicates successful termination + +} // end main + +// roll dice, calculate sum and display results +int rollDice( void ) +{ + int die1; + int die2; + int workSum; + + die1 = 1 + rand() % 6; // pick random die1 value + die2 = 1 + rand() % 6; // pick random die2 value + workSum = die1 + die2; // sum die1 and die2 + + // display results of this roll + // cout << "Player rolled " << die1 << " + " << die2 + // << " = " << workSum << endl; + + return workSum; // return sum of dice + +} // end function rollDice diff --git a/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp new file mode 100644 index 0000000..d954bb5 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p4_1 - 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 "prg1p4_1.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 "prg1p4_1.mak" CFG="prg1p4_1 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p4_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p4_1 - 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)" == "prg1p4_1 - 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)" == "prg1p4_1 - 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 "prg1p4_1 - Win32 Release" +# Name "prg1p4_1 - 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/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsw b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsw new file mode 100644 index 0000000..4b8cd6b --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.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: "prg1p4_1"=.\prg1p4_1.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp new file mode 100644 index 0000000..6c30139 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp @@ -0,0 +1,123 @@ +// Programmieren 1, Praktikum 4, Aufgabe 2 +// Sven Eisenhauer +// 08.12.2004 +// +// file: main.cpp +// +// purpose: Implementation of Selection Sort and Insertion Sort algorithm +// + +#include + +using std::cout; +using std::endl; + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include + +#include + +void selectionSort(int[], int); +void insertionSort(int[], int); + +int main () +{ + const int arraySize=5; + int array1[arraySize],array2[arraySize]; + + srand(time(0)); + + // fill the arrays with some random stuff + for (int i=0;i= 0)) + { + // always copy the value from the array field before + // so the gap "walks" to the left, until a[i] is at the right place + // and we can put temp in it. + a[i+1]=a[i]; + i--; + } + // i+1 to compensate the last i--, because we want a[i] before the last i-- + a[i+1]=temp; + } + + } +} // end function insertionSort \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp new file mode 100644 index 0000000..954904e --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p4_2 - 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 "prg1p4_2.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 "prg1p4_2.mak" CFG="prg1p4_2 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p4_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p4_2 - 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)" == "prg1p4_2 - 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)" == "prg1p4_2 - 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 "prg1p4_2 - Win32 Release" +# Name "prg1p4_2 - 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/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsw b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsw new file mode 100644 index 0000000..fe3d2a4 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.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: "prg1p4_2"=.\prg1p4_2.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp new file mode 100644 index 0000000..fb7e564 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp @@ -0,0 +1,102 @@ +// Programmieren 1, Praktikum 4, Aufgabe 3 +// Sven Eisenhauer +// 14.12.2004 +// +// file: main.cpp +// +// purpose: Analyse multiple rolls of multiple dice +// + +#include + +using std::cin; +using std::cout; +using std::endl; + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include + +#include + +void roll(const int, const int, int[]); +void getPara(int &, int &); +void printResultTbl(const int[], const int, const int); +void printResultGrph(const int[], const int, const int); + +const int maxDice=20, + maxEyes=6, + minEyes=1; + +int main() +{ + + + int nrDice, + nrRolls; + + int result[(maxDice*maxEyes)+1]={0}; + + // initialize random number generator + srand(time(0)); + + getPara(nrDice,nrRolls); + + roll(nrDice,nrRolls,result); + + printResultTbl(result, nrDice, nrRolls); + printResultGrph(result, nrDice, nrRolls); + + return 0; +}// end main + +void getPara(int &nrDice,int &nrRolls) +{ + cout << "Please enter number of dice to roll (max. "<> nrDice; + cout << "Please enter number of rolls: "; + cin >> nrRolls; +} // end function getPara + +void roll (const int nDice, const int nrRolls, int resultArray[]) +{ + int sum; + + for (int n=1;n<=nrRolls;n++) + { + sum=0; + for (int i=1;i<=nDice;i++) + sum+=(rand()%6)+1; + ++resultArray[sum]; + } + +} // end fnction roll + +void printResultTbl(const int resArray[],const int nrDice, const int nrRolls) +{ + cout << setw(5) << "Sum" << setw(12) << "Frequency" << setw(20) << "norm. Frequency"<< endl; + + for (int n=(nrDice*minEyes);n<=(nrDice*maxEyes);n++) + { + cout << setw(5) << n << setw(12) << resArray[n] << setprecision(2)<< setw(20) << (static_cast (resArray[n]))/nrRolls << endl; + } +}// end function printResultTbl + +void printResultGrph(const int resArray[],const int nrDice, const int nrRolls) +{ + cout << endl; + + const int maxColumns=75; + + for (int n=(nrDice*minEyes);n<=(nrDice*maxEyes);n++) + { + cout << setw(2) << n << ": "; + for (int i=0;i(((static_cast (resArray[n]))/nrRolls)*maxColumns);i++) + cout<<"*"; + cout << endl; + } +}// end function printResultGrph \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp new file mode 100644 index 0000000..ba2f06a --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_3" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p4_3 - 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 "prg1p4_3.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 "prg1p4_3.mak" CFG="prg1p4_3 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p4_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p4_3 - 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)" == "prg1p4_3 - 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)" == "prg1p4_3 - 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 "prg1p4_3 - Win32 Release" +# Name "prg1p4_3 - 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/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw new file mode 100644 index 0000000..b24236f --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.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: "prg1p4_3"=.\prg1p4_3.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp new file mode 100644 index 0000000..8f481ff --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp @@ -0,0 +1,122 @@ +// Programmieren 1, Praktikum 4, Aufgabe 4 +// Sven Eisenhauer +// 14.12.2004 +// +// file: main.cpp +// +// purpose: Simulate a Galton Board +// + +#include + +using std::cin; +using std::cout; +using std::endl; + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include + +#include + +const int maxBoxes=100; +const int minBoxes=1; + +int fall(int &,int &); +void getInput(int &,int &, char &); +void textOutput(int[], const int, const int); +void graphicalOutput(int[], const int, const int); + +int main() +{ + srand(time(0)); + + int nrBalls; + int minBox,maxBox,nrBox; + int box; + int result[maxBoxes+1]={0}; + char outputMode; + + getInput(nrBalls,nrBox,outputMode); + for (int i=1;i<=nrBalls;i++) + { + minBox=minBoxes; + maxBox=nrBox; + box=fall(minBox,maxBox); + result[box]++; + } + if (outputMode=='t' || outputMode=='T') + textOutput(result,nrBalls,nrBox); + else + graphicalOutput(result,nrBalls,nrBox); + + return 0; +}// end function main + +void getInput(int& nrBa, int& nrBo, char &outpMode) +{ + cout << "Please enter number of boxes (max." << maxBoxes <<"): "; + cin>>nrBo; + cout << "Please enter number of balls: "; + cin>>nrBa; + cout << "Please enter output mode: [T/t] table, [G/g] graphical: "; + cin >> outpMode; +}// end function getInput + +int fall(int &minB, int &maxB) +{ + // if we are not over last 2 boxes + if((maxB-minB)>1) + { + if (0==rand()%2) + // ball falls to the right => we cannot reach the most left box anymore + minB++; + else + // ball falls to the left => we cannot reach the most right box anymore + maxB--; + fall(minB,maxB); + //return 0; + } + // only 2 possible boxes left... the base case + else + { + if (0==rand()%2) + // left box + return minB; + else + // right box + return maxB; + } +} + +void textOutput(int resArray[], const int balls,const int nrBox) +{ + //int sum=0; + + cout << endl << setw(10) << "Box" << setw(10) << "Balls" << setw(16) << "Norm." <(resArray[n])/balls<(((static_cast (resArray[n]))/balls)*maxColumns);i++) + cout<<"*"; + cout << endl; + + + } +}// end function graphicalOutput diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp new file mode 100644 index 0000000..760be15 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_4" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p4_4 - 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 "prg1p4_4.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 "prg1p4_4.mak" CFG="prg1p4_4 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p4_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p4_4 - 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)" == "prg1p4_4 - 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)" == "prg1p4_4 - 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 "prg1p4_4 - Win32 Release" +# Name "prg1p4_4 - 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/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw new file mode 100644 index 0000000..85399da --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.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: "prg1p4_4"=.\prg1p4_4.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt5/index.htm b/Bachelor/Prog1/Prakt5/index.htm new file mode 100644 index 0000000..a96b249 --- /dev/null +++ b/Bachelor/Prog1/Prakt5/index.htm @@ -0,0 +1,414 @@ + + + + + + +Praktikum 5 + + + + +  + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren I  +
Praktikum
+
+
5
+
+ +
+ + + + +
Ziel: + Sie sollen die Verwendung von Zeigern, Arrays, Funktionen und Rekursion üben + sowie das Sortierverfahren Quicksort und einen Backtrackingalgorithmus + realisieren.  +
+ +
+ + + + +
+

+1    Verbesserter Misch- und Gebe-Algorithmus

+
    +
  • +Im Kartenmisch- und -gebeprogramm der Vorlesung wurde ein ineffizienter +Mischalgorithmus verwendet, bei dem es nicht garantiert war, dass er in einer +bestimmten Zeit abgeschlossen ist. Dieser Algorithmus soll verbessert werden.
  • + +
  • +Initialisieren Sie das deck Array wie folgt: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
     0123456789101112
    012345678910111213
    114151617181920212223242526
    227282930313233343536373839
    340414243444546474849505152
    +
    +
  • + +
  • +Modifizieren Sie die shuffle Funktion so, +dass sie Zeile für Zeile und Spalte für Spalte durch das Array läuft und +jedes Element einmal bearbeitet: Jedes Element soll mit einem zufällig +ausgewählten Element des Arrays vertauscht werden. Die shuffle +Funktion soll so oft ausgeführt werden, bis das Blatt gut gemischt ist. +Überprüfen Sie dies durch Ausdrucken des Arrays.
  • + +
  • +Optimieren Sie zusätzlich auch den Gebe-Algorithmus in der deal +Funktion: Sobald eine Karte ausgegeben ist, soll nicht weiter nach der Nummer +dieser Karte gesucht werden, sondern das Programm soll sofort mit dem Geben der +nächsten Karte fortfahren.
  • + +
+ +
+ +
+ + + + +
+

+2    Sortierverfahren 'Quicksort'

+ +
    +
  • +Das rekursive Sortierverfahren 'Quicksort' besteht aus zwei Schritten: +
      +
    • + +Partitionierungsschritt: Nimm das erste Element des unsortierten Arrays +('Partitionierungselement') und bestimme seine endgültige Position im sortierten Array (d.h. alle Werte +links des Elementes sind kleiner und alle Werte rechts des Elementes sind +größer). Ergebnis dieses Schrittes ist ein Element an der richtigen Position +und zwei unsortierte Teilarrays. +
    • + +
    • +Rekursionschritt: Führe den Partitionierungsschritt für jedes +unsortierte Teilarray aus, solange, bis die Teilarrays nur noch aus einem +Element bestehen.
    • + +
    +
  • Die Bestimmung der endgültigen Position des Partitionierungselementes im + Partitionierungsschritt läuft folgendermaßen ab: +
      +
    • + +Beginnend beim letzten Element des Arrays wird das erste Element gesucht, das +kleiner als das Partitionierungselement ist und dieses wird mit dem +Partitionierungselement vertauscht: + + + + + + + + + + + + + +
      3726489810126845
      +führt also zu + + + + + + + + + + + + + +
      1226489810376845
      + +
    • +
    • +Nun wird von links aus (aber ohne das bereits behandelte Element 12) das erste +Element gesucht, das größer als das Partitionierungselement ist und dieses wird mit dem +Partitionierungselement vertauscht: + + + + + + + + + + + + + +
      1226437810896845
      +
    • +
    • + +Wieder von rechts, aber beginnend mit dem Element vor dem gerade behandelten +Element 89 wird das erste Element gesucht, das +kleiner als das Partitionierungselement ist und dieses wird mit dem +Partitionierungselement vertauscht: + + + + + + + + + + + + + +
      1226410837896845
      +
    • +
    • + +Wieder von links, aber beginnend mit dem Element hinter dem gerade behandelten +Element 10 wird das erste +Element gesucht, das größer als das Partitionierungselement ist. Es wird keins +mehr gefunden, so dass beim Vergleich von 37 mit sich selbst die +endgültige Position von 37 fest steht. + +
    +
  • Schreiben Sie eine rekursive Funktion quickSort, + die ein Array mit 100 zufälligen int-Werten (aus dem Bereich von 1 bis 1000) sortiert. Die Funktion soll als Argumente + das int-Array, einen Anfangsindex und einen Endindex erhalten. Eine Funktion partition + soll von quickSort zur Durchführung + des + Partitionierungsschritts aufgerufen werden.
  • +
+
+ +
+ + + + +
+

+3    Labyrinth (Backtracking)

+
    + +
  • +Folgendes Gitter aus Kreuzen(#), +Leerstellen( ) und Punkten(.) stellt ein Labyrinth in Form eines +doppelt indizierten Arrays dar: +
    +
    +..............
    +.############.
    +.#   #      #.
    +.  # # #### #.
    +.### #    # #.
    +.     ### #  .
    +.#### # # # #.
    +.#  # # # # #.
    +.## # # # # #.
    +.#        # #.
    +.###### ### #.
    +.#      #   #.
    +.######## ###.
    +..............
    +
    +
    +In dem doppelt indizierten Array repräsentieren die Kreuze die Mauern des +Labyrinths, die Leerstellen die möglichen Wege durch das Labyrinth und die Punkte +die Welt außerhalb des Labyrinths. Man kann also +nur zu einem Ort im Array 'laufen', der eine Leerstelle enthält und man hat +einen Ausgang gefunden, sobald man auf einen Punkt trifft. +
  • + +
  • +Schreiben Sie eine rekursive Funktion mazeTraverse +zum Durchlaufen des Labyrinths. Die Funktion soll als Argumente ein 14mal14 +char-Array +für das Labyrinth und außerdem die Koordinaten für einen Ort innerhalb des +Labyrinths (beim ersten Aufruf der Eingang) übernehmen. Während +mazeTraverse versucht, den Ausgang aus dem Labyrinth zu finden, soll +jede Leerstelle auf dem gelaufenen Weg durch ein x +ersetzt werden. Die Funktion soll das Labyrinth bei jedem Schritt ausgeben, so +dass der Nutzer des Programms zusehen kann, wie das Labyrinth durchlaufen wird. +Die Anzahl der gefundenen Ausgänge soll mitgezählt werden und jeder Ausgang +mit seiner laufenden Nummer gekennzeichnet werden.
  • + +
  • +Hinweis: Von einem gegebenen Ort im Labyrinth kann man versuchen nach rechts, +unten, links oder oben weiterzulaufen. Jeder dieser Versuche wird durch einen +rekursiven Aufruf von +mazeTraverse realisiert. Ist ein Weiterlaufen möglich, folgt der +nächste rekursive Aufruf. Wird hingegen ein Ort erreicht, von dem aus kein +Weiterlaufen mehr möglich ist, wird eine Rekursionsstufe zurückgenommen. Dies +hat den Effekt, dass von einem früher erreichten Ort eine neue Möglichkeit des +Weiterkommens ausprobiert wird. Einen solchen Algorithmus bezeichnet man als +'Backtracking'.
  • + +
+ +
+ +
+ + + + + +
+

4    Geben und Beurteilen eines Pokerblatts + (fakultativ) +

+ +
    +
  • +Modifizieren Sie das Kartenmisch- und -gebeprogramm der Vorlesung, so dass ein +Pokerblatt mit fünf Karten gegeben wird. Schreiben Sie zusätzliche Funktionen, +die folgendes leisten: +
      + +
    • Bestimmen, ob das Blatt 'One pair' (z.B. 2 Buben) enthält.
    • +
    • Bestimmen, ob das Blatt 'Two pair' enthält.
    • + +
    • +Bestimmen, ob das Blatt 'Three-of-a-kind' (z.B. 3 Damen) enthält.
    • + +
    • +Bestimmen, ob das Blatt 'Straight' (5 direkt aufeinander folgende Karten +beliebiger Farbe) +enthält.
    • + +
    • +Bestimmen, ob das Blatt 'Flush' (5 Karten der gleichen Farbe) enthält.
    • + +
    • +Bestimmen, ob das Blatt 'Full house' ('One pair' + 'Three of a kind') enthält. 
    • + +
    • +Bestimmen, ob das Blatt 'Four-of-a-kind' (z.B. 4 Asse) enthält.
    • + +
    • +Bestimmen, ob das Blatt 'Straight flush' (5 direkt aufeinander folgende Karten +einer Farbe) +enthält.
    • + +
    • +Bestimmen, ob das Blatt 'Royal flush' (Zehn, Bube, Dame, König, Ass in einer +Farbe) +enthält.
    • +
    +
  • Wie oft erhalten Sie die angegebenen Pokerblätter von 'One pair' bis + 'Royal flush', wenn Sie 1000 Blätter geben lassen? Wie oft, wenn Sie eine + Million Blätter (oder mehr) geben lassen? Bestätigen Ihre Ergebnisse die + Tatsache, dass die angegebenen neun Blätter von oben nach unten als zunehmend + besser gewertet werden?
  • +
  • Anmerkung: Um realistischere Ergebnisse zu erhalten, können Sie die Aufgabe + auch in der folgenden Variante bearbeiten ('Seven-card stud'): Der Spieler + erhält sieben Karten, aus denen er sich sein Blatt mit fünf Karten + zusammenstellt.
  • +
+ + + \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp new file mode 100644 index 0000000..61644cc --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp @@ -0,0 +1,124 @@ +// Programmieren 1, Praktikum 5, Aufgabe 1 +// Sven Eisenhauer +// 16.12.2004 +// +// file: main.cpp +// +// purpose: Shuffle a standard deck of 52 cards and deal them +// + +#include + +using std::cin; +using std::cout; +using std::endl; +using std::left; +using std::right; + + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include +#include + +const int maxColumns=13; +const int maxRows=4; +const int maxCards=52; + +// prototypes +void shuffle( int [][ maxColumns ] ); +void deal( const int [][ maxColumns ], const char *[], const char *[] ); + + + +int main() +{ + // initialize suit array + const char *suit[ 4 ] = + { "Hearts", "Diamonds", "Clubs", "Spades" }; + + // initialize face array + const char *face[ 13 ] = + { "Ace", "Deuce", "Three", "Four", + "Five", "Six", "Seven", "Eight", + "Nine", "Ten", "Jack", "Queen", "King" }; + + // initialize deck array + int deck[ maxRows ][ maxColumns ] = + { + { 1,2,3,4,5,6,7,8,9,10,11,12,13 }, + { 14,15,16,17,18,19,20,21,22,23,24,25,26 }, + { 27,28,29,30,31,32,33,34,35,36,37,38,39 }, + { 40,41,42,43,44,45,46,47,48,49,50,51,52 } + }; + + srand( time( 0 ) ); // seed random number generator + + shuffle( deck ); + deal( deck, face, suit ); + + return 0; // indicates successful termination + +} // end main + +// shuffle cards in deck +void shuffle( int wDeck[][ 13 ] ) +{ + int temp=0; + int randRow, + randCol; + + for (int column=0;column +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p5_1 - 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 "prg1p5_1.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 "prg1p5_1.mak" CFG="prg1p5_1 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p5_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p5_1 - 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)" == "prg1p5_1 - 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)" == "prg1p5_1 - 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 "prg1p5_1 - Win32 Release" +# Name "prg1p5_1 - 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/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsw b/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsw new file mode 100644 index 0000000..08dce0d --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.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: "prg1p5_1"=.\prg1p5_1.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp new file mode 100644 index 0000000..5d5b74e --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp @@ -0,0 +1,178 @@ +// Programmieren 1, Praktikum 5, Aufgabe 2 +// Sven Eisenhauer +// 16.12.2004 +// +// file: main.cpp +// +// purpose: QuickSort algorithm +// + +#include + +using std::cin; +using std::cout; +using std::endl; + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include + +#include + +// constant definitions +const int arraySize=100; // number of array elements +const int maxNum=1000; // max. Number in Array plus 1 +const int arrayStart=0; // first array element +const int arrayEnd=arraySize-1; // last array element + +// function prototypes +void quickSort(int [],int,int); +int partition(int [], int,int,int&); +void swapRight(int [], int &,int &, int &, int &, int &); +void swapLeft(int [], int&,int &, int&, int &, int &); + +int main() +{ + int array[arraySize]; + + // initialize random number generator + srand(time(0)); + + // generate array with random content + for (int i=0;i start) + // now sort lower part + quickSort(toSort,start,pos-1); + if (pos < end) + // and higher part + quickSort(toSort,pos+1,end); +}// end function quicksort + +int partition(int array[],int start, int end, int &pos) +{ + int loop=0; + int foundL,foundR; + int newStart=start; + int newEnd=end; + int nextStart=start; + + pos=start; + + do { + foundR=0; + foundL=0; + // decide whether to search from left or right + // 0: right, 1: left + if (0==(loop%2)) { + swapRight(array,newEnd,newStart,nextStart,pos,foundR); + // set newStart for the next call of a swap fct. + newStart=nextStart; + /*cout << endl << " right "<< loop << " "<< endl; + for (int j=0;j<=end;j++) + cout << setw(4) << array[j]; + cout << endl;*/ + } + else { + swapLeft(array,newEnd,newStart,nextStart,pos,foundL); + // set newStart for the next call of a swap fct. + newStart=nextStart; + /*cout << endl << " left "<< loop << " "<< endl; + for (int j=0;j<=end;j++) + cout << setw(4) << array[j]; + cout << endl;*/ + } + loop++; + } while (((1==foundL)||(1==foundR))); + + return 0; +}// end function partition + +void swapRight(int arr[], int &end,int &newStart,int &nextStart, int &pos, int &found) +{ + int i,temp; + // here we start to walk through array, from RIGHT!!! + i=end; + // newStart is the beginning of the area to check of the array + // when newStart==pos (which is the position of we element, which we order at the moment) + // this means: we are done here! + while((i>=newStart)&&(i!=pos)) { + // if we have found a smaller value, when searching from right + if (arr[i]<=arr[pos]) { + // swap the values + temp=arr[i]; + arr[i]=arr[pos]; + arr[pos]=temp; + // now set the next Start of search from left to one field right of + // the element, we currently searched and swapped + nextStart=newStart+1; + // in i is the actual position of the element which should be ordered + // we should not forget this and tell this the place, from where we were called + pos=i; + // YES!!! we found a smaller value by searching from right + found=1; + break; + } + i--; + } +}// end function swapRight + +void swapLeft(int arr[], int &end,int &newStart,int &nextStart, int &pos, int &found) +{ + int i,temp; + // here we start to walk through array, from LEFT!!! + i=newStart; + // newStart is the beginning of the area to check of the array + // when newStart==pos (which is the position of we element, which we order at the moment) + // this means: we are done here! + while((i<=end)&&(i!=pos)) { + // if we have found a bigger value, when searching from left + if (arr[i]>arr[pos]) { + // swap the values + temp=arr[i]; + arr[i]=arr[pos]; + arr[pos]=temp; + // now set the next Start of search from right to one field left of + // the element, we currently searched and swapped + nextStart=newStart-1; + // in i is the actual position of the element which should be ordered + // we should not forget this and tell this the place, from where we were called + pos=i; + // YES!!! we found a smaller value by searching from right + found=1; + break; + } + i++; + } +}// end function swapLeft \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp new file mode 100644 index 0000000..8d19b08 --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p5_2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p5_2 - 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 "prg1p5_2.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 "prg1p5_2.mak" CFG="prg1p5_2 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p5_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p5_2 - 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)" == "prg1p5_2 - 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)" == "prg1p5_2 - 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 "prg1p5_2 - Win32 Release" +# Name "prg1p5_2 - 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/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsw b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsw new file mode 100644 index 0000000..b0380fc --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.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: "prg1p5_2"=.\prg1p5_2.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp new file mode 100644 index 0000000..b99a0ab --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp @@ -0,0 +1,128 @@ +// Programmieren 1, Praktikum 5, Aufgabe 3 +// Sven Eisenhauer +// 10.01.2005 +// +// file: main.cpp +// +// purpose: Find all exists of a given maze +// + +#include + +using std::cin; +using std::cout; +using std::endl; + +// contains function prototypes for functions srand and rand +#include + +// constant definitions +const int maxLines=14; +const int maxRows=14; +const int startRow=1; +const int startLine=3; + +//function prototypes +//void mazePrint(const char[][maxRows], const int); +void mazePrint(const char[][maxRows]); +void mazeTraverse(char [][maxRows],int,int,int&); + +int main () +{ + int exitCount=0; + + char maze[maxLines][maxRows] = + { + {'.','.','.','.','.','.','.','.','.','.','.','.','.','.'}, + {'.','#','#','#','#','#','#','#','#','#','#','#','#','.'}, + {'.','#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#','.'}, + {'.',' ',' ','#',' ','#',' ','#','#','#','#',' ','#','.'}, + {'.','#','#','#',' ','#',' ',' ',' ',' ','#',' ','#','.'}, + {'.',' ',' ',' ',' ',' ','#','#','#',' ','#',' ',' ','.'}, + {'.','#','#','#','#',' ','#',' ','#',' ','#',' ','#','.'}, + {'.','#',' ',' ','#',' ','#',' ','#',' ','#',' ','#','.'}, + {'.','#','#',' ','#',' ','#',' ','#',' ','#',' ','#','.'}, + {'.','#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#','.'}, + {'.','#','#','#','#','#','#',' ','#','#','#',' ','#','.'}, + {'.','#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#','.'}, + {'.','#','#','#','#','#','#','#','#',' ','#','#','#','.'}, + {'.','.','.','.','.','.','.','.','.','.','.','.','.','.'} + }; + + mazeTraverse(maze,startRow,startLine,exitCount); + + cout << "\nNumber of Exits: " << exitCount << endl; + + return 0; +} + +void mazeTraverse(char laby[][maxRows],int x,int y,int &count) +{ + char temp=' '; + + if (x < maxLines && y < maxRows && x > 0 && y > 0) + { + + if (laby[y][x] == ' ') + laby[y][x] = 'x'; + + if (laby[y+1][x] == '.') + { + count++; + itoa(count,&temp,10); + laby[y+1][x]=temp; + } + if (laby[y][x+1] == '.') + { + count++; + itoa(count,&temp,10); + laby[y][x+1]=temp; + } + if (laby[y-1][x] == '.') + { + count++; + itoa(count,&temp,10); + laby[y-1][x]=temp; + } + if (laby[y][x-1] == '.') + { + count++; + itoa(count,&temp,10); + laby[y][x-1]=temp; + } + + //mazePrint(laby,count); + mazePrint(laby); + + if (laby[y+1][x] == ' ') + mazeTraverse(laby,x,y+1,count); + + + if (laby[y][x+1] == ' ') + mazeTraverse(laby,x+1,y,count); + + + if (laby[y-1][x] == ' ') + mazeTraverse(laby,x,y-1,count); + + + if (laby[y][x-1] == ' ') + mazeTraverse(laby,x-1,y,count); + + } + +} + +void mazePrint(const char array[][maxRows]) +//void mazePrint(const char array[][maxRows],const int count) +{ + system ("cls"); + for (int i=0;i +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p5_3 - 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 "prg1p5_3.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 "prg1p5_3.mak" CFG="prg1p5_3 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p5_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p5_3 - 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)" == "prg1p5_3 - 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)" == "prg1p5_3 - 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 "prg1p5_3 - Win32 Release" +# Name "prg1p5_3 - 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/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsw b/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsw new file mode 100644 index 0000000..5abecf4 --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.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: "prg1p5_3"=.\prg1p5_3.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp new file mode 100644 index 0000000..260ff9c --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp @@ -0,0 +1,438 @@ +// Programmieren 1, Praktikum 5, Aufgabe 4 +// Sven Eisenhauer +// 10.01.2005 +// +// file: main.cpp +// +// purpose: Shuffle a standard deck of 52 cards, deal a poker game and analyse the cards of the player +// + +#include + +using std::cin; +using std::cout; +using std::endl; +using std::left; +using std::right; + + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include +#include + +const int maxColumns=13; +const int maxRows=4; +const int maxCards=52; +const int cards=7; +const int maxResults=10; +const int nrGames=1000000; + +struct hand { + const char *farbe; + const char *wert; +}; + + +// prototypes +void shuffle( int [][ maxColumns ] ); +void deal( const int [][ maxColumns ], const char *[], const char *[], hand[] ); +void printHand(const hand []); +void analyseCards(const hand[], const char *[], const char *[],int[],const char *[]); +void printResults(const int[],const char *[]); + +int onePair(const hand[], const char *[]); +int twoPairs(const hand[], const char *[]); +int threeOfAKind(const hand[], const char *[]); +int straight(const hand[], const char *[]); +int flush(const hand[], const char *[]); +int fullHouse(const hand[], const char *[]); +int fourOfAKind(const hand[], const char *[]); +int straightFlush(const hand[], const char *[], const char *[]); +int royalFlush(const hand[], const char *[], const char *[]); + +int main() +{ + hand blatt[cards]; + + int erg[maxResults]={0}; + + const char *results[maxResults] = + { "Nothing","One Pair","Two Pairs","Three of a kind", + "Straight","Flush","Full house","Four of a kind", + "Straight Flush","Royal Flush" }; + + // initialize suit array + const char *suit[ 4 ] = + { "Hearts", "Diamonds", "Clubs", "Spades" }; + + // initialize face array + const char *face[ 13 ] = + { "Ace", "Deuce", "Three", "Four", + "Five", "Six", "Seven", "Eight", + "Nine", "Ten", "Jack", "Queen", "King" }; + + // initialize deck array + int deck[ maxRows ][ maxColumns ] = + { + { 1,2,3,4,5,6,7,8,9,10,11,12,13 }, + { 14,15,16,17,18,19,20,21,22,23,24,25,26 }, + { 27,28,29,30,31,32,33,34,35,36,37,38,39 }, + { 40,41,42,43,44,45,46,47,48,49,50,51,52 } + }; + + srand( time( 0 ) ); // seed random number generator + + for (int n=1;n<=nrGames;n++) + { + shuffle( deck ); + deal( deck, face, suit, blatt ); + //printHand(blatt); + analyseCards(blatt,face,suit,erg,results); + } + printResults(erg,results); + + return 0; // indicates successful termination + +} // end main + +void printHand(const hand blatt[]) +{ + cout << endl << endl << "Player's cards:" << endl; + for (int i=0;i +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p5_4 - 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 "prg1p5_4.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 "prg1p5_4.mak" CFG="prg1p5_4 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p5_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p5_4 - 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)" == "prg1p5_4 - 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)" == "prg1p5_4 - 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 "prg1p5_4 - Win32 Release" +# Name "prg1p5_4 - 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/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsw b/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsw new file mode 100644 index 0000000..a01539b --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.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: "prg1p5_4"=.\prg1p5_4.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt6.zip b/Bachelor/Prog1/Prakt6.zip new file mode 100644 index 0000000..805d968 Binary files /dev/null and b/Bachelor/Prog1/Prakt6.zip differ diff --git a/Bachelor/Prog1/Prakt6/index.htm b/Bachelor/Prog1/Prakt6/index.htm new file mode 100644 index 0000000..03c361b --- /dev/null +++ b/Bachelor/Prog1/Prakt6/index.htm @@ -0,0 +1,249 @@ + + + + + + +Praktikum 6 + + + + + + + + + + + + + + +
 
FH Darmstadt  +
FB Informatik  +
Prof.Dr. H.P.Weber
+
Programmieren I  +
Praktikum
+
+
6
+
+ +
+ + + + +
Ziel: +Sie sollen problemangepasste Datentypen als Klassen entwerfen und ein + Anwendungsprogramm als System aus Objekten implementieren können.  +
+ +
+ + + + + + + + + + + + + +
+

+1    Erwärmen eines Tiefkühlgerichts in einer Mikrowelle + +

+ +Realisieren Sie eine Klasse Microwave sowie eine Klasse FrozenMeal:  +
+ + + + + + + + + + + + +
+
Microwave
+
- power : int  +
- volume : int +
- period : double
Constructor(a certain volume)  +
Destructor() +
+ morePower() : void +
+ lessPower() : void +
+ setPeriod(a certain period) : void  +
+ heatMeal(a certain FrozenMeal) : void +
+ getPower() : int +
+ getPeriod() : double
+
+ + + + + + + + + + + + +
+
FrozenMeal
+
- name : char* (or string) +
- volume : int +
- temperature : double +
- coeffizient : double
Constructor(a certain name, a certain volume)  +
Destructor() +
+ changeTemperature(a certain temperature) : void +
+ getName() : char* (or string) +
+ getVolume() : int +
+ getCoeffizient() : double +
+ getTemperature() : double
+
+
+Besonderheiten der Methoden sind: +
    +
  • +Durch morePower() und lessPower() soll die Leistung im Bereich +von minimal 200 W bis maximal 1000 W in Schritten von 200 W geändert +werden.
  • + +
  • +Das Erwärmen eines Gerichtes wird durch folgenden Zusammenhang beschrieben:
    +Temperatur = Anfangstemperatur + ( Koeffizient * Leistung * Zeitdauer +/ Volumen)
  • + +
  • +Als Erwärmungskoeffizient soll der Wert für Wasser verwendet +werden: Koeffizient = 0.24 cm3 * Grad / Ws.
  • + +
  • +Achten Sie auf die Einheiten: am einfachsten ist es, wenn Volumen von Mikrowelle +und Tiefkühlgericht in cm3 vom Anwendungsprogramm übernommen +werden.
  • + +
  • +Beim Erzeugen soll ein Tiefkühlgericht eine Temperatur von -18 Grad +haben.
  • + +
  • +Die Destruktoren sollen den Endzustand des jeweiligen Objektes am Bildschirm +ausgeben.
  • + +
  • +Keine Methode der beiden Klassen liest irgendwelche Daten von Tastatur ein oder +gibt etwas auf den Bildschirm aus. Dafür ist allein das Anwendungsprogramm +zuständig.
  • +
+

Realisieren Sie zum Testen Ihrer Klassen ein Anwendungsprogramm, das mit verschiedenen +Tiefkühlgerichten und einer geeigneten Mikrowelle die vorhandenen Methoden benutzt. +

+ +
+ + + + + +
+

+2    Tic-Tac-Toe

+ +

Entwickeln Sie einen Datentyp TicTacToe, +der es ermöglicht ein vollständiges Programm zum Spielen von Tic-Tac-Toe zu +schreiben. +

    +
  • Die Klasse TicTacToe soll als private + Attribut + ein char-Array mit neun Elementen enthalten. +
  • +
  • +Der Konstruktor soll ein leeres Spielfeld initialisieren. +
  • +
  • +Die public Methode playOneGame +soll den Ablauf eines Tic-Tac-Toe-Spieles realisieren. Dabei soll sie +verschiedene private Methoden aufrufen, +die die verschiedenen Teilaufgaben während des Spielablaufs (Eingaben, +Ausgaben, Ermitteln eines Siegers, Realisierung einer Strategie für die +Computerzüge) erledigen. +
  • +
  • +Das Spiel soll für zwei Spieler realisiert werden, wobei der Computer einen der +beiden Spieler spielt. Der menschliche Spieler soll aussuchen können, ob er +erster oder zweiter Spieler ist.Wenn der erste +Spieler zieht, soll ein X in das +entsprechende Kästchen gesetzt werden, wenn der zweite Spieler zieht, soll ein O +in das entsprechende Kästchen gesetzt werden. Es darf nur in ein leeres +Kästchen gezogen werden. +
  • +
  • +Nach jedem Zug soll bestimmt werden, ob ein Spieler gewonnen hat oder ob das +Spiel unentschieden endete. +
  • +
+ +
+ +
+ + + + + +
+

+3    Große Integer-Zahlen (fakultativ)

+ +

Entwickeln Sie einen Datentyp Integer40, +der ein Array mit 40 Elementen benutzt, um ganze Zahlen mit bis zu 40 Dezimalstellen zu +speichern. +

    +
  • Implemetieren Sie die Methoden read, +write, add, +subtract. +
  • +
  • +Für den Vergleich von Integer40-Objekten +sollen die Methoden isEqual, isNotEqual, +isGreaterThan, +isSmallerThan, +isGreaterOrEqual, +isSmallerOrEqual +zur Verfügung stehen. Jede dieser Methoden ist eine Prädikat-Funktion, die true +zurückgibt, wenn die entsprechende Beziehung zwischen zwei Objekten stimmt und false, +wenn sie nicht stimmt. Realisieren Sie außerdem eine Prädikat-Funktion +isZero. +
  • +
+

Testen Sie Ihre Klasse in einem Anwendungsprogramm, das die +vorhandenen Operationen mit geeignet gewählten Integer40-Objekten +ausführt. +

+ +
+ + + +
+

+4    Übungsklausur (fakultativ)

+

+Als Klausurvorbereitung können Sie die PG 1-Klausur vom letzten Jahr bearbeiten. +Am besten halten Sie sich dabei auch schon an die allgemeinen Hinweise, die Sie +bei der Klausur am 10.02.05 beachten müssen.

+ +
  + + + \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp new file mode 100644 index 0000000..07b7dfd --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp @@ -0,0 +1,30 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 13.01.2005 +// File: frozenm.cpp +// Description: Implementation of class FrozenMeal + +#include "frozenm.h" +#include "microwave.h" +#include +using std::cout; +using std::endl; + +FrozenMeal::FrozenMeal(string mealname, int vol) { + name=mealname; + volume=vol; + temperature=-18.0; + coefficient=.24; + cout << endl << "Constructor of class FrozenMeal for object " << mealname; +} + +FrozenMeal::~FrozenMeal() +{ + cout << endl << "Destructor of class FrozenMeal for object " << name + << ", Temperature: "<< temperature; +} + +void FrozenMeal::changeTemperature(double &temp) +{ + temperature=temp; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h new file mode 100644 index 0000000..7631346 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h @@ -0,0 +1,31 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 13.01.2005 +// File: frozenm.h +// Description: class FrozenMeal + + + +#ifndef FROZENM_1 +#define FROZENM_1 + +#include +using std::string; + +class FrozenMeal { +public: + //FrozenMeal(char *, int); + FrozenMeal (string, int); + ~FrozenMeal(); + void changeTemperature(double &); + string getName() { return name; } + int getVolume() { return volume; } + double getCoefficient() { return coefficient; } + double getTemperature() { return temperature; } +private: + string name; + int volume; + double temperature; + double coefficient; +}; +#endif \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp b/Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp new file mode 100644 index 0000000..6c26572 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp @@ -0,0 +1,25 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 13.01.2005 +// File: main.cpp +// Description: Application + +#include "frozenm.h" +#include "microwave.h" +#include + +int main() +{ + Microwave micro(22000); + FrozenMeal lasagne("Lasagne",200); + micro.setPeriod(120.0); + micro.morePower(); + micro.morePower(); + micro.morePower(); + micro.heatMeal(lasagne); + FrozenMeal something("Something",250); + micro.lessPower(); + micro.setPeriod(180.0); + micro.heatMeal(something); + return 0; +} diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h b/Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h new file mode 100644 index 0000000..48d0654 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h @@ -0,0 +1,30 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 13.01.2005 +// File: mircowave.h +// Description: class microwave + +#ifndef MICROW_1 +#define MICROW_1 + +#include "frozenm.h" + +class Microwave { + +public: + Microwave(int = 20000); + ~Microwave(); + void morePower(); + void lessPower(); + void setPeriod(double per) { period=per; } + void heatMeal(FrozenMeal &); + int getPower() { return power;} + double getPeriod() { return period; }; + +private: + int power; + int volume; + double period; +}; + +#endif \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp b/Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp new file mode 100644 index 0000000..467a1b3 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp @@ -0,0 +1,41 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 13.01.2005 +// File: mircowave.cpp +// Description: Implementation of class microwave + +#include "microwave.h" +#include + +using std::cout; +using std::endl; + +Microwave::Microwave(int vol) +{ + volume=vol; + power=200; + cout<= 400) + power-=200; +} + +void Microwave::heatMeal(FrozenMeal &myMeal) +{ + double newTemp=myMeal.getTemperature()+((myMeal.getCoefficient()*getPower()*getPeriod())/myMeal.getVolume()); + if (myMeal.getVolume() <= volume) + myMeal.changeTemperature(newTemp); +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp new file mode 100644 index 0000000..672fa8b --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp @@ -0,0 +1,116 @@ +# Microsoft Developer Studio Project File - Name="prg1p6_1" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p6_1 - 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 "prg1p6_1.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 "prg1p6_1.mak" CFG="prg1p6_1 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p6_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p6_1 - 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)" == "prg1p6_1 - 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)" == "prg1p6_1 - 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 "prg1p6_1 - Win32 Release" +# Name "prg1p6_1 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\frozenm.cpp +# End Source File +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# Begin Source File + +SOURCE=.\mircowave.cpp +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\frozenm.h +# End Source File +# Begin Source File + +SOURCE=.\microwave.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/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsw b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsw new file mode 100644 index 0000000..a809ab7 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.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: "prg1p6_1"=.\prg1p6_1.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp b/Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp new file mode 100644 index 0000000..79ab352 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp @@ -0,0 +1,15 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 14.01.2005 +// File: main.cpp +// Description: Application for class TicTacToe + +#include "tictactoe.h" + +int main() +{ + TicTacToe game; + game.playOneGame(); + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp new file mode 100644 index 0000000..3a9b49a --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp @@ -0,0 +1,108 @@ +# Microsoft Developer Studio Project File - Name="prg1p6_2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p6_2 - 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 "prg1p6_2.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 "prg1p6_2.mak" CFG="prg1p6_2 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p6_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p6_2 - 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)" == "prg1p6_2 - 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)" == "prg1p6_2 - 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 "prg1p6_2 - Win32 Release" +# Name "prg1p6_2 - 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=.\tictactoe.cpp +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\tictactoe.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/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsw b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsw new file mode 100644 index 0000000..3b81189 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.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: "prg1p6_2"=.\prg1p6_2.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp new file mode 100644 index 0000000..0b9693d --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp @@ -0,0 +1,385 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1 +// Author: Sven Eisenhauer +// Date: 14.01.2005 +// File: tictactoe.cpp +// Description: Implementation of class TicTacToe + +#include "tictactoe.h" +#include +#include +#include +using std::cout; +using std::endl; +using std::cin; + +TicTacToe::TicTacToe() +:nrFields(9) +{ + for (int i=0;i (i+49); + winner=""; + round=0; +} + +TicTacToe::~TicTacToe() +{ + cout << endl << "Game Over!" << endl; +} + +void TicTacToe::eraseField() +{ + for (int i=0;i> input; + switch (input) + { + case 'p': + case 'P': + nextPlayer="Player"; + break; + case 'c': + case 'C': + nextPlayer="Computer"; + break; + default: + cout << endl << "Bad selection! Enter new selection: "; + } + } while (input!='P' && input!='C' && input!='p' && input!='c'); +} +void TicTacToe::movePlayer() +{ + int draw=0; + cout << endl << "Enter your move: "; + //print(); + cin >> draw; + while (testField(draw-1)) + { + cout << endl << "Irregular move... please enter a new one" << endl; + cin >> draw; + } + field[draw-1]='X'; + setNext("Computer"); + round++; +} + +int TicTacToe::testField(int f) +{ + if (field[f]==' ') + return 0; + else + return 1; +} + +void TicTacToe::moveComputer() +{ + int move=4; + int vertX[3]={0}; + int horX[3]={0}; + int diagX[2]={0}; + int vertO[3]={0}; + int horO[3]={0}; + int diagO[2]={0}; + int n=0, + x=0, + y=0, + d=0; + + if (testField(move)) + { + while(testField(n) && n +using std::ostream; +using std::istream; + + +const static int ARRAYSIZE=40; + +class Integer40 +{ +public: + Integer40(); + Integer40(const Integer40&); + ~Integer40(); + const Integer40& read(); + friend istream& operator>> (istream&, Integer40 &); + const Integer40& write(); + friend ostream& operator<< (ostream&, const Integer40&); + friend Integer40& operator+ (const Integer40&, const Integer40&); + friend Integer40& operator- (const Integer40&, const Integer40&); + const Integer40& add(const Integer40&); + const Integer40& operator+=(const Integer40&); + const Integer40& substract(const Integer40&); + const Integer40& operator-=(const Integer40&); + const Integer40& operator=(const Integer40&); + bool isEqual(const Integer40&) const; + bool operator==(const Integer40&) const; + bool isNotEqual(const Integer40&) const; + bool operator!=(const Integer40&) const; + bool isGreaterThan(const Integer40&) const; + bool operator>(const Integer40&) const; + bool isSmallerThan(const Integer40&) const; + bool operator<(const Integer40&) const; + bool isGreaterOrEqual(const Integer40&) const; + bool operator>=(const Integer40&) const; + bool isSmallerOrEqual(const Integer40&) const; + bool operator<=(const Integer40&) const; + bool isZero(); + //const Integer40& operator-(const Integer40&); + //const Integer40& operator+(const Integer40&); + +private: + int *int40; + //static int nrInt40; +}; + +#endif \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp b/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp new file mode 100644 index 0000000..16e3f67 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp @@ -0,0 +1,344 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3 +// Author: Sven Eisenhauer +// Date: 17.01.2005 +// File: int40.cpp +// Description: Implementation of class Integer40 + +#include "int40.h" +#include +#include +#include +#include + +using std::cout; +using std::endl; +using std::cin; +using std::ostream; +using std::istream; + + + +ostream& operator<<(ostream &out, Integer40 &right) +{ + right.write(); + + return out; +} + +istream& operator>> (istream &in, Integer40 &right) +{ + right.read(); + + return in; +} + +Integer40& operator+ (const Integer40& left, const Integer40& right) +{ + static Integer40 temp; + + int sum=0; + int carry=0; + + for (int i=ARRAYSIZE-1;i>=0;i--) + { + sum=(left.int40[i]+right.int40[i]+carry); + if (sum >= 10) + { + temp.int40[i]=sum%10; + carry=1; + } + else + { + temp.int40[i]=sum; + carry=0; + } + } + + return temp; + +} +Integer40& operator- (const Integer40& left, const Integer40& right) +{ + static Integer40 temp; + + int diff=0; + int carry=0; + + for (int i=ARRAYSIZE-1;i>=0;i--) + { + if (right.int40[i] > left.int40[i]) + { + temp.int40[i]=(left.int40[i]+10)-right.int40[i]-carry; + carry=1; + } + else + { + temp.int40[i]=left.int40[i]-right.int40[i]-carry; + carry=0; + } + + } + + return temp; +} + +Integer40::Integer40() +{ + int40=new int[ARRAYSIZE]; + for (int n=0;n=0;n--) + { + temp[n]=0; + } + i=strlen(input)-1; + for (n=ARRAYSIZE-1;n>=ARRAYSIZE-strlen(input);n--) + { + int40[n]=input[i]-48; + i--; + } + return *this; +} + +const Integer40& Integer40::write() +{ + cout << endl; + for (int n=0;n=0;i--) + { + sum=(int40[i]+toAdd.int40[i]+carry); + int40[i]=sum%10; + if (sum >= 10) + carry=1; + else + carry=0; + } + return *this; +} + +/*const Integer40& Integer40::operator+(const Integer40 &toAdd) +{ + add(toAdd); + + return *this; +} +*/ +const Integer40& Integer40::operator+=(const Integer40 &toAdd) +{ + add(toAdd); + + return *this; +} + +const Integer40& Integer40::substract(const Integer40 &toSub) +{ + int temp=0; + + for (int i=ARRAYSIZE-1;i>=0;i--) + { + if (toSub.int40[i] > int40[i]) + { + int40[i]=((int40[i])+10)-toSub.int40[i]; + (int40[i-1])--; + } + else + int40[i]=((int40[i]))-toSub.int40[i]; + + } + return *this; +} + +/*const Integer40& Integer40::operator-(const Integer40 &toSub) +{ + substract(toSub); + + return *this; +}*/ + +const Integer40& Integer40::operator-=(const Integer40 &toSub) +{ + substract(toSub); + + return *this; +} + +const Integer40& Integer40::operator =(const Integer40 &right) +{ + if(&right!=this) + { + for (int n=0;n=(const Integer40 &toCompare) const +{ + return isGreaterOrEqual(toCompare); +} + +bool Integer40::isSmallerOrEqual(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((i toCompare.int40[i]) + { + retval=false; + } + return retval; +} + +bool Integer40::operator<=(const Integer40 &toCompare) const +{ + return isSmallerOrEqual(toCompare); +} + + +bool Integer40::isGreaterThan(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((i(const Integer40 &toCompare) const +{ + return isGreaterThan(toCompare); +} + +bool Integer40::isSmallerThan(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((i= toCompare.int40[i]) + { + retval=false; + } + return retval; +} + +bool Integer40::operator<(const Integer40 &toCompare) const +{ + return isSmallerThan(toCompare);; +} + +bool Integer40::isEqual(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((iint40[i]!=0) + { + retval=false; + break; + } + i++; + } + + return retval; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp b/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp new file mode 100644 index 0000000..60b73dc --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp @@ -0,0 +1,74 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3 +// Author: Sven Eisenhauer +// Date: 17.01.2005 +// File: main.cpp +// Description: Application to test class Integer40 + +#include "Int40.h" +#include +#include +using std::cin; +using std::cout; +using std::endl; + + + +ostream& operator<<(ostream &out, Integer40 &right); +istream& operator>> (istream &in, Integer40 &right); +Integer40& operator+ (const Integer40&, const Integer40&); +Integer40& operator- (const Integer40&, const Integer40&); + +int main() +{ + Integer40 bigint1; + Integer40 bigint2; + + //bigint1.read(); + cin >> bigint1 >> bigint2; + //bigint1.write(); + //cout << bigint1 ; + + //bigint2.read(); + //cin >> bigint2; + //bigint2.write(); + cout << bigint1 <add(bigint2); + + /*bigint1+=bigint2; + cout << bigint1; + bigint1-=bigint2; + cout << bigint1; + */ + + cout << bigint1 - bigint2; + cout << bigint1 + bigint2; + + if(bigint1 >= bigint2) + cout << endl << "BigInt1 is greater or equal BigInt2" << endl; + if(bigint1 <= bigint2) + cout << endl << "BigInt1 is smaller or equal BigInt2" << endl; + if(bigint1 > bigint2) + cout << endl << "BigInt1 is greater than BigInt2" << endl; + if(bigint1 < bigint2) + cout << endl << "BigInt1 is smaller than BigInt2" << endl; + if(bigint1 == bigint2) + cout << endl << "BigInt1 is equal BigInt2" << endl; + if(bigint1.isZero()) + cout << endl << "BigInt1 is zero" << endl; + + if(bigint2 >= bigint1) + cout << endl << "BigInt2 is greater or equal BigInt1" << endl; + if(bigint2 <= bigint1) + cout << endl << "BigInt2 is smaller or equal BigInt1" << endl; + if(bigint2 > bigint1) + cout << endl << "BigInt2 is greater than BigInt1" << endl; + if(bigint2 < bigint1) + cout << endl << "BigInt2 is smaller than BigInt1" << endl; + if(bigint2 == bigint1) + cout << endl << "BigInt2 is equal BigInt1" << endl; + if(bigint2.isZero()) + cout << endl << "BigInt2 is zero" << endl; + + return 0; +} \ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp new file mode 100644 index 0000000..aec95a9 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp @@ -0,0 +1,108 @@ +# Microsoft Developer Studio Project File - Name="prg1p6_3" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p6_3 - 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 "prg1p6_3.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 "prg1p6_3.mak" CFG="prg1p6_3 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p6_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p6_3 - 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)" == "prg1p6_3 - 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)" == "prg1p6_3 - 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 "prg1p6_3 - Win32 Release" +# Name "prg1p6_3 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\int40.cpp +# End Source File +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\Int40.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/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw new file mode 100644 index 0000000..0f372ae --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.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: "prg1p6_3"=.\prg1p6_3.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Bachelor/Prog1/Vorlesung.htm b/Bachelor/Prog1/Vorlesung.htm new file mode 100644 index 0000000..62dfd47 --- /dev/null +++ b/Bachelor/Prog1/Vorlesung.htm @@ -0,0 +1,31 @@ + + + + + + +Material zur Vorlesung + + + +

Inhaltsübersicht

+ +

Literatur

+ +

Codierungs-Standard

+

PowerPoint-Folien (gezipt:  940 kB)
+(Reproduced from the PowerPoints for C++ How to +Program 3rd ed, by Deitel and Deitel  © 2001
+
and C++ How to Program 4th ed, by Deitel and Deitel  © 2003. 
+
Reproduced by permission of Pearson Education, Inc.)

+

Code-Beispiele (gezipt: 180 kB)

+ +

zusätzliche Beispiele aus der Vorlesung

+ +

Vorrangtabelle für Operatoren

+ +

ASCII-Tabelle

+ +

 

+ + \ No newline at end of file diff --git a/Bachelor/Prog1/Vorlesung_files/style.css b/Bachelor/Prog1/Vorlesung_files/style.css new file mode 100644 index 0000000..6bb3a39 --- /dev/null +++ b/Bachelor/Prog1/Vorlesung_files/style.css @@ -0,0 +1,54 @@ +BODY { + FONT-SIZE: 10pt; MARGIN: 0px 10px 10px 20px; FONT-FAMILY: Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #fffff7; TEXT-ALIGN: left +} +FONT { + FONT-SIZE: 10pt; FONT-FAMILY: Arial, Helvetica, sans-serif +} +FONT.INDEX { + FONT-SIZE: 10pt; COLOR: #b05000; FONT-FAMILY: Arial, Helvetica, sans-serif +} +TD { + FONT-SIZE: 10pt; FONT-FAMILY: Arial, Helvetica, sans-serif +} +DL { + MARGIN-TOP: 0.4em; MARGIN-BOTTOM: 0.4em +} +DT { + PADDING-BOTTOM: 0.3em; LINE-HEIGHT: 1em +} +.Copyright { + FONT-SIZE: 7pt +} +.Autor { + FONT-SIZE: 8pt +} +A { + FONT-SIZE: 10pt; FONT-STYLE: normal; FONT-FAMILY: Arial, Helvetica, sans-serif; TEXT-DECORATION: none +} +A:link { + COLOR: maroon +} +A:visited { + COLOR: maroon +} +A:active { + COLOR: #000000 +} +H1 { + FONT-SIZE: 16pt; TEXT-ALIGN: left +} +H2 { + FONT-SIZE: 14pt; TEXT-ALIGN: left +} +H3 { + FONT-SIZE: 12pt; TEXT-ALIGN: left +} +H4 { + FONT-SIZE: 10pt; TEXT-ALIGN: left +} +BLOCKQUOTE { + FONT-SIZE: 8pt +} +CITE { + FONT-SIZE: 8pt; FONT-STYLE: normal; FONT-FAMILY: Arial, Helvetica, sans-serif +} \ No newline at end of file diff --git a/Bachelor/Prog1/chap1_8.zip b/Bachelor/Prog1/chap1_8.zip new file mode 100644 index 0000000..d9a738f Binary files /dev/null and b/Bachelor/Prog1/chap1_8.zip differ diff --git a/Bachelor/Prog1/ex1_8.zip b/Bachelor/Prog1/ex1_8.zip new file mode 100644 index 0000000..2d911e3 Binary files /dev/null and b/Bachelor/Prog1/ex1_8.zip differ diff --git a/Bachelor/Prog1/examples/ch01/Fig01_02.cpp b/Bachelor/Prog1/examples/ch01/Fig01_02.cpp new file mode 100644 index 0000000..4d6b3d4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_02.cpp @@ -0,0 +1,30 @@ +// Fig. 1.2: fig01_02.cpp +// A first program in C++. +#include + +// function main begins program execution +int main() +{ + std::cout << "Welcome to C++!\n"; + + return 0; // indicate that program ended successfully + +} // end function 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/Prog1/examples/ch01/Fig01_04.cpp b/Bachelor/Prog1/examples/ch01/Fig01_04.cpp new file mode 100644 index 0000000..aaee89a --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_04.cpp @@ -0,0 +1,30 @@ +// Fig. 1.4: fig01_04.cpp +// Printing a line with multiple statements. +#include + +// function main begins program execution +int main() +{ + std::cout << "Welcome "; + std::cout << "to C++!\n"; + + return 0; // indicate that program ended successfully + +} // end function 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/Prog1/examples/ch01/Fig01_05.cpp b/Bachelor/Prog1/examples/ch01/Fig01_05.cpp new file mode 100644 index 0000000..6a8d719 --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_05.cpp @@ -0,0 +1,29 @@ +// Fig. 1.5: fig01_05.cpp +// Printing multiple lines with a single statement. +#include + +// function main begins program execution +int main() +{ + std::cout << "Welcome\nto\n\nC++!\n"; + + return 0; // indicate that program ended successfully + +} // end function 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/Prog1/examples/ch01/Fig01_06.cpp b/Bachelor/Prog1/examples/ch01/Fig01_06.cpp new file mode 100644 index 0000000..403121a --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_06.cpp @@ -0,0 +1,41 @@ +// Fig. 1.6: fig01_06.cpp +// Addition program. +#include + +// function main begins program execution +int main() +{ + int integer1; // first number to be input by user + int integer2; // second number to be input by user + int sum; // variable in which sum will be stored + + std::cout << "Enter first integer\n"; // prompt + std::cin >> integer1; // read an integer + + std::cout << "Enter second integer\n"; // prompt + std::cin >> integer2; // read an integer + + sum = integer1 + integer2; // assignment result to sum + + std::cout << "Sum is " << sum << std::endl; // print sum + + return 0; // indicate that program ended successfully + +} // end function 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/Prog1/examples/ch01/Fig01_14.cpp b/Bachelor/Prog1/examples/ch01/Fig01_14.cpp new file mode 100644 index 0000000..cb623fb --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_14.cpp @@ -0,0 +1,58 @@ +// Fig. 1.14: fig01_14.cpp +// Using if statements, relational +// operators, and equality operators. +#include + +using std::cout; // program uses cout +using std::cin; // program uses cin +using std::endl; // program uses endl + +// function main begins program execution +int main() +{ + int num1; // first number to be read from user + int num2; // second number to be read from user + + cout << "Enter two integers, and I will tell you\n" + << "the relationships they satisfy: "; + cin >> num1 >> num2; // read two integers + + if ( num1 == num2 ) + cout << num1 << " is equal to " << num2 << endl; + + if ( num1 != num2 ) + cout << num1 << " is not equal to " << num2 << endl; + + if ( num1 < num2 ) + cout << num1 << " is less than " << num2 << endl; + + if ( num1 > num2 ) + cout << num1 << " is greater than " << num2 << endl; + + if ( num1 <= num2 ) + cout << num1 << " is less than or equal to " + << num2 << endl; + + if ( num1 >= num2 ) + cout << num1 << " is greater than or equal to " + << num2 << endl; + + return 0; // indicate that program ended successfully + +} // end function 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/Prog1/examples/ch02/Ex02_05.cpp b/Bachelor/Prog1/examples/ch02/Ex02_05.cpp new file mode 100644 index 0000000..1189989 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_05.cpp @@ -0,0 +1,43 @@ +// Ex. 2.5: ex02_05.cpp +// Calculate the sum of the integers from 1 to 10. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int sum; // stores sum of integers 1 to 10 + int x; // counter + + x = 1; // count from 1 + sum = 0; // initialize sum + + while ( x <= 10 ) { + sum += x; // add x to sum + ++x; // increment x + + } // end while + + cout << "The sum is: " << sum << endl; + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Ex02_08.cpp b/Bachelor/Prog1/examples/ch02/Ex02_08.cpp new file mode 100644 index 0000000..db9685a --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_08.cpp @@ -0,0 +1,55 @@ +// Ex. 2.8: ex02_08.cpp +// Raise x to the y power. +#include + +using std::cout; +using std::cin; +using std::endl; + +// function main begins program execution +int main() +{ + int x; // base + int y; // exponent + int i; // counts from 1 to y + int power; // used to calculate x raised to power y + + i = 1; // initialize i to begin counting from 1 + power = 1; // initialize power + + cout << "Enter base as an integer: "; // prompt for base + cin >> x; // input base + + // prompt for exponent + cout << "Enter exponent as an integer: "; + cin >> y; // input exponent + + // count from 1 to y and multiply power by x each time + while ( i <= y ) { + power *= x; + ++i; + + } // end while + + cout << power << endl; // display result + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Ex02_15.cpp b/Bachelor/Prog1/examples/ch02/Ex02_15.cpp new file mode 100644 index 0000000..63e8e14 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_15.cpp @@ -0,0 +1,44 @@ +// Ex. 2.15: ex02_15.cpp +// What does this program print? +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int y; // declare y + int x = 1; // initialize x + int total = 0; // initialize total + + while ( x <= 10 ) { // loop 10 times + y = x * x; // perform calculation + cout << y << endl; // output result + total += y; // add y to total + ++x; // increment counter x + + } // end while + + cout << "Total is " << total << endl; // display result + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Ex02_24.cpp b/Bachelor/Prog1/examples/ch02/Ex02_24.cpp new file mode 100644 index 0000000..3faf50c --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_24.cpp @@ -0,0 +1,39 @@ +// Ex. 2.24: ex02_24.cpp +// What does this program print? +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int count = 1; // initialize count + + while ( count <= 10 ) { // loop 10 times + + // output line of text + cout << ( count % 2 ? "****" : "++++++++" ) + << endl; + ++count; // increment count + } + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Ex02_25.cpp b/Bachelor/Prog1/examples/ch02/Ex02_25.cpp new file mode 100644 index 0000000..6d4a82a --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_25.cpp @@ -0,0 +1,47 @@ +// Ex. 2.25: ex_02_25.cpp +// What does this program print? +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int row = 10; // initialize row + int column; // declare column + + while ( row >= 1 ) { // loop until row < 1 + column = 1; // set column to 1 as iteration begins + + while ( column <= 10 ) { // loop 10 times + cout << ( row % 2 ? "<" : ">" ); // output + ++column; // increment column + + } // end inner while + + --row; // decrement row + cout << endl; // begin new output line + + } // end outer while + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Ex02_42.cpp b/Bachelor/Prog1/examples/ch02/Ex02_42.cpp new file mode 100644 index 0000000..3c3b514 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_42.cpp @@ -0,0 +1,47 @@ +// Ex. 2.42: ex02_42.cpp +// What does this program print? +#include + +using std::cout; +using std::cin; +using std::endl; + +// function main begins program execution +int main() +{ + int x, // declare x + y; // declare y + + // prompt user for input + cout << "Enter two integers in the range 1-20: "; + cin >> x >> y; // read values for x and y + + for ( int i = 1; i <= y; i++ ) { // count from 1 to y + + for ( int j = 1; j <= x; j++ ) // count from 1 to x + cout << '@'; // output @ + + cout << endl; // begin new line + + } // end outer for + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_07.cpp b/Bachelor/Prog1/examples/ch02/Fig02_07.cpp new file mode 100644 index 0000000..eac7fce --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_07.cpp @@ -0,0 +1,54 @@ +// Fig. 2.7: fig02_07.cpp +// Class average program with counter-controlled repetition. +#include + +using std::cout; +using std::cin; +using std::endl; + +// function main begins program execution +int main() +{ + int total; // sum of grades input by user + int gradeCounter; // number of grade to be entered next + int grade; // grade value + int average; // average of grades + + // initialization phase + total = 0; // initialize total + gradeCounter = 1; // initialize loop counter + + // processing phase + while ( gradeCounter <= 10 ) { // loop 10 times + cout << "Enter grade: "; // prompt for input + cin >> grade; // read grade from user + total = total + grade; // add grade to total + gradeCounter = gradeCounter + 1; // increment counter + } + + // termination phase + average = total / 10; // integer division + + // display result + cout << "Class average is " << average << endl; + + return 0; // indicate program ended successfully + +} // end function 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/Prog1/examples/ch02/Fig02_09.cpp b/Bachelor/Prog1/examples/ch02/Fig02_09.cpp new file mode 100644 index 0000000..a0c1065 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_09.cpp @@ -0,0 +1,76 @@ +// Fig. 2.9: fig02_09.cpp +// Class average program with sentinel-controlled repetition. +#include + +using std::cout; +using std::cin; +using std::endl; +using std::fixed; + +#include // parameterized stream manipulators + +using std::setprecision; // sets numeric output precision + +// function main begins program execution +int main() +{ + int total; // sum of grades + int gradeCounter; // number of grades entered + int grade; // grade value + + double average; // number with decimal point for average + + // initialization phase + total = 0; // initialize total + gradeCounter = 0; // initialize loop counter + + // processing phase + // get first grade from user + cout << "Enter grade, -1 to end: "; // prompt for input + cin >> grade; // read grade from user + + // loop until sentinel value read from user + while ( grade != -1 ) { + total = total + grade; // add grade to total + gradeCounter = gradeCounter + 1; // increment counter + + cout << "Enter grade, -1 to end: "; // prompt for input + cin >> grade; // read next grade + + } // end while + + // termination phase + // if user entered at least one grade ... + if ( gradeCounter != 0 ) { + + // calculate average of all grades entered + average = static_cast< double >( total ) / gradeCounter; + + // display average with two digits of precision + cout << "Class average is " << setprecision( 2 ) + << fixed << average << endl; + + } // end if part of if/else + + else // if no grades were entered, output appropriate message + cout << "No grades were entered" << endl; + + return 0; // indicate program ended successfully + +} // end function 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/Prog1/examples/ch02/Fig02_11.cpp b/Bachelor/Prog1/examples/ch02/Fig02_11.cpp new file mode 100644 index 0000000..5cf6523 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_11.cpp @@ -0,0 +1,64 @@ +// Fig. 2.11: fig02_11.cpp +// Analysis of examination results. +#include + +using std::cout; +using std::cin; +using std::endl; + +// function main begins program execution +int main() +{ + // initialize variables in declarations + int passes = 0; // number of passes + int failures = 0; // number of failures + int studentCounter = 1; // student counter + int result; // one exam result + + // process 10 students using counter-controlled loop + while ( studentCounter <= 10 ) { + + // prompt user for input and obtain value from user + cout << "Enter result (1 = pass, 2 = fail): "; + cin >> result; + + // if result 1, increment passes; if/else nested in while + if ( result == 1 ) // if/else nested in while + passes = passes + 1; + + else // if result not 1, increment failures + failures = failures + 1; + + // increment studentCounter so loop eventually terminates + studentCounter = studentCounter + 1; + + } // end while + + // termination phase; display number of passes and failures + cout << "Passed " << passes << endl; + cout << "Failed " << failures << endl; + + // if more than eight students passed, print "raise tuition" + if ( passes > 8 ) + cout << "Raise tuition " << endl; + + return 0; // successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_14.cpp b/Bachelor/Prog1/examples/ch02/Fig02_14.cpp new file mode 100644 index 0000000..b56633a --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_14.cpp @@ -0,0 +1,44 @@ +// Fig. 2.14: fig02_14.cpp +// Preincrementing and postincrementing. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int c; // declare variable + + // demonstrate postincrement + c = 5; // assign 5 to c + cout << c << endl; // print 5 + cout << c++ << endl; // print 5 then postincrement + cout << c << endl << endl; // print 6 + + // demonstrate preincrement + c = 5; // assign 5 to c + cout << c << endl; // print 5 + cout << ++c << endl; // preincrement then print 6 + cout << c << endl; // print 6 + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_16.cpp b/Bachelor/Prog1/examples/ch02/Fig02_16.cpp new file mode 100644 index 0000000..a1998b0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_16.cpp @@ -0,0 +1,38 @@ +// Fig. 2.16: fig02_16.cpp +// Counter-controlled repetition. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int counter = 1; // initialization + + while ( counter <= 10 ) { // repetition condition + cout << counter << endl; // display counter + ++counter; // increment + + } // end while + + return 0; // successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_17.cpp b/Bachelor/Prog1/examples/ch02/Fig02_17.cpp new file mode 100644 index 0000000..26e9a9f --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_17.cpp @@ -0,0 +1,36 @@ +// Fig. 2.17: fig02_17.cpp +// Counter-controlled repetition with the for structure. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + // Initialization, repetition condition and incrementing + // are all included in the for structure header. + + for ( int counter = 1; counter <= 10; counter++ ) + cout << counter << endl; + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_20.cpp b/Bachelor/Prog1/examples/ch02/Fig02_20.cpp new file mode 100644 index 0000000..6a8081f --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_20.cpp @@ -0,0 +1,38 @@ +// Fig. 2.20: fig02_20.cpp +// Summation with for. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int sum = 0; // initialize sum + + // sum even integers from 2 through 100 + for ( int number = 2; number <= 100; number += 2 ) + sum += number; // add number to sum + + cout << "Sum is " << sum << endl; // output sum + return 0; // successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_21.cpp b/Bachelor/Prog1/examples/ch02/Fig02_21.cpp new file mode 100644 index 0000000..d27d6e8 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_21.cpp @@ -0,0 +1,60 @@ +// Fig. 2.21: fig02_21.cpp +// Calculating compound interest. +#include + +using std::cout; +using std::endl; +using std::ios; +using std::fixed; + +#include + +using std::setw; +using std::setprecision; + +#include // enables program to use function pow + +// function main begins program execution +int main() +{ + double amount; // amount on deposit + double principal = 1000.0; // starting principal + double rate = .05; // interest rate + + // output table column heads + cout << "Year" << setw( 21 ) << "Amount on deposit" << endl; + + // set floating-point number format + cout << fixed << setprecision( 2 ); + + // calculate amount on deposit for each of ten years + for ( int year = 1; year <= 10; year++ ) { + + // calculate new amount for specified year + amount = principal * pow( 1.0 + rate, year ); + + // output one table row + cout << setw( 4 ) << year + << setw( 21 ) << amount << endl; + + } // end for + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_22.cpp b/Bachelor/Prog1/examples/ch02/Fig02_22.cpp new file mode 100644 index 0000000..025f666 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_22.cpp @@ -0,0 +1,95 @@ +// Fig. 2.22: fig02_22.cpp +// Counting letter grades. +#include + +using std::cout; +using std::cin; +using std::endl; + +// function main begins program execution +int main() +{ + int grade; // one grade + int aCount = 0; // number of As + int bCount = 0; // number of Bs + int cCount = 0; // number of Cs + int dCount = 0; // number of Ds + int fCount = 0; // number of Fs + + cout << "Enter the letter grades." << endl + << "Enter the EOF character to end input." << endl; + + // loop until user types end-of-file key sequence + while ( ( grade = cin.get() ) != EOF ) { + + // determine which grade was input + switch ( grade ) { // switch structure nested in while + + case 'A': // grade was uppercase A + case 'a': // or lowercase a + ++aCount; // increment aCount + break; // necessary to exit switch + + case 'B': // grade was uppercase B + case 'b': // or lowercase b + ++bCount; // increment bCount + break; // exit switch + + case 'C': // grade was uppercase C + case 'c': // or lowercase c + ++cCount; // increment cCount + break; // exit switch + + case 'D': // grade was uppercase D + case 'd': // or lowercase d + ++dCount; // increment dCount + break; // exit switch + + case 'F': // grade was uppercase F + case 'f': // or lowercase f + ++fCount; // increment fCount + break; // exit switch + + case '\n': // ignore newlines, + case '\t': // tabs, + case ' ': // and spaces in input + break; // exit switch + + default: // catch all other characters + cout << "Incorrect letter grade entered." + << " Enter a new grade." << endl; + break; // optional; will exit switch anyway + + } // end switch + + } // end while + + // output summary of results + cout << "\n\nTotals for each letter grade are:" + << "\nA: " << aCount // display number of A grades + << "\nB: " << bCount // display number of B grades + << "\nC: " << cCount // display number of C grades + << "\nD: " << dCount // display number of D grades + << "\nF: " << fCount // display number of F grades + << endl; + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_24.cpp b/Bachelor/Prog1/examples/ch02/Fig02_24.cpp new file mode 100644 index 0000000..23724b7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_24.cpp @@ -0,0 +1,39 @@ +// Fig. 2.24: fig02_24.cpp +// Using the do/while repetition structure. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + int counter = 1; // initialize counter + + do { + cout << counter << " "; // display counter + } while ( ++counter <= 10 ); // end do/while + + cout << endl; + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_26.cpp b/Bachelor/Prog1/examples/ch02/Fig02_26.cpp new file mode 100644 index 0000000..a17fd07 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_26.cpp @@ -0,0 +1,46 @@ +// Fig. 2.26: fig02_26.cpp +// Using the break statement in a for structure. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + + int x; // x declared here so it can be used after the loop + + // loop 10 times + for ( x = 1; x <= 10; x++ ) { + + // if x is 5, terminate loop + if ( x == 5 ) + break; // break loop only if x is 5 + + cout << x << " "; // display value of x + + } // end for + + cout << "\nBroke out of loop when x became " << x << endl; + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch02/Fig02_27.cpp b/Bachelor/Prog1/examples/ch02/Fig02_27.cpp new file mode 100644 index 0000000..9504968 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_27.cpp @@ -0,0 +1,45 @@ +// Fig. 2.27: fig02_27.cpp +// Using the continue statement in a for structure. +#include + +using std::cout; +using std::endl; + +// function main begins program execution +int main() +{ + // loop 10 times + for ( int x = 1; x <= 10; x++ ) { + + // if x is 5, continue with next iteration of loop + if ( x == 5 ) + continue; // skip remaining code in loop body + + cout << x << " "; // display value of x + + } // end for structure + + cout << "\nUsed continue to skip printing the value 5" + << endl; + + return 0; // indicate successful termination + +} // end function 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/Prog1/examples/ch03/Ex03_02.cpp b/Bachelor/Prog1/examples/ch03/Ex03_02.cpp new file mode 100644 index 0000000..cb1f501 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_02.cpp @@ -0,0 +1,41 @@ +// Exercise 3.2: ex03_02.cpp +#include + +using std::cout; +using std::endl; + +int cube( int y ); // function prototype + +int main() +{ + int x; + + // loop 10 times, calculate cube of x and output results + for ( x = 1; x <= 10; x++ ) + cout << cube( x ) << endl; + + return 0; // indicates successful termination + +} // end main + +// definition of function cube +int cube( int y ) +{ + return y * y * y; +} + + +/************************************************************************** + * (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/Prog1/examples/ch03/Ex03_03.cpp b/Bachelor/Prog1/examples/ch03/Ex03_03.cpp new file mode 100644 index 0000000..af9b320 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_03.cpp @@ -0,0 +1,67 @@ +// Exercise 3.3: ex03_03.cpp +// Testing the math library functions. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +#include + +int main() +{ + cout << fixed << setprecision( 1 ); + + cout << "sqrt(" << 900.0 << ") = " << sqrt( 900.0 ) + << "\nsqrt(" << 9.0 << ") = " << sqrt( 9.0 ); + cout << "\nexp(" << 1.0 << ") = " << setprecision( 6 ) + << exp( 1.0 ) << "\nexp(" << setprecision( 1 ) << 2.0 + << ") = " << setprecision( 6 ) << exp( 2.0 ); + cout << "\nlog(" << 2.718282 << ") = " << setprecision( 1 ) + << log( 2.718282 ) + << "\nlog(" << setprecision( 6 ) << 7.389056 << ") = " + << setprecision( 1 ) << log( 7.389056 ); + cout << "\nlog10(" << 1.0 << ") = " << log10( 1.0 ) + << "\nlog10(" << 10.0 << ") = " << log10( 10.0 ) + << "\nlog10(" << 100.0 << ") = " << log10( 100.0 ) ; + cout << "\nfabs(" << 13.5 << ") = " << fabs( 13.5 ) + << "\nfabs(" << 0.0 << ") = " << fabs( 0.0 ) + << "\nfabs(" << -13.5 << ") = " << fabs( -13.5 ); + cout << "\nceil(" << 9.2 << ") = " << ceil( 9.2 ) + << "\nceil(" << -9.8 << ") = " << ceil( -9.8 ); + cout << "\nfloor(" << 9.2 << ") = " << floor( 9.2 ) + << "\nfloor(" << -9.8 << ") = " << floor( -9.8 ); + cout << "\npow(" << 2.0 << ", " << 7.0 << ") = " + << pow( 2.0, 7.0 ) << "\npow(" << 9.0 << ", " + << 0.5 << ") = " << pow( 9.0, 0.5 ); + cout << setprecision(3) << "\nfmod(" + << 13.675 << ", " << 2.333 << ") = " + << fmod( 13.675, 2.333 ) << setprecision( 1 ); + cout << "\nsin(" << 0.0 << ") = " << sin( 0.0 ); + cout << "\ncos(" << 0.0 << ") = " << cos( 0.0 ); + cout << "\ntan(" << 0.0 << ") = " << tan( 0.0 ) << 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/Prog1/examples/ch03/Ex03_10.cpp b/Bachelor/Prog1/examples/ch03/Ex03_10.cpp new file mode 100644 index 0000000..466ad86 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_10.cpp @@ -0,0 +1,53 @@ +// Exercise 3.10: ex03_10.cpp +// Inline function that calculates the volume of a sphere. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +// define global constant PI +const double PI = 3.14159; + +// calculates volume of a sphere +inline double sphereVolume( const double radius ) +{ + return 4.0 / 3.0 * PI * pow( radius, 3 ); + +} // end inline function sphereVolume + +int main() +{ + double radiusValue; + + // prompt user for radius + cout << "Enter the length of the radius of your sphere: "; + cin >> radiusValue; // input radius + + // use radiusValue to calculate volume of sphere + // and display result + cout << "Volume of sphere with radius " << radiusValue + << " is " << sphereVolume( radiusValue ) << 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/Prog1/examples/ch03/Ex03_49.cpp b/Bachelor/Prog1/examples/ch03/Ex03_49.cpp new file mode 100644 index 0000000..faaf62f --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_49.cpp @@ -0,0 +1,36 @@ +// Exercise 3.49: ex03_49.cpp +// What is wrong with this program? +#include + +using std::cin; +using std::cout; + +int main() +{ + int c; + + if ( ( c = cin.get() ) != EOF ) { + main(); + cout << c; + } + + 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/Prog1/examples/ch03/Ex03_50.cpp b/Bachelor/Prog1/examples/ch03/Ex03_50.cpp new file mode 100644 index 0000000..c887d3d --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_50.cpp @@ -0,0 +1,51 @@ +// Exercise 3.50: ex03_50.cpp +// What does this program do? +#include + +using std::cout; +using std::cin; +using std::endl; + +int mystery( int, int ); // function prototype + +int main() +{ + int x, y; + + cout << "Enter two integers: "; + cin >> x >> y; + cout << "The result is " << mystery( x, y ) << endl; + + return 0; // indicates successful termination + +} // end main + +// Parameter b must be a positive +// integer to prevent infinite recursion +int mystery( int a, int b ) +{ + // base case + if ( b == 1 ) + return a; + + // recursive step + else + return a + mystery( a, b - 1 ); + +} // end function mystery + + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_03.cpp b/Bachelor/Prog1/examples/ch03/Fig03_03.cpp new file mode 100644 index 0000000..271802e --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_03.cpp @@ -0,0 +1,45 @@ +// Fig. 3.3: fig03_03.cpp +// Creating and using a programmer-defined function. +#include + +using std::cout; +using std::endl; + +int square( int ); // function prototype + +int main() +{ + // loop 10 times and calculate and output + // square of x each time + for ( int x = 1; x <= 10; x++ ) + cout << square( x ) << " "; // function call + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// square function definition returns square of an integer +int square( int y ) // y is a copy of argument to function +{ + return y * y; // returns square of y as an int + +} // end function square + + + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_04.cpp b/Bachelor/Prog1/examples/ch03/Fig03_04.cpp new file mode 100644 index 0000000..d9e27f3 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_04.cpp @@ -0,0 +1,60 @@ +// Fig. 3.4: fig03_04.cpp +// Finding the maximum of three floating-point numbers. +#include + +using std::cout; +using std::cin; +using std::endl; + +double maximum( double, double, double ); // function prototype + +int main() +{ + double number1; + double number2; + double number3; + + cout << "Enter three floating-point numbers: "; + cin >> number1 >> number2 >> number3; + + // number1, number2 and number3 are arguments to + // the maximum function call + cout << "Maximum is: " + << maximum( number1, number2, number3 ) << endl; + + return 0; // indicates successful termination + +} // end main + +// function maximum definition; +// x, y and z are parameters +double maximum( double x, double y, double z ) +{ + double max = x; // assume x is largest + + if ( y > max ) // if y is larger, + max = y; // assign y to max + + if ( z > max ) // if z is larger, + max = z; // assign z to max + + return max; // max is largest value + +} // end function maximum + + + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_07.cpp b/Bachelor/Prog1/examples/ch03/Fig03_07.cpp new file mode 100644 index 0000000..4971cc4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_07.cpp @@ -0,0 +1,46 @@ +// Fig. 3.7: fig03_07.cpp +// Shifted, scaled integers produced by 1 + rand() % 6. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include // contains function prototype for rand + +int main() +{ + // loop 20 times + for ( int counter = 1; counter <= 20; counter++ ) { + + // pick random number from 1 to 6 and output it + cout << setw( 10 ) << ( 1 + rand() % 6 ); + + // if counter divisible by 5, begin new line of output + if ( counter % 5 == 0 ) + cout << endl; + + } // end for structure + + 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/Prog1/examples/ch03/Fig03_08.cpp b/Bachelor/Prog1/examples/ch03/Fig03_08.cpp new file mode 100644 index 0000000..8bb489e --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_08.cpp @@ -0,0 +1,89 @@ +// Fig. 3.8: fig03_08.cpp +// Roll a six-sided die 6000 times. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include // contains function prototype for rand + +int main() +{ + int frequency1 = 0; + int frequency2 = 0; + int frequency3 = 0; + int frequency4 = 0; + int frequency5 = 0; + int frequency6 = 0; + int face; // represents one roll of the die + + // loop 6000 times and summarize results + for ( int roll = 1; roll <= 6000; roll++ ) { + face = 1 + rand() % 6; // random number from 1 to 6 + + // determine face value and increment appropriate counter + switch ( face ) { + + case 1: // rolled 1 + ++frequency1; + break; + + case 2: // rolled 2 + ++frequency2; + break; + + case 3: // rolled 3 + ++frequency3; + break; + + case 4: // rolled 4 + ++frequency4; + break; + + case 5: // rolled 5 + ++frequency5; + break; + + case 6: // rolled 6 + ++frequency6; + break; + + default: // invalid value + cout << "Program should never get here!"; + + } // end switch + + } // end for + + // display results in tabular format + cout << "Face" << setw( 13 ) << "Frequency" + << "\n 1" << setw( 13 ) << frequency1 + << "\n 2" << setw( 13 ) << frequency2 + << "\n 3" << setw( 13 ) << frequency3 + << "\n 4" << setw( 13 ) << frequency4 + << "\n 5" << setw( 13 ) << frequency5 + << "\n 6" << setw( 13 ) << frequency6 << 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/Prog1/examples/ch03/Fig03_09.cpp b/Bachelor/Prog1/examples/ch03/Fig03_09.cpp new file mode 100644 index 0000000..5ea5fb6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_09.cpp @@ -0,0 +1,54 @@ +// Fig. 3.9: fig03_09.cpp +// Randomizing die-rolling program. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::setw; + +// contains prototypes for functions srand and rand +#include + +int main() +{ + unsigned seed; + + cout << "Enter seed: "; + cin >> seed; + srand( seed ); // seed random number generator + + // loop 10 times + for ( int counter = 1; counter <= 10; counter++ ) { + + // pick random number from 1 to 6 and output it + cout << setw( 10 ) << ( 1 + rand() % 6 ); + + // if counter divisible by 5, begin new line of output + if ( counter % 5 == 0 ) + cout << endl; + + } // end for + + 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/Prog1/examples/ch03/Fig03_10.cpp b/Bachelor/Prog1/examples/ch03/Fig03_10.cpp new file mode 100644 index 0000000..5ebbd59 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_10.cpp @@ -0,0 +1,111 @@ +// Fig. 3.10: fig03_10.cpp +// Craps. +#include + +using std::cout; +using std::endl; + +// contains function prototypes for functions srand and rand +#include + +#include // contains prototype for function time + +int rollDice( void ); // function prototype + +int main() +{ + // enumeration constants represent game status + enum Status { CONTINUE, WON, LOST }; + + int sum; + int myPoint; + + Status gameStatus; // can contain CONTINUE, WON or LOST + + // randomize random number generator using current time + srand( time( 0 ) ); + + sum = rollDice(); // first roll of the dice + + // determine game status and point based on sum of dice + switch ( sum ) { + + // win on first roll + case 7: + case 11: + gameStatus = WON; + break; + + // lose on first roll + case 2: + case 3: + case 12: + gameStatus = LOST; + break; + + // remember point + default: + gameStatus = CONTINUE; + myPoint = sum; + cout << "Point is " << myPoint << endl; + break; // optional + + } // end switch + + // while game not complete ... + while ( gameStatus == CONTINUE ) { + sum = rollDice(); // roll dice again + + // determine game status + if ( sum == myPoint ) // win by making point + gameStatus = WON; + else + if ( sum == 7 ) // lose by rolling 7 + gameStatus = LOST; + + } // end while + + // display won or lost message + if ( gameStatus == WON ) + cout << "Player wins" << endl; + else + cout << "Player loses" << endl; + + return 0; // indicates successful termination + +} // end main + +// roll dice, calculate sum and display results +int rollDice( void ) +{ + int die1; + int die2; + int workSum; + + die1 = 1 + rand() % 6; // pick random die1 value + die2 = 1 + rand() % 6; // pick random die2 value + workSum = die1 + die2; // sum die1 and die2 + + // display results of this roll + cout << "Player rolled " << die1 << " + " << die2 + << " = " << workSum << endl; + + return workSum; // return sum of dice + +} // end function rollDice + + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_12.cpp b/Bachelor/Prog1/examples/ch03/Fig03_12.cpp new file mode 100644 index 0000000..593c27a --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_12.cpp @@ -0,0 +1,96 @@ +// Fig. 3.12: fig03_12.cpp +// A scoping example. +#include + +using std::cout; +using std::endl; + +void useLocal( void ); // function prototype +void useStaticLocal( void ); // function prototype +void useGlobal( void ); // function prototype + +int x = 1; // global variable + +int main() +{ + int x = 5; // local variable to main + + cout << "local x in main's outer scope is " << x << endl; + + { // start new scope + + int x = 7; + + cout << "local x in main's inner scope is " << x << endl; + + } // end new scope + + cout << "local x in main's outer scope is " << x << endl; + + useLocal(); // useLocal has local x + useStaticLocal(); // useStaticLocal has static local x + useGlobal(); // useGlobal uses global x + useLocal(); // useLocal reinitializes its local x + useStaticLocal(); // static local x retains its prior value + useGlobal(); // global x also retains its value + + cout << "\nlocal x in main is " << x << endl; + + return 0; // indicates successful termination + +} // end main + +// useLocal reinitializes local variable x during each call +void useLocal( void ) +{ + int x = 25; // initialized each time useLocal is called + + cout << endl << "local x is " << x + << " on entering useLocal" << endl; + ++x; + cout << "local x is " << x + << " on exiting useLocal" << endl; + +} // end function useLocal + +// useStaticLocal initializes static local variable x only the +// first time the function is called; value of x is saved +// between calls to this function +void useStaticLocal( void ) +{ + // initialized first time useStaticLocal is called. + static int x = 50; + + cout << endl << "local static x is " << x + << " on entering useStaticLocal" << endl; + ++x; + cout << "local static x is " << x + << " on exiting useStaticLocal" << endl; + +} // end function useStaticLocal + +// useGlobal modifies global variable x during each call +void useGlobal( void ) +{ + cout << endl << "global x is " << x + << " on entering useGlobal" << endl; + x *= 10; + cout << "global x is " << x + << " on exiting useGlobal" << endl; + +} // end function useGlobal + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_14.cpp b/Bachelor/Prog1/examples/ch03/Fig03_14.cpp new file mode 100644 index 0000000..ca4f128 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_14.cpp @@ -0,0 +1,52 @@ +// Fig. 3.14: fig03_14.cpp +// Recursive factorial function. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +unsigned long factorial( unsigned long ); // function prototype + +int main() +{ + // Loop 10 times. During each iteration, calculate + // factorial( i ) and display result. + for ( int i = 0; i <= 10; i++ ) + cout << setw( 2 ) << i << "! = " + << factorial( i ) << endl; + + return 0; // indicates successful termination + +} // end main + +// recursive definition of function factorial +unsigned long factorial( unsigned long number ) +{ + // base case + if ( number <= 1 ) + return 1; + + // recursive step + else + return number * factorial( number - 1 ); + +} // end function factorial + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_15.cpp b/Bachelor/Prog1/examples/ch03/Fig03_15.cpp new file mode 100644 index 0000000..3882d55 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_15.cpp @@ -0,0 +1,56 @@ +// Fig. 3.15: fig03_15.cpp +// Recursive fibonacci function. +#include + +using std::cout; +using std::cin; +using std::endl; + +unsigned long fibonacci( unsigned long ); // function prototype + +int main() +{ + unsigned long result, number; + + // obtain integer from user + cout << "Enter an integer: "; + cin >> number; + + // calculate fibonacci value for number input by user + result = fibonacci( number ); + + // display result + cout << "Fibonacci(" << number << ") = " << result << endl; + + return 0; // indicates successful termination + +} // end main + +// recursive definition of function fibonacci +unsigned long fibonacci( unsigned long n ) +{ + // base case + if ( n == 0 || n == 1 ) + return n; + + // recursive step + else + return fibonacci( n - 1 ) + fibonacci( n - 2 ); + +} // end function fibonacci + + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_18.cpp b/Bachelor/Prog1/examples/ch03/Fig03_18.cpp new file mode 100644 index 0000000..9e5781c --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_18.cpp @@ -0,0 +1,50 @@ +// Fig. 3.18: fig03_18.cpp +// Functions that take no arguments. +#include + +using std::cout; +using std::endl; + +void function1(); // function prototype +void function2( void ); // function prototype + +int main() +{ + function1(); // call function1 with no arguments + function2(); // call function2 with no arguments + + return 0; // indicates successful termination + +} // end main + +// function1 uses an empty parameter list to specify that +// the function receives no arguments +void function1() +{ + cout << "function1 takes no arguments" << endl; + +} // end function1 + +// function2 uses a void parameter list to specify that +// the function receives no arguments +void function2( void ) +{ + cout << "function2 also takes no arguments" << endl; + +} // end function2 + + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_19.cpp b/Bachelor/Prog1/examples/ch03/Fig03_19.cpp new file mode 100644 index 0000000..e785534 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_19.cpp @@ -0,0 +1,50 @@ +// Fig. 3.19: fig03_19.cpp +// Using an inline function to calculate. +// the volume of a cube. +#include + +using std::cout; +using std::cin; +using std::endl; + +// Definition of inline function cube. Definition of function +// appears before function is called, so a function prototype +// is not required. First line of function definition acts as +// the prototype. +inline double cube( const double side ) +{ + return side * side * side; // calculate cube + +} // end function cube + +int main() +{ + cout << "Enter the side length of your cube: "; + + double sideValue; + + cin >> sideValue; + + // calculate cube of sideValue and display result + cout << "Volume of cube with side " + << sideValue << " is " << cube( sideValue ) << 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/Prog1/examples/ch03/Fig03_20.cpp b/Bachelor/Prog1/examples/ch03/Fig03_20.cpp new file mode 100644 index 0000000..e94ca30 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_20.cpp @@ -0,0 +1,61 @@ +// Fig. 3.20: fig03_20.cpp +// Comparing pass-by-value and pass-by-reference +// with references. +#include + +using std::cout; +using std::endl; + +int squareByValue( int ); // function prototype +void squareByReference( int & ); // function prototype + +int main() +{ + int x = 2; + int z = 4; + + // demonstrate squareByValue + cout << "x = " << x << " before squareByValue\n"; + cout << "Value returned by squareByValue: " + << squareByValue( x ) << endl; + cout << "x = " << x << " after squareByValue\n" << endl; + + // demonstrate squareByReference + cout << "z = " << z << " before squareByReference" << endl; + squareByReference( z ); + cout << "z = " << z << " after squareByReference" << endl; + + return 0; // indicates successful termination +} // end main + +// squareByValue multiplies number by itself, stores the +// result in number and returns the new value of number +int squareByValue( int number ) +{ + return number *= number; // caller's argument not modified + +} // end function squareByValue + +// squareByReference multiplies numberRef by itself and +// stores the result in the variable to which numberRef +// refers in function main +void squareByReference( int &numberRef ) +{ + numberRef *= numberRef; // caller's argument modified + +} // end function squareByReference + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_21.cpp b/Bachelor/Prog1/examples/ch03/Fig03_21.cpp new file mode 100644 index 0000000..4e1af15 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_21.cpp @@ -0,0 +1,37 @@ +// Fig. 3.21: fig03_21.cpp +// References must be initialized. +#include + +using std::cout; +using std::endl; + +int main() +{ + int x = 3; + + // y refers to (is an alias for) x + int &y = x; + + cout << "x = " << x << endl << "y = " << y << endl; + y = 7; + cout << "x = " << x << endl << "y = " << y << 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/Prog1/examples/ch03/Fig03_22.cpp b/Bachelor/Prog1/examples/ch03/Fig03_22.cpp new file mode 100644 index 0000000..90ab6a9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_22.cpp @@ -0,0 +1,35 @@ +// Fig. 3.22: fig03_22.cpp +// References must be initialized. +#include + +using std::cout; +using std::endl; + +int main() +{ + int x = 3; + int &y; // Error: y must be initialized + + cout << "x = " << x << endl << "y = " << y << endl; + y = 7; + cout << "x = " << x << endl << "y = " << y << 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/Prog1/examples/ch03/Fig03_23.cpp b/Bachelor/Prog1/examples/ch03/Fig03_23.cpp new file mode 100644 index 0000000..b3cffc5 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_23.cpp @@ -0,0 +1,54 @@ +// Fig. 3.23: fig03_23.cpp +// Using default arguments. +#include + +using std::cout; +using std::endl; + +// function prototype that specifies default arguments +int boxVolume( int length = 1, int width = 1, int height = 1 ); + +int main() +{ + // no arguments--use default values for all dimensions + cout << "The default box volume is: " << boxVolume(); + + // specify length; default width and height + cout << "\n\nThe volume of a box with length 10,\n" + << "width 1 and height 1 is: " << boxVolume( 10 ); + + // specify length and width; default height + cout << "\n\nThe volume of a box with length 10,\n" + << "width 5 and height 1 is: " << boxVolume( 10, 5 ); + + // specify all arguments + cout << "\n\nThe volume of a box with length 10,\n" + << "width 5 and height 2 is: " << boxVolume( 10, 5, 2 ) + << endl; + + return 0; // indicates successful termination + +} // end main + +// function boxVolume calculates the volume of a box +int boxVolume( int length, int width, int height ) +{ + return length * width * height; + +} // end function boxVolume + + +/************************************************************************** + * (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/Prog1/examples/ch03/Fig03_24.cpp b/Bachelor/Prog1/examples/ch03/Fig03_24.cpp new file mode 100644 index 0000000..b1fa28b --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_24.cpp @@ -0,0 +1,44 @@ +// Fig. 3.24: fig03_24.cpp +// Using the unary scope resolution operator. +#include + +using std::cout; +using std::endl; + +#include + +using std::setprecision; + +// define global constant PI +const double PI = 3.14159265358979; + +int main() +{ + // define local constant PI + const float PI = static_cast< float >( ::PI ); + + // display values of local and global PI constants + cout << setprecision( 20 ) + << " Local float value of PI = " << PI + << "\nGlobal double value of PI = " << ::PI << 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/Prog1/examples/ch03/Fig03_25.cpp b/Bachelor/Prog1/examples/ch03/Fig03_25.cpp new file mode 100644 index 0000000..2539aee --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_25.cpp @@ -0,0 +1,50 @@ +// Fig. 3.25: fig03_25.cpp +// Using overloaded functions. +#include + +using std::cout; +using std::endl; + +// function square for int values +int square( int x ) +{ + cout << "Called square with int argument: " << x << endl; + return x * x; + +} // end int version of function square + +// function square for double values +double square( double y ) +{ + cout << "Called square with double argument: " << y << endl; + return y * y; + +} // end double version of function square + +int main() +{ + int intResult = square( 7 ); // calls int version + double doubleResult = square( 7.5 ); // calls double version + + cout << "\nThe square of integer 7 is " << intResult + << "\nThe square of double 7.5 is " << doubleResult + << 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/Prog1/examples/ch03/Fig03_26.cpp b/Bachelor/Prog1/examples/ch03/Fig03_26.cpp new file mode 100644 index 0000000..5b2fdec --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_26.cpp @@ -0,0 +1,50 @@ +// Fig. 3.26: fig03_26.cpp +// Name mangling. + +// function square for int values +int square( int x ) +{ + return x * x; +} + +// function square for double values +double square( double y ) +{ + return y * y; +} + +// function that receives arguments of types +// int, float, char and int * +void nothing1( int a, float b, char c, int *d ) +{ + // empty function body +} + +// function that receives arguments of types +// char, int, float * and double * +char *nothing2( char a, int b, float *c, double *d ) +{ + return 0; +} + +int main() +{ + 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/Prog1/examples/ch03/Fig03_27.cpp b/Bachelor/Prog1/examples/ch03/Fig03_27.cpp new file mode 100644 index 0000000..13a671f --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_27.cpp @@ -0,0 +1,76 @@ +// Fig. 3.27: fig03_27.cpp +// Using a function template. +#include + +using std::cout; +using std::cin; +using std::endl; + +// definition of function template maximum +template < class T > // or template< typename T > +T maximum( T value1, T value2, T value3 ) +{ + T max = value1; + + if ( value2 > max ) + max = value2; + + if ( value3 > max ) + max = value3; + + return max; + +} // end function template maximum + +int main() +{ + // demonstrate maximum with int values + int int1, int2, int3; + + cout << "Input three integer values: "; + cin >> int1 >> int2 >> int3; + + // invoke int version of maximum + cout << "The maximum integer value is: " + << maximum( int1, int2, int3 ); + + // demonstrate maximum with double values + double double1, double2, double3; + + cout << "\n\nInput three double values: "; + cin >> double1 >> double2 >> double3; + + // invoke double version of maximum + cout << "The maximum double value is: " + << maximum( double1, double2, double3 ); + + // demonstrate maximum with char values + char char1, char2, char3; + + cout << "\n\nInput three characters: "; + cin >> char1 >> char2 >> char3; + + // invoke char version of maximum + cout << "The maximum character value is: " + << maximum( char1, char2, char3 ) + << 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/Prog1/examples/ch04/Ex04_18.cpp b/Bachelor/Prog1/examples/ch04/Ex04_18.cpp new file mode 100644 index 0000000..9ccbc6e --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Ex04_18.cpp @@ -0,0 +1,49 @@ +// Ex. 4.18: ex04_18.cpp +// What does this program do? +#include + +using std::cout; +using std::endl; + +int whatIsThis( int [], int ); // function prototype + +int main() +{ + const int arraySize = 10; + int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + int result = whatIsThis( a, arraySize ); + + cout << "Result is " << result << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +int whatIsThis( int b[], int size ) +{ + // base case + if ( size == 1 ) + return b[ 0 ]; + + // recursive step + else + return b[ size - 1 ] + whatIsThis( b, size - 1 ); + +} // end function whatIsThis + +/************************************************************************** + * (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/Prog1/examples/ch04/Ex04_21.cpp b/Bachelor/Prog1/examples/ch04/Ex04_21.cpp new file mode 100644 index 0000000..06c3e49 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Ex04_21.cpp @@ -0,0 +1,47 @@ +// Ex. 4.21: ex04_21.cpp +// What does this program do? +#include + +using std::cout; +using std::endl; + +void someFunction( int [], int, int ); // function prototype + +int main() +{ + const int arraySize = 10; + int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + cout << "The values in the array are:" << endl; + someFunction( a, 0, arraySize ); + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +void someFunction( int b[], int current, int size ) +{ + if ( current < size ) { + someFunction( b, current + 1, size ); + cout << b[ current ] << " "; + } + +} // end function someFunction + + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_03.cpp b/Bachelor/Prog1/examples/ch04/Fig04_03.cpp new file mode 100644 index 0000000..9dffb95 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_03.cpp @@ -0,0 +1,44 @@ +// Fig. 4.3: fig04_03.cpp +// Initializing an array. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + int n[ 10 ]; // n is an array of 10 integers + + // initialize elements of array n to 0 + for ( int i = 0; i < 10; i++ ) + n[ i ] = 0; // set element at location i to 0 + + cout << "Element" << setw( 13 ) << "Value" << endl; + + // output contents of array n in tabular format + for ( int j = 0; j < 10; j++ ) + cout << setw( 7 ) << j << setw( 13 ) << n[ j ] << 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/Prog1/examples/ch04/Fig04_04.cpp b/Bachelor/Prog1/examples/ch04/Fig04_04.cpp new file mode 100644 index 0000000..6f6efb0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_04.cpp @@ -0,0 +1,42 @@ +// Fig. 4.4: fig04_04.cpp +// Initializing an array with a declaration. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + // use initializer list to initialize array n + int n[ 10 ] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 }; + + cout << "Element" << setw( 13 ) << "Value" << endl; + + // output contents of array n in tabular format + for ( int i = 0; i < 10; i++ ) + cout << setw( 7 ) << i << setw( 13 ) << n[ i ] << 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/Prog1/examples/ch04/Fig04_05.cpp b/Bachelor/Prog1/examples/ch04/Fig04_05.cpp new file mode 100644 index 0000000..4905155 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_05.cpp @@ -0,0 +1,46 @@ +// Fig. 4.5: fig04_05.cpp +// Initialize array s to the even integers from 2 to 20. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + // constant variable can be used to specify array size + const int arraySize = 10; + + int s[ arraySize ]; // array s has 10 elements + + for ( int i = 0; i < arraySize; i++ ) // set the values + s[ i ] = 2 + 2 * i; + + cout << "Element" << setw( 13 ) << "Value" << endl; + + // output contents of array s in tabular format + for ( int j = 0; j < arraySize; j++ ) + cout << setw( 7 ) << j << setw( 13 ) << s[ j ] << 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/Prog1/examples/ch04/Fig04_06.cpp b/Bachelor/Prog1/examples/ch04/Fig04_06.cpp new file mode 100644 index 0000000..f62da85 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_06.cpp @@ -0,0 +1,35 @@ +// Fig. 4.6: fig04_06.cpp +// Using a properly initialized constant variable. +#include + +using std::cout; +using std::endl; + +int main() +{ + const int x = 7; // initialized constant variable + + cout << "The value of constant variable x is: " + << x << 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/Prog1/examples/ch04/Fig04_07.cpp b/Bachelor/Prog1/examples/ch04/Fig04_07.cpp new file mode 100644 index 0000000..bc1cc0c --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_07.cpp @@ -0,0 +1,29 @@ +// Fig. 4.7: fig04_07.cpp +// A const object must be initialized. + +int main() +{ + const int x; // Error: x must be initialized + + x = 7; // Error: cannot modify a const variable + + 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/Prog1/examples/ch04/Fig04_08.cpp b/Bachelor/Prog1/examples/ch04/Fig04_08.cpp new file mode 100644 index 0000000..bda7cc0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_08.cpp @@ -0,0 +1,41 @@ +// Fig. 4.8: fig04_08.cpp +// Compute the sum of the elements of the array. +#include + +using std::cout; +using std::endl; + +int main() +{ + const int arraySize = 10; + + int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + int total = 0; + + // sum contents of array a + for ( int i = 0; i < arraySize; i++ ) + total += a[ i ]; + + cout << "Total of array element values is " << total << 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/Prog1/examples/ch04/Fig04_09.cpp b/Bachelor/Prog1/examples/ch04/Fig04_09.cpp new file mode 100644 index 0000000..1b722e9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_09.cpp @@ -0,0 +1,49 @@ +// Fig. 4.9: fig04_09.cpp +// Histogram printing program. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + const int arraySize = 10; + int n[ arraySize ] = { 19, 3, 15, 7, 11, 9, 13, 5, 17, 1 }; + + cout << "Element" << setw( 13 ) << "Value" + << setw( 17 ) << "Histogram" << endl; + + // for each element of array n, output a bar in histogram + for ( int i = 0; i < arraySize; i++ ) { + cout << setw( 7 ) << i << setw( 13 ) + << n[ i ] << setw( 9 ); + + for ( int j = 0; j < n[ i ]; j++ ) // print one bar + cout << '*'; + + cout << endl; // start next line of output + + } // end outer for structure + + 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/Prog1/examples/ch04/Fig04_10.cpp b/Bachelor/Prog1/examples/ch04/Fig04_10.cpp new file mode 100644 index 0000000..9984df6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_10.cpp @@ -0,0 +1,53 @@ +// Fig. 4.10: fig04_10.cpp +// Roll a six-sided die 6000 times. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include +#include + +int main() +{ + const int arraySize = 7; + int frequency[ arraySize ] = { 0 }; + + srand( time( 0 ) ); // seed random-number generator + + // roll die 6000 times + for ( int roll = 1; roll <= 6000; roll++ ) + ++frequency[ 1 + rand() % 6 ]; // replaces 20-line switch + // of Fig. 3.8 + + cout << "Face" << setw( 13 ) << "Frequency" << endl; + + // output frequency elements 1-6 in tabular format + for ( int face = 1; face < arraySize; face++ ) + cout << setw( 4 ) << face + << setw( 13 ) << frequency[ face ] << 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/Prog1/examples/ch04/Fig04_11.cpp b/Bachelor/Prog1/examples/ch04/Fig04_11.cpp new file mode 100644 index 0000000..86eba62 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_11.cpp @@ -0,0 +1,58 @@ +// Fig. 4.11: fig04_11.cpp +// Student poll program. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + // define array sizes + const int responseSize = 40; // size of array responses + const int frequencySize = 11; // size of array frequency + + // place survey responses in array responses + int responses[ responseSize ] = { 1, 2, 6, 4, 8, 5, 9, 7, 8, + 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, + 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10 }; + + // initialize frequency counters to 0 + int frequency[ frequencySize ] = { 0 }; + + // for each answer, select value of an element of array + // responses and use that value as subscript in array + // frequency to determine element to increment + for ( int answer = 0; answer < responseSize; answer++ ) + ++frequency[ responses[answer] ]; + + // display results + cout << "Rating" << setw( 17 ) << "Frequency" << endl; + + // output frequencies in tabular format + for ( int rating = 1; rating < frequencySize; rating++ ) + cout << setw( 6 ) << rating + << setw( 17 ) << frequency[ rating ] << 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/Prog1/examples/ch04/Fig04_12.cpp b/Bachelor/Prog1/examples/ch04/Fig04_12.cpp new file mode 100644 index 0000000..115d033 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_12.cpp @@ -0,0 +1,49 @@ +// Fig. 4_12: fig04_12.cpp +// Treating character arrays as strings. +#include + +using std::cout; +using std::cin; +using std::endl; + +int main() +{ + char string1[ 20 ]; // reserves 20 characters + char string2[] = "string literal"; // reserves 15 characters + + // read string from user into array string2 + cout << "Enter the string \"hello there\": "; + cin >> string1; // reads "hello" [space terminates input] + + // output strings + cout << "string1 is: " << string1 + << "\nstring2 is: " << string2; + + cout << "\nstring1 with spaces between characters is:\n"; + + // output characters until null character is reached + for ( int i = 0; string1[ i ] != '\0'; i++ ) + cout << string1[ i ] << ' '; + + cin >> string1; // reads "there" + cout << "\nstring1 is: " << string1 << 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/Prog1/examples/ch04/Fig04_13.cpp b/Bachelor/Prog1/examples/ch04/Fig04_13.cpp new file mode 100644 index 0000000..ed21456 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_13.cpp @@ -0,0 +1,82 @@ +// Fig. 4.13: fig04_13.cpp +// Static arrays are initialized to zero. +#include + +using std::cout; +using std::endl; + +void staticArrayInit( void ); // function prototype +void automaticArrayInit( void ); // function prototype + +int main() +{ + cout << "First call to each function:\n"; + staticArrayInit(); + automaticArrayInit(); + + cout << "\n\nSecond call to each function:\n"; + staticArrayInit(); + automaticArrayInit(); + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// function to demonstrate a static local array +void staticArrayInit( void ) +{ + // initializes elements to 0 first time function is called + static int array1[ 3 ]; + + cout << "\nValues on entering staticArrayInit:\n"; + + // output contents of array1 + for ( int i = 0; i < 3; i++ ) + cout << "array1[" << i << "] = " << array1[ i ] << " "; + + cout << "\nValues on exiting staticArrayInit:\n"; + + // modify and output contents of array1 + for ( int j = 0; j < 3; j++ ) + cout << "array1[" << j << "] = " + << ( array1[ j ] += 5 ) << " "; + +} // end function staticArrayInit + +// function to demonstrate an automatic local array +void automaticArrayInit( void ) +{ + // initializes elements each time function is called + int array2[ 3 ] = { 1, 2, 3 }; + + cout << "\n\nValues on entering automaticArrayInit:\n"; + + // output contents of array2 + for ( int i = 0; i < 3; i++ ) + cout << "array2[" << i << "] = " << array2[ i ] << " "; + + cout << "\nValues on exiting automaticArrayInit:\n"; + + // modify and output contents of array2 + for ( int j = 0; j < 3; j++ ) + cout << "array2[" << j << "] = " + << ( array2[ j ] += 5 ) << " "; + +} // end function automaticArrayInit + + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_14.cpp b/Bachelor/Prog1/examples/ch04/Fig04_14.cpp new file mode 100644 index 0000000..a1db3ea --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_14.cpp @@ -0,0 +1,87 @@ +// Fig. 4.14: fig04_14.cpp +// Passing arrays and individual array elements to functions. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +void modifyArray( int [], int ); // appears strange +void modifyElement( int ); + +int main() +{ + const int arraySize = 5; // size of array a + int a[ arraySize ] = { 0, 1, 2, 3, 4 }; // initialize a + + cout << "Effects of passing entire array by reference:" + << "\n\nThe values of the original array are:\n"; + + // output original array + for ( int i = 0; i < arraySize; i++ ) + cout << setw( 3 ) << a[ i ]; + + cout << endl; + + // pass array a to modifyArray by reference + modifyArray( a, arraySize ); + + cout << "The values of the modified array are:\n"; + + // output modified array + for ( int j = 0; j < arraySize; j++ ) + cout << setw( 3 ) << a[ j ]; + + // output value of a[ 3 ] + cout << "\n\n\n" + << "Effects of passing array element by value:" + << "\n\nThe value of a[3] is " << a[ 3 ] << '\n'; + + // pass array element a[ 3 ] by value + modifyElement( a[ 3 ] ); + + // output value of a[ 3 ] + cout << "The value of a[3] is " << a[ 3 ] << endl; + + return 0; // indicates successful termination + +} // end main + +// in function modifyArray, "b" points to +// the original array "a" in memory +void modifyArray( int b[], int sizeOfArray ) +{ + // multiply each array element by 2 + for ( int k = 0; k < sizeOfArray; k++ ) + b[ k ] *= 2; + +} // end function modifyArray + +// in function modifyElement, "e" is a local copy of +// array element a[ 3 ] passed from main +void modifyElement( int e ) +{ + // multiply parameter by 2 + cout << "Value in modifyElement is " + << ( e *= 2 ) << endl; + +} // end function modifyElement + + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_15.cpp b/Bachelor/Prog1/examples/ch04/Fig04_15.cpp new file mode 100644 index 0000000..5d35b9d --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_15.cpp @@ -0,0 +1,46 @@ +// Fig. 4.15: fig04_15.cpp +// Demonstrating the const type qualifier. +#include + +using std::cout; +using std::endl; + +void tryToModifyArray( const int [] ); // function prototype + +int main() +{ + int a[] = { 10, 20, 30 }; + + tryToModifyArray( a ); + + cout << a[ 0 ] << ' ' << a[ 1 ] << ' ' << a[ 2 ] << '\n'; + + return 0; // indicates successful termination + +} // end main + +// In function tryToModifyArray, "b" cannot be used +// to modify the original array "a" in main. +void tryToModifyArray( const int b[] ) +{ + b[ 0 ] /= 2; // error + b[ 1 ] /= 2; // error + b[ 2 ] /= 2; // error + +} // end function tryToModifyArray + + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_16.cpp b/Bachelor/Prog1/examples/ch04/Fig04_16.cpp new file mode 100644 index 0000000..e009daf --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_16.cpp @@ -0,0 +1,65 @@ +// Fig. 4.16: fig04_16.cpp +// This program sorts an array's values into ascending order. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + const int arraySize = 10; // size of array a + int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; + int hold; // temporary location used to swap array elements + + cout << "Data items in original order\n"; + + // output original array + for ( int i = 0; i < arraySize; i++ ) + cout << setw( 4 ) << a[ i ]; + + // bubble sort + // loop to control number of passes + for ( int pass = 0; pass < arraySize - 1; pass++ ) + + // loop to control number of comparisons per pass + for ( int j = 0; j < arraySize - 1; j++ ) + + // compare side-by-side elements and swap them if + // first element is greater than second element + if ( a[ j ] > a[ j + 1 ] ) { + hold = a[ j ]; + a[ j ] = a[ j + 1 ]; + a[ j + 1 ] = hold; + + } // end if + + cout << "\nData items in ascending order\n"; + + // output sorted array + for ( int k = 0; k < arraySize; k++ ) + cout << setw( 4 ) << a[ k ]; + + 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/Prog1/examples/ch04/Fig04_17.cpp b/Bachelor/Prog1/examples/ch04/Fig04_17.cpp new file mode 100644 index 0000000..c6442c1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_17.cpp @@ -0,0 +1,193 @@ +// Fig. 4.17: fig04_17.cpp +// This program introduces the topic of survey data analysis. +// It computes the mean, median, and mode of the data. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setw; +using std::setprecision; + +void mean( const int [], int ); +void median( int [], int ); +void mode( int [], int [], int ); +void bubbleSort( int[], int ); +void printArray( const int[], int ); + +int main() +{ + const int responseSize = 99; // size of array responses + + int frequency[ 10 ] = { 0 }; // initialize array frequency + + // initialize array responses + int response[ responseSize ] = + { 6, 7, 8, 9, 8, 7, 8, 9, 8, 9, + 7, 8, 9, 5, 9, 8, 7, 8, 7, 8, + 6, 7, 8, 9, 3, 9, 8, 7, 8, 7, + 7, 8, 9, 8, 9, 8, 9, 7, 8, 9, + 6, 7, 8, 7, 8, 7, 9, 8, 9, 2, + 7, 8, 9, 8, 9, 8, 9, 7, 5, 3, + 5, 6, 7, 2, 5, 3, 9, 4, 6, 4, + 7, 8, 9, 6, 8, 7, 8, 9, 7, 8, + 7, 4, 4, 2, 5, 3, 8, 7, 5, 6, + 4, 5, 6, 1, 6, 5, 7, 8, 7 }; + + // process responses + mean( response, responseSize ); + median( response, responseSize ); + mode( frequency, response, responseSize ); + + return 0; // indicates successful termination + +} // end main + +// calculate average of all response values +void mean( const int answer[], int arraySize ) +{ + int total = 0; + + cout << "********\n Mean\n********\n"; + + // total response values + for ( int i = 0; i < arraySize; i++ ) + total += answer[ i ]; + + // format and output results + cout << fixed << setprecision( 4 ); + + cout << "The mean is the average value of the data\n" + << "items. The mean is equal to the total of\n" + << "all the data items divided by the number\n" + << "of data items (" << arraySize + << "). The mean value for\nthis run is: " + << total << " / " << arraySize << " = " + << static_cast< double >( total ) / arraySize + << "\n\n"; + +} // end function mean + +// sort array and determine median element's value +void median( int answer[], int size ) +{ + cout << "\n********\n Median\n********\n" + << "The unsorted array of responses is"; + + printArray( answer, size ); // output unsorted array + + bubbleSort( answer, size ); // sort array + + cout << "\n\nThe sorted array is"; + printArray( answer, size ); // output sorted array + + // display median element + cout << "\n\nThe median is element " << size / 2 + << " of\nthe sorted " << size + << " element array.\nFor this run the median is " + << answer[ size / 2 ] << "\n\n"; + +} // end function median + +// determine most frequent response +void mode( int freq[], int answer[], int size ) +{ + int largest = 0; // represents largest frequency + int modeValue = 0; // represents most frequent response + + cout << "\n********\n Mode\n********\n"; + + // initialize frequencies to 0 + for ( int i = 1; i <= 9; i++ ) + freq[ i ] = 0; + + // summarize frequencies + for ( int j = 0; j < size; j++ ) + ++freq[ answer[ j ] ]; + + // output headers for result columns + cout << "Response" << setw( 11 ) << "Frequency" + << setw( 19 ) << "Histogram\n\n" << setw( 55 ) + << "1 1 2 2\n" << setw( 56 ) + << "5 0 5 0 5\n\n"; + + // output results + for ( int rating = 1; rating <= 9; rating++ ) { + cout << setw( 8 ) << rating << setw( 11 ) + << freq[ rating ] << " "; + + // keep track of mode value and largest fequency value + if ( freq[ rating ] > largest ) { + largest = freq[ rating ]; + modeValue = rating; + + } // end if + + // output histogram bar representing frequency value + for ( int k = 1; k <= freq[ rating ]; k++ ) + cout << '*'; + + cout << '\n'; // begin new line of output + + } // end outer for + + // display the mode value + cout << "The mode is the most frequent value.\n" + << "For this run the mode is " << modeValue + << " which occurred " << largest << " times." << endl; + +} // end function mode + +// function that sorts an array with bubble sort algorithm +void bubbleSort( int a[], int size ) +{ + int hold; // temporary location used to swap elements + + // loop to control number of passes + for ( int pass = 1; pass < size; pass++ ) + + // loop to control number of comparisons per pass + for ( int j = 0; j < size - 1; j++ ) + + // swap elements if out of order + if ( a[ j ] > a[ j + 1 ] ) { + hold = a[ j ]; + a[ j ] = a[ j + 1 ]; + a[ j + 1 ] = hold; + + } // end if + +} // end function bubbleSort + +// output array contents (20 values per row) +void printArray( const int a[], int size ) +{ + for ( int i = 0; i < size; i++ ) { + + if ( i % 20 == 0 ) // begin new line every 20 values + cout << endl; + + cout << setw( 2 ) << a[ i ]; + + } // end for + +} // end function printArray + + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_19.cpp b/Bachelor/Prog1/examples/ch04/Fig04_19.cpp new file mode 100644 index 0000000..0be6aa3 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_19.cpp @@ -0,0 +1,63 @@ +// Fig. 4.19: fig04_19.cpp +// Linear search of an array. +#include + +using std::cout; +using std::cin; +using std::endl; + +int linearSearch( const int [], int, int ); // prototype + +int main() +{ + const int arraySize = 100; // size of array a + int a[ arraySize ]; // create array a + int searchKey; // value to locate in a + + for ( int i = 0; i < arraySize; i++ ) // create some data + a[ i ] = 2 * i; + + cout << "Enter integer search key: "; + cin >> searchKey; + + // attempt to locate searchKey in array a + int element = linearSearch( a, searchKey, arraySize ); + + // display results + if ( element != -1 ) + cout << "Found value in element " << element << endl; + else + cout << "Value not found" << endl; + + return 0; // indicates successful termination + +} // end main + +// compare key to every element of array until location is +// found or until end of array is reached; return subscript of +// element if key or -1 if key not found +int linearSearch( const int array[], int key, int sizeOfArray ) +{ + for ( int j = 0; j < sizeOfArray; j++ ) + + if ( array[ j ] == key ) // if found, + return j; // return location of key + + return -1; // key not found + +} // end function linearSearch + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_20.cpp b/Bachelor/Prog1/examples/ch04/Fig04_20.cpp new file mode 100644 index 0000000..241c800 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_20.cpp @@ -0,0 +1,142 @@ +// Fig. 4.20: fig04_20.cpp +// Binary search of an array. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::setw; + +// function prototypes +int binarySearch( const int [], int, int, int, int ); +void printHeader( int ); +void printRow( const int [], int, int, int, int ); + +int main() +{ + const int arraySize = 15; // size of array a + int a[ arraySize ]; // create array a + int key; // value to locate in a + + for ( int i = 0; i < arraySize; i++ ) // create some data + a[ i ] = 2 * i; + + cout << "Enter a number between 0 and 28: "; + cin >> key; + + printHeader( arraySize ); + + // search for key in array a + int result = + binarySearch( a, key, 0, arraySize - 1, arraySize ); + + // display results + if ( result != -1 ) + cout << '\n' << key << " found in array element " + << result << endl; + else + cout << '\n' << key << " not found" << endl; + + return 0; // indicates successful termination + +} // end main + +// function to perform binary search of an array +int binarySearch( const int b[], int searchKey, int low, + int high, int size ) +{ + int middle; + + // loop until low subscript is greater than high subscript + while ( low <= high ) { + + // determine middle element of subarray being searched + middle = ( low + high ) / 2; + + // display subarray used in this loop iteration + printRow( b, low, middle, high, size ); + + // if searchKey matches middle element, return middle + if ( searchKey == b[ middle ] ) // match + return middle; + + else + + // if searchKey less than middle element, + // set new high element + if ( searchKey < b[ middle ] ) + high = middle - 1; // search low end of array + + // if searchKey greater than middle element, + // set new low element + else + low = middle + 1; // search high end of array + } + + return -1; // searchKey not found + +} // end function binarySearch + +// print header for output +void printHeader( int size ) +{ + cout << "\nSubscripts:\n"; + + // output column heads + for ( int j = 0; j < size; j++ ) + cout << setw( 3 ) << j << ' '; + + cout << '\n'; // start new line of output + + // output line of - characters + for ( int k = 1; k <= 4 * size; k++ ) + cout << '-'; + + cout << endl; // start new line of output + +} // end function printHeader + +// print one row of output showing the current +// part of the array being processed +void printRow( const int b[], int low, int mid, + int high, int size ) +{ + // loop through entire array + for ( int m = 0; m < size; m++ ) + + // display spaces if outside current subarray range + if ( m < low || m > high ) + cout << " "; + + // display middle element marked with a * + else + + if ( m == mid ) // mark middle value + cout << setw( 3 ) << b[ m ] << '*'; + + // display other elements in subarray + else + cout << setw( 3 ) << b[ m ] << ' '; + + cout << endl; // start new line of output + +} // end function printRow + + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_22.cpp b/Bachelor/Prog1/examples/ch04/Fig04_22.cpp new file mode 100644 index 0000000..44c17da --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_22.cpp @@ -0,0 +1,57 @@ +// Fig. 4.22: fig04_22.cpp +// Initializing multidimensional arrays. +#include + +using std::cout; +using std::endl; + +void printArray( int [][ 3 ] ); + +int main() +{ + int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } }; + int array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 }; + int array3[ 2 ][ 3 ] = { { 1, 2 }, { 4 } }; + + cout << "Values in array1 by row are:" << endl; + printArray( array1 ); + + cout << "Values in array2 by row are:" << endl; + printArray( array2 ); + + cout << "Values in array3 by row are:" << endl; + printArray( array3 ); + + return 0; // indicates successful termination + +} // end main + +// function to output array with two rows and three columns +void printArray( int a[][ 3 ] ) +{ + for ( int i = 0; i < 2; i++ ) { // for each row + + for ( int j = 0; j < 3; j++ ) // output column values + cout << a[ i ][ j ] << ' '; + + cout << endl; // start new line of output + + } // end outer for structure + +} // end function printArray + + +/************************************************************************** + * (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/Prog1/examples/ch04/Fig04_23.cpp b/Bachelor/Prog1/examples/ch04/Fig04_23.cpp new file mode 100644 index 0000000..7957c1e --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_23.cpp @@ -0,0 +1,134 @@ +// Fig. 4.23: fig04_23.cpp +// Double-subscripted array example. +#include + +using std::cout; +using std::endl; +using std::fixed; +using std::left; + +#include + +using std::setw; +using std::setprecision; + +const int students = 3; // number of students +const int exams = 4; // number of exams + +// function prototypes +int minimum( int [][ exams ], int, int ); +int maximum( int [][ exams ], int, int ); +double average( int [], int ); +void printArray( int [][ exams ], int, int ); + +int main() +{ + // initialize student grades for three students (rows) + int studentGrades[ students ][ exams ] = + { { 77, 68, 86, 73 }, + { 96, 87, 89, 78 }, + { 70, 90, 86, 81 } }; + + // output array studentGrades + cout << "The array is:\n"; + printArray( studentGrades, students, exams ); + + // determine smallest and largest grade values + cout << "\n\nLowest grade: " + << minimum( studentGrades, students, exams ) + << "\nHighest grade: " + << maximum( studentGrades, students, exams ) << '\n'; + + cout << fixed << setprecision( 2 ); + + // calculate average grade for each student + for ( int person = 0; person < students; person++ ) + cout << "The average grade for student " << person + << " is " + << average( studentGrades[ person ], exams ) + << endl; + + return 0; // indicates successful termination + +} // end main + +// find minimum grade +int minimum( int grades[][ exams ], int pupils, int tests ) +{ + int lowGrade = 100; // initialize to highest possible grade + + for ( int i = 0; i < pupils; i++ ) + + for ( int j = 0; j < tests; j++ ) + + if ( grades[ i ][ j ] < lowGrade ) + lowGrade = grades[ i ][ j ]; + + return lowGrade; + +} // end function minimum + +// find maximum grade +int maximum( int grades[][ exams ], int pupils, int tests ) +{ + int highGrade = 0; // initialize to lowest possible grade + + for ( int i = 0; i < pupils; i++ ) + + for ( int j = 0; j < tests; j++ ) + + if ( grades[ i ][ j ] > highGrade ) + highGrade = grades[ i ][ j ]; + + return highGrade; + +} // end function maximum + +// determine average grade for particular student +double average( int setOfGrades[], int tests ) +{ + int total = 0; + + // total all grades for one student + for ( int i = 0; i < tests; i++ ) + total += setOfGrades[ i ]; + + return static_cast< double >( total ) / tests; // average + +} // end function maximum + +// Print the array +void printArray( int grades[][ exams ], int pupils, int tests ) +{ + // set left justification and output column heads + cout << left << " [0] [1] [2] [3]"; + + // output grades in tabular format + for ( int i = 0; i < pupils; i++ ) { + + // output label for row + cout << "\nstudentGrades[" << i << "] "; + + // output one grades for one student + for ( int j = 0; j < tests; j++ ) + cout << setw( 5 ) << grades[ i ][ j ]; + + } // end outer for + +} // end function printArray + + +/************************************************************************** + * (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/Prog1/examples/ch05/Ex05_21.cpp b/Bachelor/Prog1/examples/ch05/Ex05_21.cpp new file mode 100644 index 0000000..1fd9111 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_21.cpp @@ -0,0 +1,49 @@ +// Ex. 5.21: ex05_21.cpp +// What does this program do? +#include + +using std::cout; +using std::cin; +using std::endl; + +void mystery1( char *, const char * ); // prototype + +int main() +{ + char string1[ 80 ]; + char string2[ 80 ]; + + cout << "Enter two strings: "; + cin >> string1 >> string2; + mystery1( string1, string2 ); + cout << string1 << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +void mystery1( char *s1, const char *s2 ) +{ + while ( *s1 != '\0' ) + ++s1; + + for ( ; *s1 = *s2; s1++, s2++ ) + ; // empty statement + +} // end function mystery1 + +/************************************************************************** + * (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/Prog1/examples/ch05/Ex05_22.cpp b/Bachelor/Prog1/examples/ch05/Ex05_22.cpp new file mode 100644 index 0000000..9299669 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_22.cpp @@ -0,0 +1,48 @@ +// Ex. 5.22: ex05_22.cpp +// What does this program do? +#include + +using std::cout; +using std::cin; +using std::endl; + +int mystery2( const char * ); // prototype + +int main() +{ + char string1[ 80 ]; + + cout << "Enter a string: "; + cin >> string1; + cout << mystery2( string1 ) << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +int mystery2( const char *s ) +{ + int x; + + for ( x = 0; *s != '\0'; s++ ) + ++x; + + return x; + +} // end function mystery2 + +/************************************************************************** + * (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/Prog1/examples/ch05/Ex05_30.cpp b/Bachelor/Prog1/examples/ch05/Ex05_30.cpp new file mode 100644 index 0000000..88ede48 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_30.cpp @@ -0,0 +1,49 @@ +// Ex. 5.30: ex05_30.cpp +// What does this program do? +#include + +using std::cout; +using std::cin; +using std::endl; + +bool mystery3( const char *, const char * ); // prototype + +int main() +{ + char string1[ 80 ], string2[ 80 ]; + + cout << "Enter two strings: "; + cin >> string1 >> string2; + cout << "The result is " + << mystery3( string1, string2 ) << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +bool mystery3( const char *s1, const char *s2 ) +{ + for ( ; *s1 != '\0' && *s2 != '\0'; s1++, s2++ ) + + if ( *s1 != *s2 ) + return false; + + return true; + +} // end function mystery3 + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_04.cpp b/Bachelor/Prog1/examples/ch05/Fig05_04.cpp new file mode 100644 index 0000000..bcf52ff --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_04.cpp @@ -0,0 +1,43 @@ +// Fig. 5.4: fig05_04.cpp +// Using the & and * operators. +#include + +using std::cout; +using std::endl; + +int main() +{ + int a; // a is an integer + int *aPtr; // aPtr is a pointer to an integer + + a = 7; + aPtr = &a; // aPtr assigned address of a + + cout << "The address of a is " << &a + << "\nThe value of aPtr is " << aPtr; + + cout << "\n\nThe value of a is " << a + << "\nThe value of *aPtr is " << *aPtr; + + cout << "\n\nShowing that * and & are inverses of " + << "each other.\n&*aPtr = " << &*aPtr + << "\n*&aPtr = " << *&aPtr << 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/Prog1/examples/ch05/Fig05_06.cpp b/Bachelor/Prog1/examples/ch05/Fig05_06.cpp new file mode 100644 index 0000000..5aad3b7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_06.cpp @@ -0,0 +1,45 @@ +// Fig. 5.6: fig05_06.cpp +// Cube a variable using pass-by-value. +#include + +using std::cout; +using std::endl; + +int cubeByValue( int ); // prototype + +int main() +{ + int number = 5; + + cout << "The original value of number is " << number; + + // pass number by value to cubeByValue + number = cubeByValue( number ); + + cout << "\nThe new value of number is " << number << endl; + + return 0; // indicates successful termination + +} // end main + +// calculate and return cube of integer argument +int cubeByValue( int n ) +{ + return n * n * n; // cube local variable n and return result + +} // end function cubeByValue + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_07.cpp b/Bachelor/Prog1/examples/ch05/Fig05_07.cpp new file mode 100644 index 0000000..b4da523 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_07.cpp @@ -0,0 +1,46 @@ +// Fig. 5.7: fig05_07.cpp +// Cube a variable using pass-by-reference +// with a pointer argument. +#include + +using std::cout; +using std::endl; + +void cubeByReference( int * ); // prototype + +int main() +{ + int number = 5; + + cout << "The original value of number is " << number; + + // pass address of number to cubeByReference + cubeByReference( &number ); + + cout << "\nThe new value of number is " << number << endl; + + return 0; // indicates successful termination + +} // end main + +// calculate cube of *nPtr; modifies variable number in main +void cubeByReference( int *nPtr ) +{ + *nPtr = *nPtr * *nPtr * *nPtr; // cube *nPtr + +} // end function cubeByReference + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_10.cpp b/Bachelor/Prog1/examples/ch05/Fig05_10.cpp new file mode 100644 index 0000000..cfd0fce --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_10.cpp @@ -0,0 +1,53 @@ +// Fig. 5.10: fig05_10.cpp +// Converting lowercase letters to uppercase letters +// using a non-constant pointer to non-constant data. +#include + +using std::cout; +using std::endl; + +#include // prototypes for islower and toupper + +void convertToUppercase( char * ); + +int main() +{ + char phrase[] = "characters and $32.98"; + + cout << "The phrase before conversion is: " << phrase; + convertToUppercase( phrase ); + cout << "\nThe phrase after conversion is: " + << phrase << endl; + + return 0; // indicates successful termination + +} // end main + +// convert string to uppercase letters +void convertToUppercase( char *sPtr ) +{ + while ( *sPtr != '\0' ) { // current character is not '\0' + + if ( islower( *sPtr ) ) // if character is lowercase, + *sPtr = toupper( *sPtr ); // convert to uppercase + + ++sPtr; // move sPtr to next character in string + + } // end while + +} // end function convertToUppercase + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_11.cpp b/Bachelor/Prog1/examples/ch05/Fig05_11.cpp new file mode 100644 index 0000000..6d92cef --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_11.cpp @@ -0,0 +1,45 @@ +// Fig. 5.11: fig05_11.cpp +// Printing a string one character at a time using +// a non-constant pointer to constant data. +#include + +using std::cout; +using std::endl; + +void printCharacters( const char * ); + +int main() +{ + char phrase[] = "print characters of a string"; + + cout << "The string is:\n"; + printCharacters( phrase ); + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// sPtr cannot modify the character to which it points, +// i.e., sPtr is a "read-only" pointer +void printCharacters( const char *sPtr ) +{ + for ( ; *sPtr != '\0'; sPtr++ ) // no initialization + cout << *sPtr; + +} // end function printCharacters + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_12.cpp b/Bachelor/Prog1/examples/ch05/Fig05_12.cpp new file mode 100644 index 0000000..c9f089a --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_12.cpp @@ -0,0 +1,38 @@ +// Fig. 5.12: fig05_12.cpp +// Attempting to modify data through a +// non-constant pointer to constant data. + +void f( const int * ); // prototype + +int main() +{ + int y; + + f( &y ); // f attempts illegal modification + + return 0; // indicates successful termination + +} // end main + +// xPtr cannot modify the value of the variable +// to which it points +void f( const int *xPtr ) +{ + *xPtr = 100; // error: cannot modify a const object + +} // end function f + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_13.cpp b/Bachelor/Prog1/examples/ch05/Fig05_13.cpp new file mode 100644 index 0000000..ac697ba --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_13.cpp @@ -0,0 +1,34 @@ +// Fig. 5.13: fig05_13.cpp +// Attempting to modify a constant pointer to +// non-constant data. + +int main() +{ + int x, y; + + // ptr is a constant pointer to an integer that can + // be modified through ptr, but ptr always points to the + // same memory location. + int * const ptr = &x; + + *ptr = 7; // allowed: *ptr is not const + ptr = &y; // error: ptr is const; cannot assign new address + + 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/Prog1/examples/ch05/Fig05_14.cpp b/Bachelor/Prog1/examples/ch05/Fig05_14.cpp new file mode 100644 index 0000000..8193ad1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_14.cpp @@ -0,0 +1,39 @@ +// Fig. 5.14: fig05_14.cpp +// Attempting to modify a constant pointer to constant data. +#include + +using std::cout; +using std::endl; + +int main() +{ + int x = 5, y; + + // ptr is a constant pointer to a constant integer. + // ptr always points to the same location; the integer + // at that location cannot be modified. + const int *const ptr = &x; + + cout << *ptr << endl; + + *ptr = 7; // error: *ptr is const; cannot assign new value + ptr = &y; // error: ptr is const; cannot assign new address + + 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/Prog1/examples/ch05/Fig05_15.cpp b/Bachelor/Prog1/examples/ch05/Fig05_15.cpp new file mode 100644 index 0000000..bcdd13a --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_15.cpp @@ -0,0 +1,77 @@ +// Fig. 5.15: fig05_15.cpp +// This program puts values into an array, sorts the values into +// ascending order, and prints the resulting array. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +void bubbleSort( int *, const int ); // prototype +void swap( int * const, int * const ); // prototype + +int main() +{ + const int arraySize = 10; + int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; + + cout << "Data items in original order\n"; + + for ( int i = 0; i < arraySize; i++ ) + cout << setw( 4 ) << a[ i ]; + + bubbleSort( a, arraySize ); // sort the array + + cout << "\nData items in ascending order\n"; + + for ( int j = 0; j < arraySize; j++ ) + cout << setw( 4 ) << a[ j ]; + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// sort an array of integers using bubble sort algorithm +void bubbleSort( int *array, const int size ) +{ + // loop to control passes + for ( int pass = 0; pass < size - 1; pass++ ) + + // loop to control comparisons during each pass + for ( int k = 0; k < size - 1; k++ ) + + // swap adjacent elements if they are out of order + if ( array[ k ] > array[ k + 1 ] ) + swap( &array[ k ], &array[ k + 1 ] ); + +} // end function bubbleSort + +// swap values at memory locations to which +// element1Ptr and element2Ptr point +void swap( int * const element1Ptr, int * const element2Ptr ) +{ + int hold = *element1Ptr; + *element1Ptr = *element2Ptr; + *element2Ptr = hold; + +} // end function swap + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_16.cpp b/Bachelor/Prog1/examples/ch05/Fig05_16.cpp new file mode 100644 index 0000000..921e8dd --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_16.cpp @@ -0,0 +1,45 @@ +// Fig. 5.16: fig05_16.cpp +// Sizeof operator when used on an array name +// returns the number of bytes in the array. +#include + +using std::cout; +using std::endl; + +size_t getSize( double * ); // prototype + +int main() +{ + double array[ 20 ]; + + cout << "The number of bytes in the array is " + << sizeof( array ); + + cout << "\nThe number of bytes returned by getSize is " + << getSize( array ) << endl; + + return 0; // indicates successful termination + +} // end main + +// return size of ptr +size_t getSize( double *ptr ) +{ + return sizeof( ptr ); + +} // end function getSize + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_17.cpp b/Bachelor/Prog1/examples/ch05/Fig05_17.cpp new file mode 100644 index 0000000..7091880 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_17.cpp @@ -0,0 +1,55 @@ +// Fig. 5.17: fig05_17.cpp +// Demonstrating the sizeof operator. +#include + +using std::cout; +using std::endl; + +int main() +{ + char c; + short s; + int i; + long l; + float f; + double d; + long double ld; + int array[ 20 ]; + int *ptr = array; + + cout << "sizeof c = " << sizeof c + << "\tsizeof(char) = " << sizeof( char ) + << "\nsizeof s = " << sizeof s + << "\tsizeof(short) = " << sizeof( short ) + << "\nsizeof i = " << sizeof i + << "\tsizeof(int) = " << sizeof( int ) + << "\nsizeof l = " << sizeof l + << "\tsizeof(long) = " << sizeof( long ) + << "\nsizeof f = " << sizeof f + << "\tsizeof(float) = " << sizeof( float ) + << "\nsizeof d = " << sizeof d + << "\tsizeof(double) = " << sizeof( double ) + << "\nsizeof ld = " << sizeof ld + << "\tsizeof(long double) = " << sizeof( long double ) + << "\nsizeof array = " << sizeof array + << "\nsizeof ptr = " << sizeof ptr + << 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/Prog1/examples/ch05/Fig05_20.cpp b/Bachelor/Prog1/examples/ch05/Fig05_20.cpp new file mode 100644 index 0000000..63bc2f7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_20.cpp @@ -0,0 +1,60 @@ +// Fig. 5.20: fig05_20.cpp +// Using subscripting and pointer notations with arrays. + +#include + +using std::cout; +using std::endl; + +int main() +{ + int b[] = { 10, 20, 30, 40 }; + int *bPtr = b; // set bPtr to point to array b + + // output array b using array subscript notation + cout << "Array b printed with:\n\n" + << "Array subscript notation\n"; + + for ( int i = 0; i < 4; i++ ) + cout << "b[" << i << "] = " << b[ i ] << '\n'; + + // output array b using the array name and + // pointer/offset notation + cout << "\nPointer/offset notation where " + << "the pointer is the array name\n"; + + for ( int offset1 = 0; offset1 < 4; offset1++ ) + cout << "*(b + " << offset1 << ") = " + << *( b + offset1 ) << '\n'; + + // output array b using bPtr and array subscript notation + cout << "\nPointer subscript notation\n"; + + for ( int j = 0; j < 4; j++ ) + cout << "bPtr[" << j << "] = " << bPtr[ j ] << '\n'; + + cout << "\nPointer/offset notation\n"; + + // output array b using bPtr and pointer/offset notation + for ( int offset2 = 0; offset2 < 4; offset2++ ) + cout << "*(bPtr + " << offset2 << ") = " + << *( bPtr + offset2 ) << '\n'; + + 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/Prog1/examples/ch05/Fig05_21.cpp b/Bachelor/Prog1/examples/ch05/Fig05_21.cpp new file mode 100644 index 0000000..e045aba --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_21.cpp @@ -0,0 +1,58 @@ +// Fig. 5.21: fig05_21.cpp +// Copying a string using array notation +// and pointer notation. +#include + +using std::cout; +using std::endl; + +void copy1( char *, const char * ); // prototype +void copy2( char *, const char * ); // prototype + +int main() +{ + char string1[ 10 ]; + char *string2 = "Hello"; + char string3[ 10 ]; + char string4[] = "Good Bye"; + + copy1( string1, string2 ); + cout << "string1 = " << string1 << endl; + + copy2( string3, string4 ); + cout << "string3 = " << string3 << endl; + + return 0; // indicates successful termination + +} // end main + +// copy s2 to s1 using array notation +void copy1( char *s1, const char *s2 ) +{ + for ( int i = 0; ( s1[ i ] = s2[ i ] ) != '\0'; i++ ) + ; // do nothing in body + +} // end function copy1 + +// copy s2 to s1 using pointer notation +void copy2( char *s1, const char *s2 ) +{ + for ( ; ( *s1 = *s2 ) != '\0'; s1++, s2++ ) + ; // do nothing in body + +} // end function copy2 + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_24.cpp b/Bachelor/Prog1/examples/ch05/Fig05_24.cpp new file mode 100644 index 0000000..746fd13 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_24.cpp @@ -0,0 +1,103 @@ +// Fig. 5.24: fig05_24.cpp +// Card shuffling dealing program. +#include + +using std::cout; +using std::left; +using std::right; + +#include + +using std::setw; + +#include // prototypes for rand and srand +#include // prototype for time + +// prototypes +void shuffle( int [][ 13 ] ); +void deal( const int [][ 13 ], const char *[], const char *[] ); + +int main() +{ + // initialize suit array + const char *suit[ 4 ] = + { "Hearts", "Diamonds", "Clubs", "Spades" }; + + // initialize face array + const char *face[ 13 ] = + { "Ace", "Deuce", "Three", "Four", + "Five", "Six", "Seven", "Eight", + "Nine", "Ten", "Jack", "Queen", "King" }; + + // initialize deck array + int deck[ 4 ][ 13 ] = { 0 }; + + srand( time( 0 ) ); // seed random number generator + + shuffle( deck ); + deal( deck, face, suit ); + + return 0; // indicates successful termination + +} // end main + +// shuffle cards in deck +void shuffle( int wDeck[][ 13 ] ) +{ + int row; + int column; + + // for each of the 52 cards, choose slot of deck randomly + for ( int card = 1; card <= 52; card++ ) { + + // choose new random location until unoccupied slot found + do { + row = rand() % 4; + column = rand() % 13; + } while( wDeck[ row ][ column ] != 0 ); // end do/while + + // place card number in chosen slot of deck + wDeck[ row ][ column ] = card; + + } // end for + +} // end function shuffle + +// deal cards in deck +void deal( const int wDeck[][ 13 ], const char *wFace[], + const char *wSuit[] ) +{ + // for each of the 52 cards + for ( int card = 1; card <= 52; card++ ) + + // loop through rows of wDeck + for ( int row = 0; row <= 3; row++ ) + + // loop through columns of wDeck for current row + for ( int column = 0; column <= 12; column++ ) + + // if slot contains current card, display card + if ( wDeck[ row ][ column ] == card ) { + cout << setw( 5 ) << right << wFace[ column ] + << " of " << setw( 8 ) << left + << wSuit[ row ] + << ( card % 2 == 0 ? '\n' : '\t' ); + + } // end if + +} // end function deal + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_25.cpp b/Bachelor/Prog1/examples/ch05/Fig05_25.cpp new file mode 100644 index 0000000..8073108 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_25.cpp @@ -0,0 +1,115 @@ +// Fig. 5.25: fig05_25.cpp +// Multipurpose sorting program using function pointers. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::setw; + +// prototypes +void bubble( int [], const int, bool (*)( int, int ) ); +void swap( int * const, int * const ); +bool ascending( int, int ); +bool descending( int, int ); + +int main() +{ + const int arraySize = 10; + int order; + int counter; + int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; + + cout << "Enter 1 to sort in ascending order,\n" + << "Enter 2 to sort in descending order: "; + cin >> order; + cout << "\nData items in original order\n"; + + // output original array + for ( counter = 0; counter < arraySize; counter++ ) + cout << setw( 4 ) << a[ counter ]; + + // sort array in ascending order; pass function ascending + // as an argument to specify ascending sorting order + if ( order == 1 ) { + bubble( a, arraySize, ascending ); + cout << "\nData items in ascending order\n"; + } + + // sort array in descending order; pass function descending + // as an argument to specify descending sorting order + else { + bubble( a, arraySize, descending ); + cout << "\nData items in descending order\n"; + } + + // output sorted array + for ( counter = 0; counter < arraySize; counter++ ) + cout << setw( 4 ) << a[ counter ]; + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// multipurpose bubble sort; parameter compare is a pointer to +// the comparison function that determines sorting order +void bubble( int work[], const int size, + bool (*compare)( int, int ) ) +{ + // loop to control passes + for ( int pass = 1; pass < size; pass++ ) + + // loop to control number of comparisons per pass + for ( int count = 0; count < size - 1; count++ ) + + // if adjacent elements are out of order, swap them + if ( (*compare)( work[ count ], work[ count + 1 ] ) ) + swap( &work[ count ], &work[ count + 1 ] ); + +} // end function bubble + +// swap values at memory locations to which +// element1Ptr and element2Ptr point +void swap( int * const element1Ptr, int * const element2Ptr ) +{ + int hold = *element1Ptr; + *element1Ptr = *element2Ptr; + *element2Ptr = hold; + +} // end function swap + +// determine whether elements are out of order +// for an ascending order sort +bool ascending( int a, int b ) +{ + return b < a; // swap if b is less than a + +} // end function ascending + +// determine whether elements are out of order +// for a descending order sort +bool descending( int a, int b ) +{ + return b > a; // swap if b is greater than a + +} // end function descending + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_26.cpp b/Bachelor/Prog1/examples/ch05/Fig05_26.cpp new file mode 100644 index 0000000..916dbb9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_26.cpp @@ -0,0 +1,76 @@ +// Fig. 5.26: fig05_26.cpp +// Demonstrating an array of pointers to functions. +#include + +using std::cout; +using std::cin; +using std::endl; + +// function prototypes +void function1( int ); +void function2( int ); +void function3( int ); + +int main() +{ + // initialize array of 3 pointers to functions that each + // take an int argument and return void + void (*f[ 3 ])( int ) = { function1, function2, function3 }; + + int choice; + + cout << "Enter a number between 0 and 2, 3 to end: "; + cin >> choice; + + // process user's choice + while ( choice >= 0 && choice < 3 ) { + + // invoke function at location choice in array f + // and pass choice as an argument + (*f[ choice ])( choice ); + + cout << "Enter a number between 0 and 2, 3 to end: "; + cin >> choice; + } + + cout << "Program execution completed." << endl; + + return 0; // indicates successful termination + +} // end main + +void function1( int a ) +{ + cout << "You entered " << a + << " so function1 was called\n\n"; + +} // end function1 + +void function2( int b ) +{ + cout << "You entered " << b + << " so function2 was called\n\n"; + +} // end function2 + +void function3( int c ) +{ + cout << "You entered " << c + << " so function3 was called\n\n"; + +} // end function3 + +/************************************************************************** + * (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/Prog1/examples/ch05/Fig05_28.cpp b/Bachelor/Prog1/examples/ch05/Fig05_28.cpp new file mode 100644 index 0000000..d973c37 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_28.cpp @@ -0,0 +1,44 @@ +// Fig. 5.28: fig05_28.cpp +// Using strcpy and strncpy. +#include + +using std::cout; +using std::endl; + +#include // prototypes for strcpy and strncpy + +int main() +{ + char x[] = "Happy Birthday to You"; + char y[ 25 ]; + char z[ 15 ]; + + strcpy( y, x ); // copy contents of x into y + + cout << "The string in array x is: " << x + << "\nThe string in array y is: " << y << '\n'; + + // copy first 14 characters of x into z + strncpy( z, x, 14 ); // does not copy null character + z[ 14 ] = '\0'; // append '\0' to z's contents + + cout << "The string in array z is: " << z << 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/Prog1/examples/ch05/Fig05_29.cpp b/Bachelor/Prog1/examples/ch05/Fig05_29.cpp new file mode 100644 index 0000000..daa58f6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_29.cpp @@ -0,0 +1,50 @@ +// Fig. 5.29: fig05_29.cpp +// Using strcat and strncat. +#include + +using std::cout; +using std::endl; + +#include // prototypes for strcat and strncat + +int main() +{ + char s1[ 20 ] = "Happy "; + char s2[] = "New Year "; + char s3[ 40 ] = ""; + + cout << "s1 = " << s1 << "\ns2 = " << s2; + + strcat( s1, s2 ); // concatenate s2 to s1 + + cout << "\n\nAfter strcat(s1, s2):\ns1 = " << s1 + << "\ns2 = " << s2; + + // concatenate first 6 characters of s1 to s3 + strncat( s3, s1, 6 ); // places '\0' after last character + + cout << "\n\nAfter strncat(s3, s1, 6):\ns1 = " << s1 + << "\ns3 = " << s3; + + strcat( s3, s1 ); // concatenate s1 to s3 + cout << "\n\nAfter strcat(s3, s1):\ns1 = " << s1 + << "\ns3 = " << s3 << 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/Prog1/examples/ch05/Fig05_30.cpp b/Bachelor/Prog1/examples/ch05/Fig05_30.cpp new file mode 100644 index 0000000..1f55555 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_30.cpp @@ -0,0 +1,50 @@ +// Fig. 5.30: fig05_30.cpp +// Using strcmp and strncmp. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include // prototypes for strcmp and strncmp + +int main() +{ + char *s1 = "Happy New Year"; + char *s2 = "Happy New Year"; + char *s3 = "Happy Holidays"; + + cout << "s1 = " << s1 << "\ns2 = " << s2 + << "\ns3 = " << s3 << "\n\nstrcmp(s1, s2) = " + << setw( 2 ) << strcmp( s1, s2 ) + << "\nstrcmp(s1, s3) = " << setw( 2 ) + << strcmp( s1, s3 ) << "\nstrcmp(s3, s1) = " + << setw( 2 ) << strcmp( s3, s1 ); + + cout << "\n\nstrncmp(s1, s3, 6) = " << setw( 2 ) + << strncmp( s1, s3, 6 ) << "\nstrncmp(s1, s3, 7) = " + << setw( 2 ) << strncmp( s1, s3, 7 ) + << "\nstrncmp(s3, s1, 7) = " + << setw( 2 ) << strncmp( s3, s1, 7 ) << 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/Prog1/examples/ch05/Fig05_31.cpp b/Bachelor/Prog1/examples/ch05/Fig05_31.cpp new file mode 100644 index 0000000..280bddc --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_31.cpp @@ -0,0 +1,47 @@ +// Fig. 5.31: fig05_31.cpp +// Using strtok. +#include + +using std::cout; +using std::endl; + +#include // prototype for strtok + +int main() +{ + char sentence[] = "This is a sentence with 7 tokens"; + char *tokenPtr; + + cout << "The string to be tokenized is:\n" << sentence + << "\n\nThe tokens are:\n\n"; + + // begin tokenization of sentence + tokenPtr = strtok( sentence, " " ); + + // continue tokenizing sentence until tokenPtr becomes NULL + while ( tokenPtr != NULL ) { + cout << tokenPtr << '\n'; + tokenPtr = strtok( NULL, " " ); // get next token + + } // end while + + cout << "\nAfter strtok, sentence = " << sentence << 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/Prog1/examples/ch05/Fig05_32.cpp b/Bachelor/Prog1/examples/ch05/Fig05_32.cpp new file mode 100644 index 0000000..ae612dd --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_32.cpp @@ -0,0 +1,40 @@ +// Fig. 5.32: fig05_32.cpp +// Using strlen. +#include + +using std::cout; +using std::endl; + +#include // prototype for strlen + +int main() +{ + char *string1 = "abcdefghijklmnopqrstuvwxyz"; + char *string2 = "four"; + char *string3 = "Boston"; + + cout << "The length of \"" << string1 + << "\" is " << strlen( string1 ) + << "\nThe length of \"" << string2 + << "\" is " << strlen( string2 ) + << "\nThe length of \"" << string3 + << "\" is " << strlen( string3 ) << 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/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp b/Bachelor/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp new file mode 100644 index 0000000..0126a02 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp @@ -0,0 +1,82 @@ +// Fig. 6.1: fig06_01.cpp +// Create a structure, set its members, and print it. +#include + +using std::cout; +using std::endl; + +#include + +using std::setfill; +using std::setw; + +// structure definition +struct Time { + int hour; // 0-23 (24-hour clock format) + int minute; // 0-59 + int second; // 0-59 + +}; // end struct Time + +void printUniversal( const Time & ); // prototype +void printStandard( const Time & ); // prototype + +int main() +{ + Time dinnerTime; // variable of new type Time + + dinnerTime.hour = 18; // set hour member of dinnerTime + dinnerTime.minute = 30; // set minute member of dinnerTime + dinnerTime.second = 0; // set second member of dinnerTime + + cout << "Dinner will be held at "; + printUniversal( dinnerTime ); + cout << " universal time,\nwhich is "; + printStandard( dinnerTime ); + cout << " standard time.\n"; + + dinnerTime.hour = 29; // set hour to invalid value + dinnerTime.minute = 73; // set minute to invalid value + + cout << "\nTime with invalid values: "; + printUniversal( dinnerTime ); + cout << endl; + + return 0; + +} // end main + +// print time in universal-time format +void printUniversal( const Time &t ) +{ + cout << setfill( '0' ) << setw( 2 ) << t.hour << ":" + << setw( 2 ) << t.minute << ":" + << setw( 2 ) << t.second; + +} // end function printUniversal + +// print time in standard-time format +void printStandard( const Time &t ) +{ + cout << ( ( t.hour == 0 || t.hour == 12 ) ? + 12 : t.hour % 12 ) << ":" << setfill( '0' ) + << setw( 2 ) << t.minute << ":" + << setw( 2 ) << t.second + << ( t.hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp b/Bachelor/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp new file mode 100644 index 0000000..3bb7a28 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp @@ -0,0 +1,114 @@ +// Fig. 6.3: fig06_03.cpp +// Time class. +#include + +using std::cout; +using std::endl; + +#include + +using std::setfill; +using std::setw; + +// Time abstract data type (ADT) definition +class Time { + +public: + Time(); // constructor + void setTime( int, int, int ); // set hour, minute, second + void printUniversal(); // print universal-time format + void printStandard(); // print standard-time format + +private: + int hour; // 0 - 23 (24-hour clock format) + int minute; // 0 - 59 + int second; // 0 - 59 + +}; // end class Time + +// Time constructor initializes each data member to zero and +// ensures all Time objects start in a consistent state +Time::Time() +{ + hour = minute = second = 0; + +} // end constructor Time + +// set new Time value using universal time, perform validity +// checks on the data values and set invalid values to zero +void Time::setTime( int h, int m, int s ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + minute = ( m >= 0 && m < 60 ) ? m : 0; + second = ( s >= 0 && s < 60 ) ? s : 0; + +} // end function setTime + +// print Time in universal format +void Time::printUniversal() +{ + cout << setfill( '0' ) << setw( 2 ) << hour << ":" + << setw( 2 ) << minute << ":" + << setw( 2 ) << second; + +} // end function printUniversal + +// print Time in standard format +void Time::printStandard() +{ + cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) + << ":" << setfill( '0' ) << setw( 2 ) << minute + << ":" << setw( 2 ) << second + << ( hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +int main() +{ + Time t; // instantiate object t of class Time + + // output Time object t's initial values + cout << "The initial universal time is "; + t.printUniversal(); // 00:00:00 + + cout << "\nThe initial standard time is "; + t.printStandard(); // 12:00:00 AM + + t.setTime( 13, 27, 6 ); // change time + + // output Time object t's new values + cout << "\n\nUniversal time after setTime is "; + t.printUniversal(); // 13:27:06 + + cout << "\nStandard time after setTime is "; + t.printStandard(); // 1:27:06 PM + + t.setTime( 99, 99, 99 ); // attempt invalid settings + + // output t's values after specifying invalid values + cout << "\n\nAfter attempting invalid settings:" + << "\nUniversal time: "; + t.printUniversal(); // 00:00:00 + + cout << "\nStandard time: "; + t.printStandard(); // 12:00:00 AM + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp b/Bachelor/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp new file mode 100644 index 0000000..68c1be3 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp @@ -0,0 +1,58 @@ +// Fig. 6.4: fig06_04.cpp +// Demonstrating the class member access operators . and -> +// +// CAUTION: IN FUTURE EXAMPLES WE AVOID PUBLIC DATA! +#include + +using std::cout; +using std::endl; + +// class Count definition +class Count { + +public: + int x; + + void print() + { + cout << x << endl; + } + +}; // end class Count + +int main() +{ + Count counter; // create counter object + Count *counterPtr = &counter; // create pointer to counter + Count &counterRef = counter; // create reference to counter + + cout << "Assign 1 to x and print using the object's name: "; + counter.x = 1; // assign 1 to data member x + counter.print(); // call member function print + + cout << "Assign 2 to x and print using a reference: "; + counterRef.x = 2; // assign 2 to data member x + counterRef.print(); // call member function print + + cout << "Assign 3 to x and print using a pointer: "; + counterPtr->x = 3; // assign 3 to data member x + counterPtr->print(); // call member function print + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp new file mode 100644 index 0000000..85cca47 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp @@ -0,0 +1,57 @@ +// Fig. 6.7: fig06_07.cpp +// Program to test class Time. +// NOTE: This file must be compiled with time1.cpp. +#include + +using std::cout; +using std::endl; + +// include definition of class Time from time1.h +#include "time1.h" + +int main() +{ + Time t; // instantiate object t of class Time + + // output Time object t's initial values + cout << "The initial universal time is "; + t.printUniversal(); // 00:00:00 + cout << "\nThe initial standard time is "; + t.printStandard(); // 12:00:00 AM + + t.setTime( 13, 27, 6 ); // change time + + // output Time object t's new values + cout << "\n\nUniversal time after setTime is "; + t.printUniversal(); // 13:27:06 + cout << "\nStandard time after setTime is "; + t.printStandard(); // 1:27:06 PM + + t.setTime( 99, 99, 99 ); // attempt invalid settings + + // output t's values after specifying invalid values + cout << "\n\nAfter attempting invalid settings:" + << "\nUniversal time: "; + t.printUniversal(); // 00:00:00 + cout << "\nStandard time: "; + t.printStandard(); // 12:00:00 AM + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_05_07/Time1.cpp b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.cpp new file mode 100644 index 0000000..6ffea1c --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.cpp @@ -0,0 +1,65 @@ +// Fig. 6.6: time1.cpp +// Member-function definitions for class Time. +#include + +using std::cout; + +#include + +using std::setfill; +using std::setw; + +// include definition of class Time from time1.h +#include "time1.h" + +// Time constructor initializes each data member to zero. +// Ensures all Time objects start in a consistent state. +Time::Time() +{ + hour = minute = second = 0; + +} // end Time constructor + +// Set new Time value using universal time. Perform validity +// checks on the data values. Set invalid values to zero. +void Time::setTime( int h, int m, int s ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + minute = ( m >= 0 && m < 60 ) ? m : 0; + second = ( s >= 0 && s < 60 ) ? s : 0; + +} // end function setTime + +// print Time in universal format +void Time::printUniversal() +{ + cout << setfill( '0' ) << setw( 2 ) << hour << ":" + << setw( 2 ) << minute << ":" + << setw( 2 ) << second; + +} // end function printUniversal + +// print Time in standard format +void Time::printStandard() +{ + cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) + << ":" << setfill( '0' ) << setw( 2 ) << minute + << ":" << setw( 2 ) << second + << ( hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_05_07/Time1.h b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.h new file mode 100644 index 0000000..9adaba7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.h @@ -0,0 +1,40 @@ +// Fig. 6.5: time1.h +// Declaration of class Time. +// Member functions are defined in time1.cpp + +// prevent multiple inclusions of header file +#ifndef TIME1_H +#define TIME1_H + +// Time abstract data type definition +class Time { + +public: + Time(); // constructor + void setTime( int, int, int ); // set hour, minute, second + void printUniversal(); // print universal-time format + void printStandard(); // print standard-time format + +private: + int hour; // 0 - 23 (24-hour clock format) + int minute; // 0 - 59 + int second; // 0 - 59 + +}; // end class Time + +#endif + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp b/Bachelor/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp new file mode 100644 index 0000000..93cacc4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp @@ -0,0 +1,38 @@ +// Fig. 6.8: fig06_08.cpp +// Demonstrate errors resulting from attempts +// to access private class members. +#include + +using std::cout; + +// include definition of class Time from time1.h +#include "time1.h" + +int main() +{ + Time t; // create Time object + + + t.hour = 7; // error: 'Time::hour' is not accessible + + // error: 'Time::minute' is not accessible + cout << "minute = " << t.minute; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_08/Time1.cpp b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.cpp new file mode 100644 index 0000000..0f53ccf --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.cpp @@ -0,0 +1,65 @@ +// Fig. 6.6: time1.cpp +// Member-function definitions for class Time. +#include + +using std::cout; + +#include + +using std::setfill; +using std::setw; + +// include definition of class Time from time1.h +#include "time1.h" + +// Time constructor initializes each data member to zero. +// Ensures all Time objects start in a consistent state. +Time::Time() +{ + hour = minute = second = 0; + +} // end Time constructor + +// Set new Time value using universal time. Perform validity +// checks on the data values. Set invalid values to zero. +void Time::setTime( int h, int m, int s ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + minute = ( m >= 0 && m < 60 ) ? m : 0; + second = ( s >= 0 && s < 60 ) ? s : 0; + +} // end function setTime + +// print Time in universal format +void Time::printUniversal() +{ + cout << setfill( '0' ) << setw( 2 ) << hour << ":" + << setw( 2 ) << minute << ":" + << setw( 2 ) << second; + +} // end function printUniversal + +// print Time in standard format +void Time::printStandard() +{ + cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) + << ":" << setfill( '0' ) << setw( 2 ) << minute + << ":" << setw( 2 ) << second + << ( hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_08/Time1.h b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.h new file mode 100644 index 0000000..9adaba7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.h @@ -0,0 +1,40 @@ +// Fig. 6.5: time1.h +// Declaration of class Time. +// Member functions are defined in time1.cpp + +// prevent multiple inclusions of header file +#ifndef TIME1_H +#define TIME1_H + +// Time abstract data type definition +class Time { + +public: + Time(); // constructor + void setTime( int, int, int ); // set hour, minute, second + void printUniversal(); // print universal-time format + void printStandard(); // print standard-time format + +private: + int hour; // 0 - 23 (24-hour clock format) + int minute; // 0 - 59 + int second; // 0 - 59 + +}; // end class Time + +#endif + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp new file mode 100644 index 0000000..82787f6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp @@ -0,0 +1,32 @@ +// Fig. 6.11: fig06_11.cpp +// Demonstrating a utility function. +// Compile this program with salesp.cpp + +// include SalesPerson class definition from salesp.h +#include "salesp.h" + +int main() +{ + SalesPerson s; // create SalesPerson object s + + s.getSalesFromUser(); // note simple sequential code; no + s.printAnnualSales(); // control structures in main + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_09_11/Salesp.cpp b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.cpp new file mode 100644 index 0000000..4c05a6d --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.cpp @@ -0,0 +1,86 @@ +// Fig. 6.10: salesp.cpp +// Member functions for class SalesPerson. +#include + +using std::cout; +using std::cin; +using std::endl; +using std::fixed; + +#include + +using std::setprecision; + +// include SalesPerson class definition from salesp.h +#include "salesp.h" + +// initialize elements of array sales to 0.0 +SalesPerson::SalesPerson() +{ + for ( int i = 0; i < 12; i++ ) + sales[ i ] = 0.0; + +} // end SalesPerson constructor + +// get 12 sales figures from the user at the keyboard +void SalesPerson::getSalesFromUser() +{ + double salesFigure; + + for ( int i = 1; i <= 12; i++ ) { + cout << "Enter sales amount for month " << i << ": "; + cin >> salesFigure; + setSales( i, salesFigure ); + + } // end for + +} // end function getSalesFromUser + +// set one of the 12 monthly sales figures; function subtracts +// one from month value for proper subscript in sales array +void SalesPerson::setSales( int month, double amount ) +{ + // test for valid month and amount values + if ( month >= 1 && month <= 12 && amount > 0 ) + sales[ month - 1 ] = amount; // adjust for subscripts 0-11 + + else // invalid month or amount value + cout << "Invalid month or sales figure" << endl; + +} // end function setSales + +// print total annual sales (with the help of utility function) +void SalesPerson::printAnnualSales() +{ + cout << setprecision( 2 ) << fixed + << "\nThe total annual sales are: $" + << totalAnnualSales() << endl; // call utility function + +} // end function printAnnualSales + +// private utility function to total annual sales +double SalesPerson::totalAnnualSales() +{ + double total = 0.0; // initialize total + + for ( int i = 0; i < 12; i++ ) // summarize sales results + total += sales[ i ]; + + return total; + +} // end function totalAnnualSales + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_09_11/Salesp.h b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.h new file mode 100644 index 0000000..240e3e7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.h @@ -0,0 +1,36 @@ +// Fig. 6.9: salesp.h +// SalesPerson class definition. +// Member functions defined in salesp.cpp. +#ifndef SALESP_H +#define SALESP_H + +class SalesPerson { + +public: + SalesPerson(); // constructor + void getSalesFromUser(); // input sales from keyboard + void setSales( int, double ); // set sales for a month + void printAnnualSales(); // summarize and print sales + +private: + double totalAnnualSales(); // utility function + double sales[ 12 ]; // 12 monthly sales figures + +}; // end class SalesPerson + +#endif + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp new file mode 100644 index 0000000..8a7546a --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp @@ -0,0 +1,63 @@ +// Fig. 6.14: fig06_14.cpp +// Demonstrating a default constructor for class Time. +#include + +using std::cout; +using std::endl; + +// include definition of class Time from time2.h +#include "time2.h" + +int main() +{ + Time t1; // all arguments defaulted + Time t2( 2 ); // minute and second defaulted + Time t3( 21, 34 ); // second defaulted + Time t4( 12, 25, 42 ); // all values specified + Time t5( 27, 74, 99 ); // all bad values specified + + cout << "Constructed with:\n\n" + << "all default arguments:\n "; + t1.printUniversal(); // 00:00:00 + cout << "\n "; + t1.printStandard(); // 12:00:00 AM + + cout << "\n\nhour specified; default minute and second:\n "; + t2.printUniversal(); // 02:00:00 + cout << "\n "; + t2.printStandard(); // 2:00:00 AM + + cout << "\n\nhour and minute specified; default second:\n "; + t3.printUniversal(); // 21:34:00 + cout << "\n "; + t3.printStandard(); // 9:34:00 PM + + cout << "\n\nhour, minute, and second specified:\n "; + t4.printUniversal(); // 12:25:42 + cout << "\n "; + t4.printStandard(); // 12:25:42 PM + + cout << "\n\nall invalid values specified:\n "; + t5.printUniversal(); // 00:00:00 + cout << "\n "; + t5.printStandard(); // 12:00:00 AM + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_12_14/Time2.cpp b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.cpp new file mode 100644 index 0000000..5a5d42c --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.cpp @@ -0,0 +1,65 @@ +// Fig. 6.13: time2.cpp +// Member-function definitions for class Time. +#include + +using std::cout; + +#include + +using std::setfill; +using std::setw; + +// include definition of class Time from time2.h +#include "time2.h" + +// Time constructor initializes each data member to zero; +// ensures all Time objects start in a consistent state +Time::Time( int hr, int min, int sec ) +{ + setTime( hr, min, sec ); // validate and set time + +} // end Time constructor + +// set new Time value using universal time, perform validity +// checks on the data values and set invalid values to zero +void Time::setTime( int h, int m, int s ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + minute = ( m >= 0 && m < 60 ) ? m : 0; + second = ( s >= 0 && s < 60 ) ? s : 0; + +} // end function setTime + +// print Time in universal format +void Time::printUniversal() +{ + cout << setfill( '0' ) << setw( 2 ) << hour << ":" + << setw( 2 ) << minute << ":" + << setw( 2 ) << second; + +} // end function printUniversal + +// print Time in standard format +void Time::printStandard() +{ + cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) + << ":" << setfill( '0' ) << setw( 2 ) << minute + << ":" << setw( 2 ) << second + << ( hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_12_14/Time2.h b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.h new file mode 100644 index 0000000..3b99b88 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.h @@ -0,0 +1,40 @@ +// Fig. 6.12: time2.h +// Declaration of class Time. +// Member functions defined in time2.cpp. + +// prevent multiple inclusions of header file +#ifndef TIME2_H +#define TIME2_H + +// Time abstract data type definition +class Time { + +public: + Time( int = 0, int = 0, int = 0); // default constructor + void setTime( int, int, int ); // set hour, minute, second + void printUniversal(); // print universal-time format + void printStandard(); // print standard-time format + +private: + int hour; // 0 - 23 (24-hour clock format) + int minute; // 0 - 59 + int second; // 0 - 59 + +}; // end class Time + +#endif + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_15_17/Create.cpp b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.cpp new file mode 100644 index 0000000..1f7614f --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.cpp @@ -0,0 +1,47 @@ +// Fig. 6.16: create.cpp +// Member-function definitions for class CreateAndDestroy +#include + +using std::cout; +using std::endl; + +// include CreateAndDestroy class definition from create.h +#include "create.h" + +// constructor +CreateAndDestroy::CreateAndDestroy( + int objectNumber, char *messagePtr ) +{ + objectID = objectNumber; + message = messagePtr; + + cout << "Object " << objectID << " constructor runs " + << message << endl; + +} // end CreateAndDestroy constructor + +// destructor +CreateAndDestroy::~CreateAndDestroy() +{ + // the following line is for pedagogic purposes only + cout << ( objectID == 1 || objectID == 6 ? "\n" : "" ); + + cout << "Object " << objectID << " destructor runs " + << message << endl; + +} // end ~CreateAndDestroy destructor + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_15_17/Create.h b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.h new file mode 100644 index 0000000..f0a73cb --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.h @@ -0,0 +1,34 @@ +// Fig. 6.15: create.h +// Definition of class CreateAndDestroy. +// Member functions defined in create.cpp. +#ifndef CREATE_H +#define CREATE_H + +class CreateAndDestroy { + +public: + CreateAndDestroy( int, char * ); // constructor + ~CreateAndDestroy(); // destructor + +private: + int objectID; + char *message; + +}; // end class CreateAndDestroy + +#endif + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp new file mode 100644 index 0000000..3bd2906 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp @@ -0,0 +1,68 @@ +// Fig. 6.17: fig06_17.cpp +// Demonstrating the order in which constructors and +// destructors are called. +#include + +using std::cout; +using std::endl; + +// include CreateAndDestroy class definition from create.h +#include "create.h" + +void create( void ); // prototype + +// global object +CreateAndDestroy first( 1, "(global before main)" ); + +int main() +{ + cout << "\nMAIN FUNCTION: EXECUTION BEGINS" << endl; + + CreateAndDestroy second( 2, "(local automatic in main)" ); + + static CreateAndDestroy third( + 3, "(local static in main)" ); + + create(); // call function to create objects + + cout << "\nMAIN FUNCTION: EXECUTION RESUMES" << endl; + + CreateAndDestroy fourth( 4, "(local automatic in main)" ); + + cout << "\nMAIN FUNCTION: EXECUTION ENDS" << endl; + + return 0; + +} // end main + +// function to create objects +void create( void ) +{ + cout << "\nCREATE FUNCTION: EXECUTION BEGINS" << endl; + + CreateAndDestroy fifth( 5, "(local automatic in create)" ); + + static CreateAndDestroy sixth( + 6, "(local static in create)" ); + + CreateAndDestroy seventh( + 7, "(local automatic in create)" ); + + cout << "\nCREATE FUNCTION: EXECUTION ENDS" << endl; + +} // end function create + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp new file mode 100644 index 0000000..58f5bb9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp @@ -0,0 +1,82 @@ +// Fig. 6.20: fig06_20.cpp +// Demonstrating the Time class set and get functions +#include + +using std::cout; +using std::endl; + +// include definition of class Time from time3.h +#include "time3.h" + +void incrementMinutes( Time &, const int ); // prototype + +int main() +{ + Time t; // create Time object + + // set time using individual set functions + t.setHour( 17 ); // set hour to valid value + t.setMinute( 34 ); // set minute to valid value + t.setSecond( 25 ); // set second to valid value + + // use get functions to obtain hour, miunute and second + cout << "Result of setting all valid values:\n" + << " Hour: " << t.getHour() + << " Minute: " << t.getMinute() + << " Second: " << t.getSecond(); + + // set time using individual set functions + t.setHour( 234 ); // invalid hour set to 0 + t.setMinute( 43 ); // set minute to valid value + t.setSecond( 6373 ); // invalid second set to 0 + + // display hour, minute and second after setting + // invalid hour and second values + cout << "\n\nResult of attempting to set invalid hour and" + << " second:\n Hour: " << t.getHour() + << " Minute: " << t.getMinute() + << " Second: " << t.getSecond() << "\n\n"; + + t.setTime( 11, 58, 0 ); // set time + incrementMinutes( t, 3 ); // increment t's minute by 3 + + return 0; + +} // end main + +// add specified number of minutes to a Time object +void incrementMinutes( Time &tt, const int count ) +{ + cout << "Incrementing minute " << count + << " times:\nStart time: "; + tt.printStandard(); + + for ( int i = 0; i < count; i++ ) { + tt.setMinute( ( tt.getMinute() + 1 ) % 60 ); + + if ( tt.getMinute() == 0 ) + tt.setHour( ( tt.getHour() + 1 ) % 24 ); + + cout << "\nminute + 1: "; + tt.printStandard(); + + } // end for + + cout << endl; + +} // end function incrementMinutes + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_18_20/Time3.cpp b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.cpp new file mode 100644 index 0000000..7cf0176 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.cpp @@ -0,0 +1,107 @@ +// Fig. 6.19: time3.cpp +// Member-function definitions for Time class. +#include + +using std::cout; + +#include + +using std::setfill; +using std::setw; + +// include definition of class Time from time3.h +#include "time3.h" + +// constructor function to initialize private data; +// calls member function setTime to set variables; +// default values are 0 (see class definition) +Time::Time( int hr, int min, int sec ) +{ + setTime( hr, min, sec ); + +} // end Time constructor + +// set hour, minute and second values +void Time::setTime( int h, int m, int s ) +{ + setHour( h ); + setMinute( m ); + setSecond( s ); + +} // end function setTime + +// set hour value +void Time::setHour( int h ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + +} // end function setHour + +// set minute value +void Time::setMinute( int m ) +{ + minute = ( m >= 0 && m < 60 ) ? m : 0; + +} // end function setMinute + +// set second value +void Time::setSecond( int s ) +{ + second = ( s >= 0 && s < 60 ) ? s : 0; + +} // end function setSecond + +// return hour value +int Time::getHour() +{ + return hour; + +} // end function getHour + +// return minute value +int Time::getMinute() +{ + return minute; + +} // end function getMinute + +// return second value +int Time::getSecond() +{ + return second; + +} // end function getSecond + +// print Time in universal format +void Time::printUniversal() +{ + cout << setfill( '0' ) << setw( 2 ) << hour << ":" + << setw( 2 ) << minute << ":" + << setw( 2 ) << second; + +} // end function printUniversal + +// print Time in standard format +void Time::printStandard() +{ + cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) + << ":" << setfill( '0' ) << setw( 2 ) << minute + << ":" << setw( 2 ) << second + << ( hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_18_20/Time3.h b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.h new file mode 100644 index 0000000..2f68d31 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.h @@ -0,0 +1,50 @@ +// Fig. 6.18: time3.h +// Declaration of class Time. +// Member functions defined in time3.cpp + +// prevent multiple inclusions of header file +#ifndef TIME3_H +#define TIME3_H + +class Time { + +public: + Time( int = 0, int = 0, int = 0 ); // default constructor + + // set functions + void setTime( int, int, int ); // set hour, minute, second + void setHour( int ); // set hour + void setMinute( int ); // set minute + void setSecond( int ); // set second + + // get functions + int getHour(); // return hour + int getMinute(); // return minute + int getSecond(); // return second + + void printUniversal(); // output universal-time format + void printStandard(); // output standard-time format + +private: + int hour; // 0 - 23 (24-hour clock format) + int minute; // 0 - 59 + int second; // 0 - 59 + +}; // end clas Time + +#endif + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp new file mode 100644 index 0000000..a5b14b6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp @@ -0,0 +1,53 @@ +// Fig. 6.23: fig06_23.cpp +// Demonstrating a public member function that +// returns a reference to a private data member. +#include + +using std::cout; +using std::endl; + +// include definition of class Time from time4.h +#include "time4.h" + +int main() +{ + Time t; + + // store in hourRef the reference returned by badSetHour + int &hourRef = t.badSetHour( 20 ); + + cout << "Hour before modification: " << hourRef; + + // use hourRef to set invalid value in Time object t + hourRef = 30; + + cout << "\nHour after modification: " << t.getHour(); + + // Dangerous: Function call that returns + // a reference can be used as an lvalue! + t.badSetHour( 12 ) = 74; + + cout << "\n\n*********************************\n" + << "POOR PROGRAMMING PRACTICE!!!!!!!!\n" + << "badSetHour as an lvalue, Hour: " + << t.getHour() + << "\n*********************************" << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_21_23/Time4.cpp b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.cpp new file mode 100644 index 0000000..eef65f2 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.cpp @@ -0,0 +1,55 @@ +// Fig. 6.22: time4.cpp +// Member-function definitions for Time class. + +// include definition of class Time from time4.h +#include "time4.h" + +// constructor function to initialize private data; +// calls member function setTime to set variables; +// default values are 0 (see class definition) +Time::Time( int hr, int min, int sec ) +{ + setTime( hr, min, sec ); + +} // end Time constructor + +// set values of hour, minute and second +void Time::setTime( int h, int m, int s ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + minute = ( m >= 0 && m < 60 ) ? m : 0; + second = ( s >= 0 && s < 60 ) ? s : 0; + +} // end function setTime + +// return hour value +int Time::getHour() +{ + return hour; + +} // end function getHour + +// POOR PROGRAMMING PRACTICE: +// Returning a reference to a private data member. +int &Time::badSetHour( int hh ) +{ + hour = ( hh >= 0 && hh < 24 ) ? hh : 0; + + return hour; // DANGEROUS reference return + +} // end function badSetHour + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_21_23/Time4.h b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.h new file mode 100644 index 0000000..92a5d84 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.h @@ -0,0 +1,40 @@ +// Fig. 6.21: time4.h +// Declaration of class Time. +// Member functions defined in time4.cpp + +// prevent multiple inclusions of header file +#ifndef TIME4_H +#define TIME4_H + +class Time { + +public: + Time( int = 0, int = 0, int = 0 ); + void setTime( int, int, int ); + int getHour(); + + int &badSetHour( int ); // DANGEROUS reference return + +private: + int hour; + int minute; + int second; + +}; // end class Time + +#endif + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp b/Bachelor/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp new file mode 100644 index 0000000..9df3198 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp @@ -0,0 +1,72 @@ +// Fig. 6.24: fig06_24.cpp +// Demonstrating that class objects can be assigned +// to each other using default memberwise assignment. +#include + +using std::cout; +using std::endl; + +// class Date definition +class Date { + +public: + Date( int = 1, int = 1, int = 1990 ); // default constructor + void print(); + +private: + int month; + int day; + int year; + +}; // end class Date + +// Date constructor with no range checking +Date::Date( int m, int d, int y ) +{ + month = m; + day = d; + year = y; + +} // end constructor Date + +// print Date in the format mm-dd-yyyy +void Date::print() +{ + cout << month << '-' << day << '-' << year; + +} // end function print + +int main() +{ + Date date1( 7, 4, 2002 ); + Date date2; // date2 defaults to 1/1/1990 + + cout << "date1 = "; + date1.print(); + cout << "\ndate2 = "; + date2.print(); + + date2 = date1; // default memberwise assignment + + cout << "\n\nAfter default memberwise assignment, date2 = "; + date2.print(); + cout << endl; + + return 0; + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2002 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/Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp new file mode 100644 index 0000000..e2f9ee2 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp @@ -0,0 +1,42 @@ +// Fig. 7.3: fig07_03.cpp +// Attempting to access a const object with +// non-const member functions. + +// include Time class definition from time5.h +#include "time5.h" + +int main() +{ + Time wakeUp( 6, 45, 0 ); // non-constant object + const Time noon( 12, 0, 0 ); // constant object + + // OBJECT MEMBER FUNCTION + wakeUp.setHour( 18 ); // non-const non-const + + noon.setHour( 12 ); // const non-const + + wakeUp.getHour(); // non-const const + + noon.getMinute(); // const const + noon.printUniversal(); // const const + + noon.printStandard(); // const non-const + + 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/Prog1/examples/ch07/Fig07_01_03/Time5.cpp b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.cpp new file mode 100644 index 0000000..a8e8a6b --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.cpp @@ -0,0 +1,107 @@ +// Fig. 7.2: time5.cpp +// Member-function definitions for class Time. +#include + +using std::cout; + +#include + +using std::setfill; +using std::setw; + +// include definition of class Time from time5.h +#include "time5.h" + +// constructor function to initialize private data; +// calls member function setTime to set variables; +// default values are 0 (see class definition) +Time::Time( int hour, int minute, int second ) +{ + setTime( hour, minute, second ); + +} // end Time constructor + +// set hour, minute and second values +void Time::setTime( int hour, int minute, int second ) +{ + setHour( hour ); + setMinute( minute ); + setSecond( second ); + +} // end function setTime + +// set hour value +void Time::setHour( int h ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + +} // end function setHour + +// set minute value +void Time::setMinute( int m ) +{ + minute = ( m >= 0 && m < 60 ) ? m : 0; + +} // end function setMinute + +// set second value +void Time::setSecond( int s ) +{ + second = ( s >= 0 && s < 60 ) ? s : 0; + +} // end function setSecond + +// return hour value +int Time::getHour() const +{ + return hour; + +} // end function getHour + +// return minute value +int Time::getMinute() const +{ + return minute; + +} // end function getMinute + +// return second value +int Time::getSecond() const +{ + return second; + +} // end function getSecond + +// print Time in universal format +void Time::printUniversal() const +{ + cout << setfill( '0' ) << setw( 2 ) << hour << ":" + << setw( 2 ) << minute << ":" + << setw( 2 ) << second; + +} // end function printUniversal + +// print Time in standard format +void Time::printStandard() +{ + cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) + << ":" << setfill( '0' ) << setw( 2 ) << minute + << ":" << setw( 2 ) << second + << ( hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +/************************************************************************** + * (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/Prog1/examples/ch07/Fig07_01_03/Time5.h b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.h new file mode 100644 index 0000000..25b583e --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.h @@ -0,0 +1,49 @@ +// Fig. 7.1: time5.h +// Definition of class Time. +// Member functions defined in time5.cpp. +#ifndef TIME5_H +#define TIME5_H + +class Time { + +public: + Time( int = 0, int = 0, int = 0 ); // default constructor + + // set functions + void setTime( int, int, int ); // set time + void setHour( int ); // set hour + void setMinute( int ); // set minute + void setSecond( int ); // set second + + // get functions (normally declared const) + int getHour() const; // return hour + int getMinute() const; // return minute + int getSecond() const; // return second + + // print functions (normally declared const) + void printUniversal() const; // print universal time + void printStandard(); // print standard time + +private: + int hour; // 0 - 23 (24-hour clock format) + int minute; // 0 - 59 + int second; // 0 - 59 + +}; // end class Time + +#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/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp b/Bachelor/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp new file mode 100644 index 0000000..62b4464 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp @@ -0,0 +1,75 @@ +// Fig. 7.4: fig07_04.cpp +// Using a member initializer to initialize a +// constant of a built-in data type. +#include + +using std::cout; +using std::endl; + +class Increment { + +public: + Increment( int c = 0, int i = 1 ); // default constructor + + void addIncrement() + { + count += increment; + + } // end function addIncrement + + void print() const; // prints count and increment + +private: + int count; + const int increment; // const data member + +}; // end class Increment + +// constructor +Increment::Increment( int c, int i ) + : count( c ), // initializer for non-const member + increment( i ) // required initializer for const member +{ + // empty body + +} // end constructor Increment + +// print count and increment values +void Increment::print() const +{ + cout << "count = " << count + << ", increment = " << increment << endl; + +} // end function print + +int main() +{ + Increment value( 10, 5 ); + + cout << "Before incrementing: "; + value.print(); + + for ( int j = 0; j < 3; j++ ) { + value.addIncrement(); + cout << "After increment " << j + 1 << ": "; + value.print(); + } + + 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/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp b/Bachelor/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp new file mode 100644 index 0000000..f7945b4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp @@ -0,0 +1,74 @@ +// Fig. 7.5: fig07_05.cpp +// Attempting to initialize a constant of +// a built-in data type with an assignment. +#include + +using std::cout; +using std::endl; + +class Increment { + +public: + Increment( int c = 0, int i = 1 ); // default constructor + + void addIncrement() + { + count += increment; + + } // end function addIncrement + + void print() const; // prints count and increment + +private: + int count; + const int increment; // const data member + +}; // end class Increment + +// constructor +Increment::Increment( int c, int i ) +{ // Constant member 'increment' is not initialized + count = c; // allowed because count is not constant + increment = i; // ERROR: Cannot modify a const object + +} // end constructor Increment + +// print count and increment values +void Increment::print() const +{ + cout << "count = " << count + << ", increment = " << increment << endl; + +} // end function print + +int main() +{ + Increment value( 10, 5 ); + + cout << "Before incrementing: "; + value.print(); + + for ( int j = 0; j < 3; j++ ) { + value.addIncrement(); + cout << "After increment " << j + 1 << ": "; + value.print(); + } + + 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/Prog1/examples/ch07/Fig07_06_10/Date1.cpp b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.cpp new file mode 100644 index 0000000..ef3818b --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.cpp @@ -0,0 +1,85 @@ +// Fig. 7.7: date1.cpp +// Member-function definitions for class Date. +#include + +using std::cout; +using std::endl; + +// include Date class definition from date1.h +#include "date1.h" + +// constructor confirms proper value for month; calls +// utility function checkDay to confirm proper value for day +Date::Date( int mn, int dy, int yr ) +{ + if ( mn > 0 && mn <= 12 ) // validate the month + month = mn; + + else { // invalid month set to 1 + month = 1; + cout << "Month " << mn << " invalid. Set to month 1.\n"; + } + + year = yr; // should validate yr + day = checkDay( dy ); // validate the day + + // output Date object to show when its constructor is called + cout << "Date object constructor for date "; + print(); + cout << endl; + +} // end Date constructor + +// print Date object in form month/day/year +void Date::print() const +{ + cout << month << '/' << day << '/' << year; + +} // end function print + +// output Date object to show when its destructor is called +Date::~Date() +{ + cout << "Date object destructor for date "; + print(); + cout << endl; + +} // end ~Date destructor + +// utility function to confirm proper day value based on +// month and year; handles leap years, too +int Date::checkDay( int testDay ) const +{ + static const int daysPerMonth[ 13 ] = + { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + // determine whether testDay is valid for specified month + if ( testDay > 0 && testDay <= daysPerMonth[ month ] ) + return testDay; + + // February 29 check for leap year + if ( month == 2 && testDay == 29 && + ( year % 400 == 0 || + ( year % 4 == 0 && year % 100 != 0 ) ) ) + return testDay; + + cout << "Day " << testDay << " invalid. Set to day 1.\n"; + + return 1; // leave object in consistent state if bad value + +} // end function checkDay + +/************************************************************************** + * (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/Prog1/examples/ch07/Fig07_06_10/Date1.h b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.h new file mode 100644 index 0000000..5829c71 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.h @@ -0,0 +1,39 @@ +// Fig. 7.6: date1.h +// Date class definition. +// Member functions defined in date1.cpp +#ifndef DATE1_H +#define DATE1_H + +class Date { + +public: + Date( int = 1, int = 1, int = 1900 ); // default constructor + void print() const; // print date in month/day/year format + ~Date(); // provided to confirm destruction order + +private: + int month; // 1-12 (January-December) + int day; // 1-31 based on month + int year; // any year + + // utility function to test proper day for month and year + int checkDay( int ) const; + +}; // end class Date + +#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/Prog1/examples/ch07/Fig07_06_10/Employee1.cpp b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.cpp new file mode 100644 index 0000000..6cc742a --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.cpp @@ -0,0 +1,72 @@ +// Fig. 7.9: employee1.cpp +// Member-function definitions for class Employee. +#include + +using std::cout; +using std::endl; + +#include // strcpy and strlen prototypes + +#include "employee1.h" // Employee class definition +#include "date1.h" // Date class definition + +// constructor uses member initializer list to pass initializer +// values to constructors of member objects birthDate and +// hireDate [Note: This invokes the so-called "default copy +// constructor" which the C++ compiler provides implicitly.] +Employee::Employee( const char *first, const char *last, + const Date &dateOfBirth, const Date &dateOfHire ) + : birthDate( dateOfBirth ), // initialize birthDate + hireDate( dateOfHire ) // initialize hireDateba +{ + // copy first into firstName and be sure that it fits + int length = strlen( first ); + length = ( length < 25 ? length : 24 ); + strncpy( firstName, first, length ); + firstName[ length ] = '\0'; + + // copy last into lastName and be sure that it fits + length = strlen( last ); + length = ( length < 25 ? length : 24 ); + strncpy( lastName, last, length ); + lastName[ length ] = '\0'; + + // output Employee object to show when constructor is called + cout << "Employee object constructor: " + << firstName << ' ' << lastName << endl; + +} // end Employee constructor + +// print Employee object +void Employee::print() const +{ + cout << lastName << ", " << firstName << "\nHired: "; + hireDate.print(); + cout << " Birth date: "; + birthDate.print(); + cout << endl; + +} // end function print + +// output Employee object to show when its destructor is called +Employee::~Employee() +{ + cout << "Employee object destructor: " + << lastName << ", " << firstName << endl; + +} // end ~Employee destructor + +/************************************************************************** + * (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/Prog1/examples/ch07/Fig07_06_10/Employee1.h b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.h new file mode 100644 index 0000000..cfc294a --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.h @@ -0,0 +1,42 @@ +// Fig. 7.8: employee1.h +// Employee class definition. +// Member functions defined in employee1.cpp. +#ifndef EMPLY1_H +#define EMPLY1_H + +// include Date class definition from date1.h +#include "date1.h" + +class Employee { + +public: + Employee( + const char *, const char *, const Date &, const Date & ); + + void print() const; + ~Employee(); // provided to confirm destruction order + +private: + char firstName[ 25 ]; + char lastName[ 25 ]; + const Date birthDate; // composition: member object + const Date hireDate; // composition: member object + +}; // end class Employee + +#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/Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp new file mode 100644 index 0000000..90dfc9b --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp @@ -0,0 +1,40 @@ +// Fig. 7.10: fig07_10.cpp +// Demonstrating composition--an object with member objects. +#include + +using std::cout; +using std::endl; + +#include "employee1.h" // Employee class definition + +int main() +{ + Date birth( 7, 24, 1949 ); + Date hire( 3, 12, 1988 ); + Employee manager( "Bob", "Jones", birth, hire ); + + cout << '\n'; + manager.print(); + + cout << "\nTest Date constructor with invalid values:\n"; + Date lastDayOff( 14, 35, 1994 ); // invalid month and day + 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/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp b/Bachelor/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp new file mode 100644 index 0000000..995bc86 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp @@ -0,0 +1,72 @@ +// Fig. 7.11: fig07_11.cpp +// Friends can access private members of a class. +#include + +using std::cout; +using std::endl; + +// Count class definition +// (note that there is no friendship declaration) +class Count { + friend void setX( Count &, int ); // friend declaration + +public: + + // constructor + Count() + : x( 0 ) // initialize x to 0 + { + // empty body + + } // end constructor Count + + // output x + void print() const + { + cout << x << endl; + + } // end function print + +private: + int x; // data member + +}; // end class Count + +// function setX can modify private data of Count +// because setX is declared as a friend of Count +void setX( Count &c, int val ) +{ + c.x = val; // legal: setX is a friend of Count + +} // end function setX + +int main() +{ + Count counter; // create Count object + + cout << "counter.x after instantiation: "; + counter.print(); + + setX( counter, 8 ); // set x with a friend + + cout << "counter.x after call to setX friend function: "; + counter.print(); + + 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/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp b/Bachelor/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp new file mode 100644 index 0000000..dbab9fc --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp @@ -0,0 +1,65 @@ +// Fig. 7.12: fig07_12.cpp +// Non-friend/non-member functions cannot access +// private data of a class. +#include + +using std::cout; +using std::endl; + +// Count class definition +class Count { + +public: + + // constructor + Count() + : x( 0 ) // initialize x to 0 + { + // empty body + + } // end constructor Count + + // output x + void print() const + { + cout << x << endl; + + } // end function print + +private: + int x; // data member + +}; // end class Count + +// function tries to modify private data of Count, +// but cannot because function is not a friend of Count +void cannotSetX( Count &c, int val ) +{ + c.x = val; // ERROR: cannot access private member in Count + +} // end function cannotSetX + +int main() +{ + Count counter; // create Count object + + cannotSetX( counter, 3 ); // cannotSetX is not a friend + + 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/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp b/Bachelor/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp new file mode 100644 index 0000000..2e385a4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp @@ -0,0 +1,66 @@ +// Fig. 7.13: fig07_13.cpp +// Using the this pointer to refer to object members. +#include + +using std::cout; +using std::endl; + +class Test { + +public: + Test( int = 0 ); // default constructor + void print() const; + +private: + int x; + +}; // end class Test + +// constructor +Test::Test( int value ) + : x( value ) // initialize x to value +{ + // empty body + +} // end constructor Test + +// print x using implicit and explicit this pointers; +// parentheses around *this required +void Test::print() const +{ + // implicitly use this pointer to access member x + cout << " x = " << x; + + // explicitly use this pointer to access member x + cout << "\n this->x = " << this->x; + + // explicitly use dereferenced this pointer and + // the dot operator to access member x + cout << "\n(*this).x = " << ( *this ).x << endl; + +} // end function print + +int main() +{ + Test testObject( 12 ); + + testObject.print(); + + 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/Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp new file mode 100644 index 0000000..70e7a64 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp @@ -0,0 +1,48 @@ +// Fig. 7.16: fig07_16.cpp +// Cascading member function calls with the this pointer. +#include + +using std::cout; +using std::endl; + +#include "time6.h" // Time class definition + +int main() +{ + Time t; + + // cascaded function calls + t.setHour( 18 ).setMinute( 30 ).setSecond( 22 ); + + // output time in universal and standard formats + cout << "Universal time: "; + t.printUniversal(); + + cout << "\nStandard time: "; + t.printStandard(); + + cout << "\n\nNew standard time: "; + + // cascaded function calls + t.setTime( 20, 20, 20 ).printStandard(); + + 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/Prog1/examples/ch07/Fig07_14_16/Time6.cpp b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.cpp new file mode 100644 index 0000000..97205c0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.cpp @@ -0,0 +1,114 @@ +// Fig. 7.15: time6.cpp +// Member-function definitions for Time class. +#include + +using std::cout; + +#include + +using std::setfill; +using std::setw; + +#include "time6.h" // Time class definition + +// constructor function to initialize private data; +// calls member function setTime to set variables; +// default values are 0 (see class definition) +Time::Time( int hr, int min, int sec ) +{ + setTime( hr, min, sec ); + +} // end Time constructor + +// set values of hour, minute, and second +Time &Time::setTime( int h, int m, int s ) +{ + setHour( h ); + setMinute( m ); + setSecond( s ); + + return *this; // enables cascading + +} // end function setTime + +// set hour value +Time &Time::setHour( int h ) +{ + hour = ( h >= 0 && h < 24 ) ? h : 0; + + return *this; // enables cascading + +} // end function setHour + +// set minute value +Time &Time::setMinute( int m ) +{ + minute = ( m >= 0 && m < 60 ) ? m : 0; + + return *this; // enables cascading + +} // end function setMinute + +// set second value +Time &Time::setSecond( int s ) +{ + second = ( s >= 0 && s < 60 ) ? s : 0; + + return *this; // enables cascading + +} // end function setSecond + +// get hour value +int Time::getHour() const +{ + return hour; + +} // end function getHour + +// get minute value +int Time::getMinute() const +{ + return minute; + +} // end function getMinute + +// get second value +int Time::getSecond() const +{ + return second; + +} // end function getSecond + +// print Time in universal format +void Time::printUniversal() const +{ + cout << setfill( '0' ) << setw( 2 ) << hour << ":" + << setw( 2 ) << minute << ":" + << setw( 2 ) << second; + +} // end function printUniversal + +// print Time in standard format +void Time::printStandard() const +{ + cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) + << ":" << setfill( '0' ) << setw( 2 ) << minute + << ":" << setw( 2 ) << second + << ( hour < 12 ? " AM" : " PM" ); + +} // end function printStandard + +/************************************************************************** + * (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/Prog1/examples/ch07/Fig07_14_16/Time6.h b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.h new file mode 100644 index 0000000..d9413ca --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.h @@ -0,0 +1,51 @@ +// Fig. 7.14: time6.h +// Cascading member function calls. + +// Time class definition. +// Member functions defined in time6.cpp. +#ifndef TIME6_H +#define TIME6_H + +class Time { + +public: + Time( int = 0, int = 0, int = 0 ); // default constructor + + // set functions + Time &setTime( int, int, int ); // set hour, minute, second + Time &setHour( int ); // set hour + Time &setMinute( int ); // set minute + Time &setSecond( int ); // set second + + // get functions (normally declared const) + int getHour() const; // return hour + int getMinute() const; // return minute + int getSecond() const; // return second + + // print functions (normally declared const) + void printUniversal() const; // print universal time + void printStandard() const; // print standard time + +private: + int hour; // 0 - 23 (24-hour clock format) + int minute; // 0 - 59 + int second; // 0 - 59 + +}; // end class Time + +#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/Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp b/Bachelor/Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp new file mode 100644 index 0000000..27ba9f7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp @@ -0,0 +1,55 @@ +// Fig. 7.19: fig07_19.cpp +// Driver to test class Employee. +#include + +using std::cout; +using std::endl; + +#include // C++ standard new operator + +#include "employee2.h" // Employee class definition + +int main() +{ + cout << "Number of employees before instantiation is " + << Employee::getCount() << endl; // use class name + + Employee *e1Ptr = new Employee( "Susan", "Baker" ); + Employee *e2Ptr = new Employee( "Robert", "Jones" ); + + cout << "Number of employees after instantiation is " + << e1Ptr->getCount(); + + cout << "\n\nEmployee 1: " + << e1Ptr->getFirstName() + << " " << e1Ptr->getLastName() + << "\nEmployee 2: " + << e2Ptr->getFirstName() + << " " << e2Ptr->getLastName() << "\n\n"; + + delete e1Ptr; // recapture memory + e1Ptr = 0; // disconnect pointer from free-store space + delete e2Ptr; // recapture memory + e2Ptr = 0; // disconnect pointer from free-store space + + cout << "Number of employees after deletion is " + << Employee::getCount() << 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/Prog1/examples/ch07/Fig07_17_19/employee2.cpp b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.cpp new file mode 100644 index 0000000..540f367 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.cpp @@ -0,0 +1,88 @@ +// Fig. 7.18: employee2.cpp +// Member-function definitions for class Employee. +#include + +using std::cout; +using std::endl; + +#include // C++ standard new operator +#include // strcpy and strlen prototypes + +#include "employee2.h" // Employee class definition + +// define and initialize static data member +int Employee::count = 0; + +// define static member function that returns number of +// Employee objects instantiated +int Employee::getCount() +{ + return count; + +} // end static function getCount + +// constructor dynamically allocates space for +// first and last name and uses strcpy to copy +// first and last names into the object +Employee::Employee( const char *first, const char *last ) +{ + firstName = new char[ strlen( first ) + 1 ]; + strcpy( firstName, first ); + + lastName = new char[ strlen( last ) + 1 ]; + strcpy( lastName, last ); + + ++count; // increment static count of employees + + cout << "Employee constructor for " << firstName + << ' ' << lastName << " called." << endl; + +} // end Employee constructor + +// destructor deallocates dynamically allocated memory +Employee::~Employee() +{ + cout << "~Employee() called for " << firstName + << ' ' << lastName << endl; + + delete [] firstName; // recapture memory + delete [] lastName; // recapture memory + + --count; // decrement static count of employees + +} // end ~Employee destructor + +// return first name of employee +const char *Employee::getFirstName() const +{ + // const before return type prevents client from modifying + // private data; client should copy returned string before + // destructor deletes storage to prevent undefined pointer + return firstName; + +} // end function getFirstName + +// return last name of employee +const char *Employee::getLastName() const +{ + // const before return type prevents client from modifying + // private data; client should copy returned string before + // destructor deletes storage to prevent undefined pointer + return lastName; + +} // end function getLastName + +/************************************************************************** + * (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/Prog1/examples/ch07/Fig07_17_19/employee2.h b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.h new file mode 100644 index 0000000..3010210 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.h @@ -0,0 +1,41 @@ +// Fig. 7.17: employee2.h +// Employee class definition. +#ifndef EMPLOYEE2_H +#define EMPLOYEE2_H + +class Employee { + +public: + Employee( const char *, const char * ); // constructor + ~Employee(); // destructor + const char *getFirstName() const; // return first name + const char *getLastName() const; // return last name + + // static member function + static int getCount(); // return # objects instantiated + +private: + char *firstName; + char *lastName; + + // static data member + static int count; // number of objects instantiated + +}; // end class Employee + +#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/Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp b/Bachelor/Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp new file mode 100644 index 0000000..a11a543 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp @@ -0,0 +1,39 @@ +// Fig. 7.23: fig07_23.cpp +// Hiding a class’s private data with a proxy class. +#include + +using std::cout; +using std::endl; + +#include "interface.h" // Interface class definition + +int main() +{ + Interface i( 5 ); + + cout << "Interface contains: " << i.getValue() + << " before setValue" << endl; + + i.setValue( 10 ); + + cout << "Interface contains: " << i.getValue() + << " after setValue" << 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/Prog1/examples/ch07/Fig07_20_23/implementation.h b/Bachelor/Prog1/examples/ch07/Fig07_20_23/implementation.h new file mode 100644 index 0000000..1630a50 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/implementation.h @@ -0,0 +1,48 @@ +// Fig. 7.20: implementation.h +// Header file for class Implementation + +class Implementation { + +public: + + // constructor + Implementation( int v ) + : value( v ) // initialize value with v + { + // empty body + + } // end constructor Implementation + + // set value to v + void setValue( int v ) + { + value = v; // should validate v + + } // end function setValue + + // return value + int getValue() const + { + return value; + + } // end function getValue + +private: + int value; + +}; // end class Implementation + +/************************************************************************** + * (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/Prog1/examples/ch07/Fig07_20_23/interface.cpp b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.cpp new file mode 100644 index 0000000..0f895fd --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.cpp @@ -0,0 +1,48 @@ +// Fig. 7.22: interface.cpp +// Definition of class Interface +#include "interface.h" // Interface class definition +#include "implementation.h" // Implementation class definition + +// constructor +Interface::Interface( int v ) + : ptr ( new Implementation( v ) ) // initialize ptr +{ + // empty body + +} // end Interface constructor + +// call Implementation's setValue function +void Interface::setValue( int v ) +{ + ptr->setValue( v ); + +} // end function setValue + +// call Implementation's getValue function +int Interface::getValue() const +{ + return ptr->getValue(); + +} // end function getValue + +// destructor +Interface::~Interface() +{ + delete ptr; + +} // end ~Interface destructor + +/************************************************************************** + * (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/Prog1/examples/ch07/Fig07_20_23/interface.h b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.h new file mode 100644 index 0000000..5d229e1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.h @@ -0,0 +1,34 @@ +// Fig. 7.21: interface.h +// Header file for interface.cpp + +class Implementation; // forward class declaration + +class Interface { + +public: + Interface( int ); + void setValue( int ); // same public interface as + int getValue() const; // class Implementation + ~Interface(); + +private: + + // requires previous forward declaration (line 4) + Implementation *ptr; + +}; // end class Interface + +/************************************************************************** + * (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/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp b/Bachelor/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp new file mode 100644 index 0000000..ac5e434 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp @@ -0,0 +1,89 @@ +// Fig. 8.3: fig08_03.cpp +// Overloading the stream-insertion and +// stream-extraction operators. +#include + +using std::cout; +using std::cin; +using std::endl; +using std::ostream; +using std::istream; + +#include + +using std::setw; + +// PhoneNumber class definition +class PhoneNumber { + friend ostream &operator<<( ostream&, const PhoneNumber & ); + friend istream &operator>>( istream&, PhoneNumber & ); + +private: + char areaCode[ 4 ]; // 3-digit area code and null + char exchange[ 4 ]; // 3-digit exchange and null + char line[ 5 ]; // 4-digit line and null + +}; // end class PhoneNumber + +// overloaded stream-insertion operator; cannot be +// a member function if we would like to invoke it with +// cout << somePhoneNumber; +ostream &operator<<( ostream &output, const PhoneNumber &num ) +{ + output << "(" << num.areaCode << ") " + << num.exchange << "-" << num.line; + + return output; // enables cout << a << b << c; + +} // end function operator<< + +// overloaded stream-extraction operator; cannot be +// a member function if we would like to invoke it with +// cin >> somePhoneNumber; +istream &operator>>( istream &input, PhoneNumber &num ) +{ + input.ignore(); // skip ( + input >> setw( 4 ) >> num.areaCode; // input area code + input.ignore( 2 ); // skip ) and space + input >> setw( 4 ) >> num.exchange; // input exchange + input.ignore(); // skip dash (-) + input >> setw( 5 ) >> num.line; // input line + + return input; // enables cin >> a >> b >> c; + +} // end function operator>> + +int main() +{ + PhoneNumber phone; // create object phone + + cout << "Enter phone number in the form (123) 456-7890:\n"; + + // cin >> phone invokes operator>> by implicitly issuing + // the non-member function call operator>>( cin, phone ) + cin >> phone; + + cout << "The phone number entered was: "; + + // cout << phone invokes operator<< by implicitly issuing + // the non-member function call operator<<( cout, phone ) + cout << phone << 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/Prog1/examples/ch08/Fig08_04_06/Array1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.cpp new file mode 100644 index 0000000..817f7ec --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.cpp @@ -0,0 +1,177 @@ +// Fig 8.5: array1.cpp +// Member function definitions for class Array +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::setw; + +#include // C++ standard "new" operator + +#include // exit function prototype + +#include "array1.h" // Array class definition + +// default constructor for class Array (default size 10) +Array::Array( int arraySize ) +{ + // validate arraySize + size = ( arraySize > 0 ? arraySize : 10 ); + + ptr = new int[ size ]; // create space for array + + for ( int i = 0; i < size; i++ ) + ptr[ i ] = 0; // initialize array + +} // end Array default constructor + +// copy constructor for class Array; +// must receive a reference to prevent infinite recursion +Array::Array( const Array &arrayToCopy ) + : size( arrayToCopy.size ) +{ + ptr = new int[ size ]; // create space for array + + for ( int i = 0; i < size; i++ ) + ptr[ i ] = arrayToCopy.ptr[ i ]; // copy into object + +} // end Array copy constructor + +// destructor for class Array +Array::~Array() +{ + delete [] ptr; // reclaim array space + +} // end destructor + +// return size of array +int Array::getSize() const +{ + return size; + +} // end function getSize + +// overloaded assignment operator; +// const return avoids: ( a1 = a2 ) = a3 +const Array &Array::operator=( const Array &right ) +{ + if ( &right != this ) { // check for self-assignment + + // for arrays of different sizes, deallocate original + // left-side array, then allocate new left-side array + if ( size != right.size ) { + delete [] ptr; // reclaim space + size = right.size; // resize this object + ptr = new int[ size ]; // create space for array copy + + } // end inner if + + for ( int i = 0; i < size; i++ ) + ptr[ i ] = right.ptr[ i ]; // copy array into object + + } // end outer if + + return *this; // enables x = y = z, for example + +} // end function operator= + +// determine if two arrays are equal and +// return true, otherwise return false +bool Array::operator==( const Array &right ) const +{ + if ( size != right.size ) + return false; // arrays of different sizes + + for ( int i = 0; i < size; i++ ) + + if ( ptr[ i ] != right.ptr[ i ] ) + return false; // arrays are not equal + + return true; // arrays are equal + +} // end function operator== + +// overloaded subscript operator for non-const Arrays +// reference return creates an lvalue +int &Array::operator[]( int subscript ) +{ + // check for subscript out of range error + if ( subscript < 0 || subscript >= size ) { + cout << "\nError: Subscript " << subscript + << " out of range" << endl; + + exit( 1 ); // terminate program; subscript out of range + + } // end if + + return ptr[ subscript ]; // reference return + +} // end function operator[] + +// overloaded subscript operator for const Arrays +// const reference return creates an rvalue +const int &Array::operator[]( int subscript ) const +{ + // check for subscript out of range error + if ( subscript < 0 || subscript >= size ) { + cout << "\nError: Subscript " << subscript + << " out of range" << endl; + + exit( 1 ); // terminate program; subscript out of range + + } // end if + + return ptr[ subscript ]; // const reference return + +} // end function operator[] + +// overloaded input operator for class Array; +// inputs values for entire array +istream &operator>>( istream &input, Array &a ) +{ + for ( int i = 0; i < a.size; i++ ) + input >> a.ptr[ i ]; + + return input; // enables cin >> x >> y; + +} // end function + +// overloaded output operator for class Array +ostream &operator<<( ostream &output, const Array &a ) +{ + int i; + + // output private ptr-based array + for ( i = 0; i < a.size; i++ ) { + output << setw( 12 ) << a.ptr[ i ]; + + if ( ( i + 1 ) % 4 == 0 ) // 4 numbers per row of output + output << endl; + + } // end for + + if ( i % 4 != 0 ) // end last line of output + output << endl; + + return output; // enables cout << x << y; + +} // end function operator<< + +/************************************************************************** + * (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/Prog1/examples/ch08/Fig08_04_06/Array1.h b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.h new file mode 100644 index 0000000..d84bc81 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.h @@ -0,0 +1,61 @@ +// Fig. 8.4: array1.h +// Array class for storing arrays of integers. +#ifndef ARRAY1_H +#define ARRAY1_H + +#include + +using std::ostream; +using std::istream; + +class Array { + friend ostream &operator<<( ostream &, const Array & ); + friend istream &operator>>( istream &, Array & ); + +public: + Array( int = 10 ); // default constructor + Array( const Array & ); // copy constructor + ~Array(); // destructor + int getSize() const; // return size + + // assignment operator + const Array &operator=( const Array & ); + + // equality operator + bool operator==( const Array & ) const; + + // inequality operator; returns opposite of == operator + bool operator!=( const Array &right ) const + { + return ! ( *this == right ); // invokes Array::operator== + + } // end function operator!= + + // subscript operator for non-const objects returns lvalue + int &operator[]( int ); + + // subscript operator for const objects returns rvalue + const int &operator[]( int ) const; + +private: + int size; // array size + int *ptr; // pointer to first element of array + +}; // end class Array + +#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/Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp new file mode 100644 index 0000000..29178eb --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp @@ -0,0 +1,90 @@ +// Fig. 8.6: fig08_06.cpp +// Array class test program. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include "array1.h" + +int main() +{ + Array integers1( 7 ); // seven-element Array + Array integers2; // 10-element Array by default + + // print integers1 size and contents + cout << "Size of array integers1 is " + << integers1.getSize() + << "\nArray after initialization:\n" << integers1; + + // print integers2 size and contents + cout << "\nSize of array integers2 is " + << integers2.getSize() + << "\nArray after initialization:\n" << integers2; + + // input and print integers1 and integers2 + cout << "\nInput 17 integers:\n"; + cin >> integers1 >> integers2; + + cout << "\nAfter input, the arrays contain:\n" + << "integers1:\n" << integers1 + << "integers2:\n" << integers2; + + // use overloaded inequality (!=) operator + cout << "\nEvaluating: integers1 != integers2\n"; + + if ( integers1 != integers2 ) + cout << "integers1 and integers2 are not equal\n"; + + // create array integers3 using integers1 as an + // initializer; print size and contents + Array integers3( integers1 ); // calls copy constructor + + cout << "\nSize of array integers3 is " + << integers3.getSize() + << "\nArray after initialization:\n" << integers3; + + // use overloaded assignment (=) operator + cout << "\nAssigning integers2 to integers1:\n"; + integers1 = integers2; // note target is smaller + + cout << "integers1:\n" << integers1 + << "integers2:\n" << integers2; + + // use overloaded equality (==) operator + cout << "\nEvaluating: integers1 == integers2\n"; + + if ( integers1 == integers2 ) + cout << "integers1 and integers2 are equal\n"; + + // use overloaded subscript operator to create rvalue + cout << "\nintegers1[5] is " << integers1[ 5 ]; + + // use overloaded subscript operator to create lvalue + cout << "\n\nAssigning 1000 to integers1[5]\n"; + integers1[ 5 ] = 1000; + cout << "integers1:\n" << integers1; + + // attempt to use out-of-range subscript + cout << "\nAttempt to assign 1000 to integers1[15]" << endl; + integers1[ 15 ] = 1000; // ERROR: out of range + + 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/Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp b/Bachelor/Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp new file mode 100644 index 0000000..9a9d516 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp @@ -0,0 +1,101 @@ +// Fig. 8.9: fig08_09.cpp +// String class test program. +#include + +using std::cout; +using std::endl; + +#include "string1.h" + +int main() +{ + String s1( "happy" ); + String s2( " birthday" ); + String s3; + + // test overloaded equality and relational operators + cout << "s1 is \"" << s1 << "\"; s2 is \"" << s2 + << "\"; s3 is \"" << s3 << '\"' + << "\n\nThe results of comparing s2 and s1:" + << "\ns2 == s1 yields " + << ( s2 == s1 ? "true" : "false" ) + << "\ns2 != s1 yields " + << ( s2 != s1 ? "true" : "false" ) + << "\ns2 > s1 yields " + << ( s2 > s1 ? "true" : "false" ) + << "\ns2 < s1 yields " + << ( s2 < s1 ? "true" : "false" ) + << "\ns2 >= s1 yields " + << ( s2 >= s1 ? "true" : "false" ) + << "\ns2 <= s1 yields " + << ( s2 <= s1 ? "true" : "false" ); + + // test overloaded String empty (!) operator + cout << "\n\nTesting !s3:\n"; + + if ( !s3 ) { + cout << "s3 is empty; assigning s1 to s3;\n"; + s3 = s1; // test overloaded assignment + cout << "s3 is \"" << s3 << "\""; + } + + // test overloaded String concatenation operator + cout << "\n\ns1 += s2 yields s1 = "; + s1 += s2; // test overloaded concatenation + cout << s1; + + // test conversion constructor + cout << "\n\ns1 += \" to you\" yields\n"; + s1 += " to you"; // test conversion constructor + cout << "s1 = " << s1 << "\n\n"; + + // test overloaded function call operator () for substring + cout << "The substring of s1 starting at\n" + << "location 0 for 14 characters, s1(0, 14), is:\n" + << s1( 0, 14 ) << "\n\n"; + + // test substring "to-end-of-String" option + cout << "The substring of s1 starting at\n" + << "location 15, s1(15, 0), is: " + << s1( 15, 0 ) << "\n\n"; // 0 is "to end of string" + + // test copy constructor + String *s4Ptr = new String( s1 ); + cout << "\n*s4Ptr = " << *s4Ptr << "\n\n"; + + // test assignment (=) operator with self-assignment + cout << "assigning *s4Ptr to *s4Ptr\n"; + *s4Ptr = *s4Ptr; // test overloaded assignment + cout << "*s4Ptr = " << *s4Ptr << '\n'; + + // test destructor + delete s4Ptr; + + // test using subscript operator to create lvalue + s1[ 0 ] = 'H'; + s1[ 6 ] = 'B'; + cout << "\ns1 after s1[0] = 'H' and s1[6] = 'B' is: " + << s1 << "\n\n"; + + // test subscript out of range + cout << "Attempt to assign 'd' to s1[30] yields:" << endl; + s1[ 30 ] = 'd'; // ERROR: subscript out of range + + 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/Prog1/examples/ch08/Fig08_07_09/String1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.cpp new file mode 100644 index 0000000..7cca6d7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.cpp @@ -0,0 +1,221 @@ +// Fig. 8.8: string1.cpp +// Member function definitions for class String. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include // C++ standard "new" operator + +#include // strcpy and strcat prototypes +#include // exit prototype + +#include "string1.h" // String class definition + +// conversion constructor converts char * to String +String::String( const char *s ) + : length( ( s != 0 ) ? strlen( s ) : 0 ) +{ + cout << "Conversion constructor: " << s << '\n'; + setString( s ); // call utility function + +} // end String conversion constructor + +// copy constructor +String::String( const String © ) + : length( copy.length ) +{ + cout << "Copy constructor: " << copy.sPtr << '\n'; + setString( copy.sPtr ); // call utility function + +} // end String copy constructor + +// Destructor +String::~String() +{ + cout << "Destructor: " << sPtr << '\n'; + delete [] sPtr; // reclaim string + +} // end ~String destructor + +// overloaded = operator; avoids self assignment +const String &String::operator=( const String &right ) +{ + cout << "operator= called\n"; + + if ( &right != this ) { // avoid self assignment + delete [] sPtr; // prevents memory leak + length = right.length; // new String length + setString( right.sPtr ); // call utility function + } + + else + cout << "Attempted assignment of a String to itself\n"; + + return *this; // enables cascaded assignments + +} // end function operator= + +// concatenate right operand to this object and +// store in this object. +const String &String::operator+=( const String &right ) +{ + size_t newLength = length + right.length; // new length + char *tempPtr = new char[ newLength + 1 ]; // create memory + + strcpy( tempPtr, sPtr ); // copy sPtr + strcpy( tempPtr + length, right.sPtr ); // copy right.sPtr + + delete [] sPtr; // reclaim old space + sPtr = tempPtr; // assign new array to sPtr + length = newLength; // assign new length to length + + return *this; // enables cascaded calls + +} // end function operator+= + +// is this String empty? +bool String::operator!() const +{ + return length == 0; + +} // end function operator! + +// Is this String equal to right String? +bool String::operator==( const String &right ) const +{ + return strcmp( sPtr, right.sPtr ) == 0; + +} // end function operator== + +// Is this String less than right String? +bool String::operator<( const String &right ) const +{ + return strcmp( sPtr, right.sPtr ) < 0; + +} // end function operator< + +// return reference to character in String as lvalue +char &String::operator[]( int subscript ) +{ + // test for subscript out of range + if( subscript < 0 || subscript >= length ) { + cout << "Error: Subscript " << subscript + << " out of range" << endl; + + exit( 1 ); // terminate program + } + + return sPtr[ subscript ]; // creates lvalue + +} // end function operator[] + +// return reference to character in String as rvalue +const char &String::operator[]( int subscript ) const +{ + // test for subscript out of range + if( subscript < 0 || subscript >= length ) { + cout << "Error: Subscript " << subscript + << " out of range" << endl; + + exit( 1 ); // terminate program + } + + return sPtr[ subscript ]; // creates rvalue + +} // end function operator[] + +// return a substring beginning at index and +// of length subLength +String String::operator()( int index, int subLength ) +{ + // if index is out of range or substring length < 0, + // return an empty String object + if ( index < 0 || index >= length || subLength < 0 ) + return ""; // converted to a String object automatically + + // determine length of substring + int len; + + if ( ( subLength == 0 ) || ( index + subLength > length ) ) + len = length - index; + else + len = subLength; + + // allocate temporary array for substring and + // terminating null character + char *tempPtr = new char[ len + 1 ]; + + // copy substring into char array and terminate string + strncpy( tempPtr, &sPtr[ index ], len ); + tempPtr[ len ] = '\0'; + + // create temporary String object containing the substring + String tempString( tempPtr ); + delete [] tempPtr; // delete temporary array + + return tempString; // return copy of the temporary String + +} // end function operator() + +// return string length +int String::getLength() const +{ + return length; + +} // end function getLenth + +// utility function called by constructors and operator= +void String::setString( const char *string2 ) +{ + sPtr = new char[ length + 1 ]; // allocate memory + + // if string2 is not a null pointer, copy contents + if ( string2 != 0 ) + strcpy( sPtr, string2 ); // copy literal to object + + // if string2 is a null pointer, make this an empty string + else + sPtr[ 0 ] = '\0'; // empty string + +} // end function setString + +// overloaded output operator +ostream &operator<<( ostream &output, const String &s ) +{ + output << s.sPtr; + + return output; // enables cascading + +} // end function operator<< + +// overloaded input operator +istream &operator>>( istream &input, String &s ) +{ + char temp[ 100 ]; // buffer to store input + + input >> setw( 100 ) >> temp; + s = temp; // use String class assignment operator + + return input; // enables cascading + +} // end function operator>> + +/************************************************************************** + * (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/Prog1/examples/ch08/Fig08_07_09/String1.h b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.h new file mode 100644 index 0000000..81012aa --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.h @@ -0,0 +1,85 @@ +// Fig. 8.7: string1.h +// String class definition. +#ifndef STRING1_H +#define STRING1_H + +#include + +using std::ostream; +using std::istream; + +class String { + friend ostream &operator<<( ostream &, const String & ); + friend istream &operator>>( istream &, String & ); + +public: + String( const char * = "" ); // conversion/default ctor + String( const String & ); // copy constructor + ~String(); // destructor + + const String &operator=( const String & ); // assignment + const String &operator+=( const String & ); // concatenation + + bool operator!() const; // is String empty? + bool operator==( const String & ) const; // test s1 == s2 + bool operator<( const String & ) const; // test s1 < s2 + + // test s1 != s2 + bool operator!=( const String & right ) const + { + return !( *this == right ); + + } // end function operator!= + + // test s1 > s2 + bool operator>( const String &right ) const + { + return right < *this; + + } // end function operator> + + // test s1 <= s2 + bool operator<=( const String &right ) const + { + return !( right < *this ); + + } // end function operator <= + + // test s1 >= s2 + bool operator>=( const String &right ) const + { + return !( *this < right ); + + } // end function operator>= + + char &operator[]( int ); // subscript operator + const char &operator[]( int ) const; // subscript operator + + String operator()( int, int ); // return a substring + + int getLength() const; // return string length + +private: + int length; // string length + char *sPtr; // pointer to start of string + + void setString( const char * ); // utility function + +}; // end class String + +#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/Prog1/examples/ch08/Fig08_10_12/Date1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.cpp new file mode 100644 index 0000000..0c96a95 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.cpp @@ -0,0 +1,137 @@ +// Fig. 8.11: date1.cpp +// Date class member function definitions. +#include +#include "date1.h" + +// initialize static member at file scope; +// one class-wide copy +const int Date::days[] = + { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + +// Date constructor +Date::Date( int m, int d, int y ) +{ + setDate( m, d, y ); + +} // end Date constructor + +// set month, day and year +void Date::setDate( int mm, int dd, int yy ) +{ + month = ( mm >= 1 && mm <= 12 ) ? mm : 1; + year = ( yy >= 1900 && yy <= 2100 ) ? yy : 1900; + + // test for a leap year + if ( month == 2 && leapYear( year ) ) + day = ( dd >= 1 && dd <= 29 ) ? dd : 1; + else + day = ( dd >= 1 && dd <= days[ month ] ) ? dd : 1; + +} // end function setDate + +// overloaded preincrement operator +Date &Date::operator++() +{ + helpIncrement(); + + return *this; // reference return to create an lvalue + +} // end function operator++ + +// overloaded postincrement operator; note that the dummy +// integer parameter does not have a parameter name +Date Date::operator++( int ) +{ + Date temp = *this; + helpIncrement(); // hold current state of object + + // return unincremented, saved, temporary object + return temp; // value return; not a reference return + +} // end function operator++ + +// add specified number of days to date +const Date &Date::operator+=( int additionalDays ) +{ + for ( int i = 0; i < additionalDays; i++ ) + helpIncrement(); + + return *this; // enables cascading + +} // end function operator+= + +// if the year is a leap year, return true; +// otherwise, return false +bool Date::leapYear( int testYear ) const +{ + if ( testYear % 400 == 0 || + ( testYear % 100 != 0 && testYear % 4 == 0 ) ) + return true; // a leap year + else + return false; // not a leap year + +} // end function leapYear + +// determine whether the day is the last day of the month +bool Date::endOfMonth( int testDay ) const +{ + if ( month == 2 && leapYear( year ) ) + return testDay == 29; // last day of Feb. in leap year + else + return testDay == days[ month ]; + +} // end function endOfMonth + +// function to help increment the date +void Date::helpIncrement() +{ + // day is not end of month + if ( !endOfMonth( day ) ) + ++day; + + else + + // day is end of month and month < 12 + if ( month < 12 ) { + ++month; + day = 1; + } + + // last day of year + else { + ++year; + month = 1; + day = 1; + } + +} // end function helpIncrement + +// overloaded output operator +ostream &operator<<( ostream &output, const Date &d ) +{ + static char *monthName[ 13 ] = { "", "January", + "February", "March", "April", "May", "June", + "July", "August", "September", "October", + "November", "December" }; + + output << monthName[ d.month ] << ' ' + << d.day << ", " << d.year; + + return output; // enables cascading + +} // end function operator<< + +/************************************************************************** + * (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/Prog1/examples/ch08/Fig08_10_12/Date1.h b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.h new file mode 100644 index 0000000..d1d6148 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.h @@ -0,0 +1,49 @@ +// Fig. 8.10: date1.h +// Date class definition. +#ifndef DATE1_H +#define DATE1_H +#include + +using std::ostream; + +class Date { + friend ostream &operator<<( ostream &, const Date & ); + +public: + Date( int m = 1, int d = 1, int y = 1900 ); // constructor + void setDate( int, int, int ); // set the date + + Date &operator++(); // preincrement operator + Date operator++( int ); // postincrement operator + + const Date &operator+=( int ); // add days, modify object + + bool leapYear( int ) const; // is this a leap year? + bool endOfMonth( int ) const; // is this end of month? + +private: + int month; + int day; + int year; + + static const int days[]; // array of days per month + void helpIncrement(); // utility function + +}; // end class Date + +#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/Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp new file mode 100644 index 0000000..0d4c996 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp @@ -0,0 +1,54 @@ +// Fig. 8.12: fig08_12.cpp +// Date class test program. +#include + +using std::cout; +using std::endl; + +#include "date1.h" // Date class definition + +int main() +{ + Date d1; // defaults to January 1, 1900 + Date d2( 12, 27, 1992 ); + Date d3( 0, 99, 8045 ); // invalid date + + cout << "d1 is " << d1 << "\nd2 is " << d2 + << "\nd3 is " << d3; + + cout << "\n\nd2 += 7 is " << ( d2 += 7 ); + + d3.setDate( 2, 28, 1992 ); + cout << "\n\n d3 is " << d3; + cout << "\n++d3 is " << ++d3; + + Date d4( 7, 13, 2002 ); + + cout << "\n\nTesting the preincrement operator:\n" + << " d4 is " << d4 << '\n'; + cout << "++d4 is " << ++d4 << '\n'; + cout << " d4 is " << d4; + + cout << "\n\nTesting the postincrement operator:\n" + << " d4 is " << d4 << '\n'; + cout << "d4++ is " << d4++ << '\n'; + cout << " d4 is " << d4 << 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/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp b/Bachelor/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp new file mode 100644 index 0000000..cd74972 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp @@ -0,0 +1,104 @@ +// Fig. 8.13: fig08_13.cpp +// Standard library string class test program. +#include + +using std::cout; +using std::endl; + +#include + +using std::string; + +int main() +{ + string s1( "happy" ); + string s2( " birthday" ); + string s3; + + // test overloaded equality and relational operators + cout << "s1 is \"" << s1 << "\"; s2 is \"" << s2 + << "\"; s3 is \"" << s3 << '\"' + << "\n\nThe results of comparing s2 and s1:" + << "\ns2 == s1 yields " + << ( s2 == s1 ? "true" : "false" ) + << "\ns2 != s1 yields " + << ( s2 != s1 ? "true" : "false" ) + << "\ns2 > s1 yields " + << ( s2 > s1 ? "true" : "false" ) + << "\ns2 < s1 yields " + << ( s2 < s1 ? "true" : "false" ) + << "\ns2 >= s1 yields " + << ( s2 >= s1 ? "true" : "false" ) + << "\ns2 <= s1 yields " + << ( s2 <= s1 ? "true" : "false" ); + + // test string member function empty + cout << "\n\nTesting s3.empty():\n"; + + if ( s3.empty() ) { + cout << "s3 is empty; assigning s1 to s3;\n"; + s3 = s1; // assign s1 to s3 + cout << "s3 is \"" << s3 << "\""; + } + + // test overloaded string concatenation operator + cout << "\n\ns1 += s2 yields s1 = "; + s1 += s2; // test overloaded concatenation + cout << s1; + + // test overloaded string concatenation operator + // with C-style string + cout << "\n\ns1 += \" to you\" yields\n"; + s1 += " to you"; + cout << "s1 = " << s1 << "\n\n"; + + // test string member function substr + cout << "The substring of s1 starting at location 0 for\n" + << "14 characters, s1.substr(0, 14), is:\n" + << s1.substr( 0, 14 ) << "\n\n"; + + // test substr "to-end-of-string" option + cout << "The substring of s1 starting at\n" + << "location 15, s1.substr(15), is:\n" + << s1.substr( 15 ) << '\n'; + + // test copy constructor + string *s4Ptr = new string( s1 ); + cout << "\n*s4Ptr = " << *s4Ptr << "\n\n"; + + // test assignment (=) operator with self-assignment + cout << "assigning *s4Ptr to *s4Ptr\n"; + *s4Ptr = *s4Ptr; + cout << "*s4Ptr = " << *s4Ptr << '\n'; + + // test destructor + delete s4Ptr; + + // test using subscript operator to create lvalue + s1[ 0 ] = 'H'; + s1[ 6 ] = 'B'; + cout << "\ns1 after s1[0] = 'H' and s1[6] = 'B' is: " + << s1 << "\n\n"; + + // test subscript out of range with string member function "at" + cout << "Attempt to assign 'd' to s1.at( 30 ) yields:" << endl; + s1.at( 30 ) = 'd'; // ERROR: subscript out of range + + 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/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp b/Bachelor/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp new file mode 100644 index 0000000..7fda752 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp @@ -0,0 +1,134 @@ +// Fig. 8.14: fig08_14.cpp +// Demonstrating standard library class vector. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::setw; + +#include + +using std::vector; + +void outputVector( const vector< int > & ); +void inputVector( vector< int > & ); + +int main() +{ + vector< int > integers1( 7 ); // 7-element vector< int > + vector< int > integers2( 10 ); // 10-element vector< int > + + // print integers1 size and contents + cout << "Size of vector integers1 is " + << integers1.size() + << "\nvector after initialization:\n"; + outputVector( integers1 ); + + // print integers2 size and contents + cout << "\nSize of vector integers2 is " + << integers2.size() + << "\nvector after initialization:\n"; + outputVector( integers2 ); + + // input and print integers1 and integers2 + cout << "\nInput 17 integers:\n"; + inputVector( integers1 ); + inputVector( integers2 ); + + cout << "\nAfter input, the vectors contain:\n" + << "integers1:\n"; + outputVector( integers1 ); + cout << "integers2:\n"; + outputVector( integers2 ); + + // use overloaded inequality (!=) operator + cout << "\nEvaluating: integers1 != integers2\n"; + + if ( integers1 != integers2 ) + cout << "integers1 and integers2 are not equal\n"; + + // create vector integers3 using integers1 as an + // initializer; print size and contents + vector< int > integers3( integers1 ); // copy constructor + + cout << "\nSize of vector integers3 is " + << integers3.size() + << "\nvector after initialization:\n"; + outputVector( integers3 ); + + + // use overloaded assignment (=) operator + cout << "\nAssigning integers2 to integers1:\n"; + integers1 = integers2; + + cout << "integers1:\n"; + outputVector( integers1 ); + cout << "integers2:\n"; + outputVector( integers1 ); + + // use overloaded equality (==) operator + cout << "\nEvaluating: integers1 == integers2\n"; + + if ( integers1 == integers2 ) + cout << "integers1 and integers2 are equal\n"; + + // use overloaded subscript operator to create rvalue + cout << "\nintegers1[5] is " << integers1[ 5 ]; + + // use overloaded subscript operator to create lvalue + cout << "\n\nAssigning 1000 to integers1[5]\n"; + integers1[ 5 ] = 1000; + cout << "integers1:\n"; + outputVector( integers1 ); + + // attempt to use out of range subscript + cout << "\nAttempt to assign 1000 to integers1.at( 15 )" + << endl; + integers1.at( 15 ) = 1000; // ERROR: out of range + + return 0; + +} // end main + +// output vector contents +void outputVector( const vector< int > &array ) +{ + for ( int i = 0; i < array.size(); i++ ) { + cout << setw( 12 ) << array[ i ]; + + if ( ( i + 1 ) % 4 == 0 ) // 4 numbers per row of output + cout << endl; + + } // end for + + if ( i % 4 != 0 ) + cout << endl; + +} // end function outputVector + +// input vector contents +void inputVector( vector< int > &array ) +{ + for ( int i = 0; i < array.size(); i++ ) + cin >> array[ i ]; + +} // end function inputVector + +/************************************************************************** + * (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/Prog1/examples/ch08/Fig08_15_17/Complex1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.cpp new file mode 100644 index 0000000..130d39e --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.cpp @@ -0,0 +1,54 @@ +// Fig. 8.16: complex1.cpp +// Complex class member function definitions. +#include + +using std::cout; + +#include "complex1.h" // Complex class definition + +// Constructor +Complex::Complex( double realPart, double imaginaryPart ) + : real( realPart ), + imaginary( imaginaryPart ) +{ + // empty body + +} // end Complex constructor + +// addition operator +Complex Complex::operator+( const Complex &operand2 ) const +{ + return Complex( real + operand2.real, + imaginary + operand2.imaginary ); + +} // end function operator+ + +// subtraction operator +Complex Complex::operator-( const Complex &operand2 ) const +{ + return Complex( real - operand2.real, + imaginary - operand2.imaginary ); + +} // end function operator- + +// display a Complex object in the form: (a, b) +void Complex::print() const +{ + cout << '(' << real << ", " << imaginary << ')'; + +} // 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/Prog1/examples/ch08/Fig08_15_17/Complex1.h b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.h new file mode 100644 index 0000000..934f2f2 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.h @@ -0,0 +1,35 @@ +// Fig. 8.15: complex1.h +// Complex class definition. +#ifndef COMPLEX1_H +#define COMPLEX1_H + +class Complex { + +public: + Complex( double = 0.0, double = 0.0 ); // constructor + Complex operator+( const Complex & ) const; // addition + Complex operator-( const Complex & ) const; // subtraction + void print() const; // output + +private: + double real; // real part + double imaginary; // imaginary part + +}; // end class Complex + +#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/Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp new file mode 100644 index 0000000..d98f9bb --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp @@ -0,0 +1,57 @@ +// Fig. 8.17: fig08_17.cpp +// Complex class test program. +#include + +using std::cout; +using std::endl; + +#include "complex1.h" + +int main() +{ + Complex x; + Complex y( 4.3, 8.2 ); + Complex z( 3.3, 1.1 ); + + cout << "x: "; + x.print(); + cout << "\ny: "; + y.print(); + cout << "\nz: "; + z.print(); + + x = y + z; + cout << "\n\nx = y + z:\n"; + x.print(); + cout << " = "; + y.print(); + cout << " + "; + z.print(); + + x = y - z; + cout << "\n\nx = y - z:\n"; + x.print(); + cout << " = "; + y.print(); + cout << " - "; + z.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. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp new file mode 100644 index 0000000..f73bde7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp @@ -0,0 +1,51 @@ +// Fig. 8.20: fig08_20.cpp +// HugeInt test program. +#include + +using std::cout; +using std::endl; + +#include "hugeint1.h" + +int main() +{ + HugeInt n1( 7654321 ); + HugeInt n2( 7891234 ); + HugeInt n3( "99999999999999999999999999999" ); + HugeInt n4( "1" ); + HugeInt n5; + + cout << "n1 is " << n1 << "\nn2 is " << n2 + << "\nn3 is " << n3 << "\nn4 is " << n4 + << "\nn5 is " << n5 << "\n\n"; + + n5 = n1 + n2; + cout << n1 << " + " << n2 << " = " << n5 << "\n\n"; + + cout << n3 << " + " << n4 << "\n= " << ( n3 + n4 ) + << "\n\n"; + + n5 = n1 + 9; + cout << n1 << " + " << 9 << " = " << n5 << "\n\n"; + + n5 = n2 + "10000"; + cout << n2 << " + " << "10000" << " = " << n5 << 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/Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp new file mode 100644 index 0000000..6e1aff7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp @@ -0,0 +1,121 @@ +// Fig. 8.19: hugeint1.cpp +// HugeInt member-function and friend-function definitions. + +#include // isdigit function prototype +#include // strlen function prototype + +#include "hugeint1.h" // HugeInt class definition + +// default constructor; conversion constructor that converts +// a long integer into a HugeInt object +HugeInt::HugeInt( long value ) +{ + // initialize array to zero + for ( int i = 0; i <= 29; i++ ) + integer[ i ] = 0; + + // place digits of argument into array + for ( int j = 29; value != 0 && j >= 0; j-- ) { + integer[ j ] = value % 10; + value /= 10; + + } // end for + +} // end HugeInt default/conversion constructor + +// conversion constructor that converts a character string +// representing a large integer into a HugeInt object +HugeInt::HugeInt( const char *string ) +{ + // initialize array to zero + for ( int i = 0; i <= 29; i++ ) + integer[ i ] = 0; + + // place digits of argument into array + int length = strlen( string ); + + for ( int j = 30 - length, k = 0; j <= 29; j++, k++ ) + + if ( isdigit( string[ k ] ) ) + integer[ j ] = string[ k ] - '0'; + +} // end HugeInt conversion constructor + +// addition operator; HugeInt + HugeInt +HugeInt HugeInt::operator+( const HugeInt &op2 ) +{ + HugeInt temp; // temporary result + int carry = 0; + + for ( int i = 29; i >= 0; i-- ) { + temp.integer[ i ] = + integer[ i ] + op2.integer[ i ] + carry; + + // determine whether to carry a 1 + if ( temp.integer[ i ] > 9 ) { + temp.integer[ i ] %= 10; // reduce to 0-9 + carry = 1; + + } // end if + + // no carry + else + carry = 0; + } + + return temp; // return copy of temporary object + +} // end function operator+ + +// addition operator; HugeInt + int +HugeInt HugeInt::operator+( int op2 ) +{ + // convert op2 to a HugeInt, then invoke + // operator+ for two HugeInt objects + return *this + HugeInt( op2 ); + +} // end function operator+ + +// addition operator; +// HugeInt + string that represents large integer value +HugeInt HugeInt::operator+( const char *op2 ) +{ + // convert op2 to a HugeInt, then invoke + // operator+ for two HugeInt objects + return *this + HugeInt( op2 ); + +} // end operator+ + +// overloaded output operator +ostream& operator<<( ostream &output, const HugeInt &num ) +{ + int i; + + for ( i = 0; ( num.integer[ i ] == 0 ) && ( i <= 29 ); i++ ) + ; // skip leading zeros + + if ( i == 30 ) + output << 0; + else + + for ( ; i <= 29; i++ ) + output << num.integer[ i ]; + + return output; + +} // end function operator<< + +/************************************************************************** + * (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/Prog1/examples/ch08/Fig08_18_20/Hugeint1.h b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.h new file mode 100644 index 0000000..46dd1df --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.h @@ -0,0 +1,47 @@ +// Fig. 8.18: hugeint1.h +// HugeInt class definition. +#ifndef HUGEINT1_H +#define HUGEINT1_H + +#include + +using std::ostream; + +class HugeInt { + friend ostream &operator<<( ostream &, const HugeInt & ); + +public: + HugeInt( long = 0 ); // conversion/default constructor + HugeInt( const char * ); // conversion constructor + + // addition operator; HugeInt + HugeInt + HugeInt operator+( const HugeInt & ); + + // addition operator; HugeInt + int + HugeInt operator+( int ); + + // addition operator; + // HugeInt + string that represents large integer value + HugeInt operator+( const char * ); + +private: + short integer[ 30 ]; + +}; // end class HugeInt + +#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/Prog1/examples/elevator/ElevatorSimulation.cpp b/Bachelor/Prog1/examples/elevator/ElevatorSimulation.cpp new file mode 100644 index 0000000..6f9e648 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/examples/elevator/bell.cpp b/Bachelor/Prog1/examples/elevator/bell.cpp new file mode 100644 index 0000000..350b826 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 destructed" << 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/Prog1/examples/elevator/bell.h b/Bachelor/Prog1/examples/elevator/bell.h new file mode 100644 index 0000000..a0ef0bc --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/examples/elevator/building.cpp b/Bachelor/Prog1/examples/elevator/building.cpp new file mode 100644 index 0000000..b2eaec3 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 constructed" << endl; + +} // end Building constructor + +// destructor +Building::~Building() +{ + cout << "building destructed" << 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/Prog1/examples/elevator/building.h b/Bachelor/Prog1/examples/elevator/building.h new file mode 100644 index 0000000..e45e3cd --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/examples/elevator/clock.cpp b/Bachelor/Prog1/examples/elevator/clock.cpp new file mode 100644 index 0000000..466f392 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 constructed" << endl; + +} // end Clock constructor + +// destructor +Clock::~Clock() +{ + cout << "clock destructed" << 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/Prog1/examples/elevator/clock.h b/Bachelor/Prog1/examples/elevator/clock.h new file mode 100644 index 0000000..29bb55a --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/examples/elevator/door.cpp b/Bachelor/Prog1/examples/elevator/door.cpp new file mode 100644 index 0000000..047fc1b --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 constructed" << endl; + +} // end Door constructor + +// destructor +Door::~Door() +{ + cout << "door destructed" << 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/Prog1/examples/elevator/door.h b/Bachelor/Prog1/examples/elevator/door.h new file mode 100644 index 0000000..a15a5d1 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/examples/elevator/elevator.cpp b/Bachelor/Prog1/examples/elevator/elevator.cpp new file mode 100644 index 0000000..1f271c1 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 + +// 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 constructed" << endl; + +} // end Elevator constructor + +// destructor +Elevator::~Elevator() +{ + delete passengerPtr; + cout << "elevator destructed" << 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/Prog1/examples/elevator/elevator.h b/Bachelor/Prog1/examples/elevator/elevator.h new file mode 100644 index 0000000..e032607 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 current 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/Prog1/examples/elevator/elevatorButton.cpp b/Bachelor/Prog1/examples/elevator/elevatorButton.cpp new file mode 100644 index 0000000..f1e3a51 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/elevatorButton.cpp @@ -0,0 +1,57 @@ +// Fig. 7.38: 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 ) + : pressed( false ), + elevatorRef( elevatorHandle ) +{ + cout << "elevator button constructed" << endl; + +} // end ElevatorButton constructor + +// destructor +ElevatorButton::~ElevatorButton() +{ + cout << "elevator button destructed" << endl; + +} // end ~ElevatorButton destructor + +// press button and signal elevator to prepare to leave floor +void ElevatorButton::pressButton() +{ + pressed = true; + cout << "elevator button tells elevator to prepare to leave" + << endl; + elevatorRef.prepareToLeave( true ); + +} // end function pressButton + +// reset button +void ElevatorButton::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/Prog1/examples/elevator/elevatorButton.h b/Bachelor/Prog1/examples/elevator/elevatorButton.h new file mode 100644 index 0000000..7b2c5be --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/elevatorButton.h @@ -0,0 +1,40 @@ +// Fig. 7.37: elevatorButton.h +// ElevatorButton class definition. +#ifndef ELEVATORBUTTON_H +#define ELEVATORBUTTON_H + +class Elevator; // forward declaration + +class ElevatorButton { + +public: + ElevatorButton( Elevator & ); // constructor + ~ElevatorButton(); // destructor + + void pressButton(); // press the button + void resetButton(); // reset the button + +private: + bool pressed; // state of button + + // reference to elevator containing this button + Elevator &elevatorRef; + +}; // 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/Prog1/examples/elevator/floor.cpp b/Bachelor/Prog1/examples/elevator/floor.cpp new file mode 100644 index 0000000..c651095 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 << " constructed" << endl; + +} // end Floor constructor + +// destructor +Floor::~Floor() +{ + delete occupantPtr; + cout << "floor " << floorNumber << " destructed" << 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/Prog1/examples/elevator/floor.h b/Bachelor/Prog1/examples/elevator/floor.h new file mode 100644 index 0000000..6ead42a --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/examples/elevator/floorButton.cpp b/Bachelor/Prog1/examples/elevator/floorButton.cpp new file mode 100644 index 0000000..6d19769 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/floorButton.cpp @@ -0,0 +1,62 @@ +// Fig. 7.40: 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 ) + : floorNumber( floor ), + pressed( false ), + elevatorRef( elevatorHandle ) +{ + cout << "floor " << floorNumber << " button constructed" + << endl; + +} // end FloorButton constructor + +// destructor +FloorButton::~FloorButton() +{ + cout << "floor " << floorNumber << " button destructed" + << endl; + +} // end ~FloorButton destructor + +// press the button +void FloorButton::pressButton() +{ + pressed = true; + cout << "floor " << floorNumber + << " button summons elevator" << endl; + + // call elevator to this floor + elevatorRef.summonElevator( floorNumber ); + +} // end function pressButton + +// reset button +void FloorButton::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/Prog1/examples/elevator/floorButton.h b/Bachelor/Prog1/examples/elevator/floorButton.h new file mode 100644 index 0000000..b09c6e5 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/floorButton.h @@ -0,0 +1,42 @@ +// Fig. 7.39: floorButton.h +// FloorButton class definition. +#ifndef FLOORBUTTON_H +#define FLOORBUTTON_H + +class Elevator; // forward declaration + +class FloorButton { + +public: + FloorButton( int, Elevator & ); // constructor + ~FloorButton(); // destructor + + void pressButton(); // press the button + void resetButton(); // reset the button + +private: + const int floorNumber; // button's floor number + bool pressed; // button state + + // reference to elevator used to summon + // elevator to floor + Elevator &elevatorRef; + +}; // 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/Prog1/examples/elevator/light.cpp b/Bachelor/Prog1/examples/elevator/light.cpp new file mode 100644 index 0000000..1a9eb79 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/light.cpp @@ -0,0 +1,65 @@ +// 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 constructed" + << endl; + +} // end Light constructor + +// destuctor +Light::~Light() +{ + cout << "floor " << floorNumber + << " light destructed" << 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/Prog1/examples/elevator/light.h b/Bachelor/Prog1/examples/elevator/light.h new file mode 100644 index 0000000..88e920d --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/light.h @@ -0,0 +1,36 @@ +// 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/Prog1/examples/elevator/person.cpp b/Bachelor/Prog1/examples/elevator/person.cpp new file mode 100644 index 0000000..72e070d --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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 ) +{ + cout << "person " << ID << " constructed" << endl; + +} // 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/Prog1/examples/elevator/person.h b/Bachelor/Prog1/examples/elevator/person.h new file mode 100644 index 0000000..7a6f10c --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/examples/elevator/scheduler.cpp b/Bachelor/Prog1/examples/elevator/scheduler.cpp new file mode 100644 index 0000000..73bdebb --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/scheduler.cpp @@ -0,0 +1,134 @@ +// Fig. 7.30: scheduler.cpp +// Member-function definitions for class Scheduler. +#include + +using std::cout; +using std::endl; + +#include +#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 constructed" << endl; + + // schedule first arrivals for floor 1 and floor 2 + scheduleTime( floor1Ref ); + scheduleTime( floor2Ref ); + +} // end Scheduler constructor + +// destructor +Scheduler::~Scheduler() +{ + cout << "scheduler destructed" << 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/Prog1/examples/elevator/scheduler.h b/Bachelor/Prog1/examples/elevator/scheduler.h new file mode 100644 index 0000000..a035d08 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/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/Prog1/probeklausur/lotto.h b/Bachelor/Prog1/probeklausur/lotto.h new file mode 100644 index 0000000..373a19a --- /dev/null +++ b/Bachelor/Prog1/probeklausur/lotto.h @@ -0,0 +1,25 @@ +// Sven Eisenhauer +// Probeklausur 09.02.2005 +// +// Definition of class LottoGenerator + +#ifndef LOTTO_H +#define LOTTO_H + +class LottoGenerator { +public: + LottoGenerator(); + ~LottoGenerator(); + void drawAllNumbers(); + void printAllNumbers(); + void sortSixNumbers(); + int getAllNumbers( int* ); + long getNumberOfDraws(); +private: + const int ARRAY_SIZE; + int * sixNumbers; + int seventhNumber; + long numberOfDraws; +}; + +#endif diff --git a/Bachelor/Prog1/probeklausur/lottogenerator.cpp b/Bachelor/Prog1/probeklausur/lottogenerator.cpp new file mode 100644 index 0000000..02c0f46 --- /dev/null +++ b/Bachelor/Prog1/probeklausur/lottogenerator.cpp @@ -0,0 +1,89 @@ +// Sven Eisenhauer +// Probeklausur 09.02.2005 +// +// Implementation of class LottoGenerator + +#include +#include +using std::cout; +using std::endl; + +#include +using std::setw; + +#include "lotto.h" + +LottoGenerator::LottoGenerator() + :ARRAY_SIZE(6) +{ + numberOfDraws=0; + sixNumbers = new int[ARRAY_SIZE]; + for (int i=0;i +using std::cout; +using std::endl; +#include +using std::setw; + +int average(int *); + +const int ARRAY_SIZE=6; + +int main() +{ + LottoGenerator lotto; + int nrEinstZusatzZ=0; + long ZusatzZ; + int erg[ARRAY_SIZE]; + const int NUMBERS=49; + int result[NUMBERS]={0}; + int avg=0; + + for(int i=0;i<10;i++) + { + lotto.drawAllNumbers(); + lotto.sortSixNumbers(); + lotto.printAllNumbers(); + } + + for(i=0;i<1000000;i++) + { + lotto.drawAllNumbers(); + ZusatzZ=lotto.getAllNumbers(erg); + if(ZusatzZ<10) + nrEinstZusatzZ++; + } + cout << endl << "Eine einstellige Zusatzzahl gab es "<< nrEinstZusatzZ <<" mal."; + + for(i=0;i<1000000;i++) + { + lotto.drawAllNumbers(); + lotto.getAllNumbers(erg); + avg=average(erg); + result[avg]++; + } + + cout << endl <<"Häufigkeitsverteilung: " << endl; + for (i=0;i