123

Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

Datei 1: dir.txt, 29.6.2016 11:57:341 Alle Dateinamen wurden relativ zum Speicherverzeichnis angegeben.2

3 Das Speicherverzeichnis ist4 K:\RZ\KURSE\BRAUN\svn\cplusplus\trunk\cplusplus5

6 Wenn im Programm steht7 // progproc/hallo/hallo.cpp8

9 dann findet man die Datei in10 K:\RZ\KURSE\BRAUN\svn\cplusplus\trunk\cplusplus\procprog\hallo\hallo.cpp11

Datei 2: mkincl., 26.4.2017 12:10:221 # include file for make with all general rules2

3 #CC = clang4 #CXX = clang++5 CC = gcc6 CXX = g++7 CFLAGS = -x c -std=c11 -pedantic -x c8 CXXFLAGS = -x c++ -std=c++11 -pedantic9

10 %.res %.rs %.r1 %.r2 %.r3 %.exe : dep11

12 %.res : %.exe13 ./$< > $@14

15 %.r1 : %.exe16 ./$< < $*.i1 > $@17

18 %.r2 : %.exe19 ./$< < $*.i2 > $@20

21 %.r3 : %.exe22 ./$< < $*.i3 > $@23

24 %.rs : %.exe25 ./$< < $*.in > $@26

27 %.exe : %.o28 $(CXX) -o $@ $<29

30 %.rc : %.ex31 ./$ > $@32

33 %.ex : %.o34 $(CC) -o $@ $<35

36 clean:37 rm -f *.o *.exe *.res *.r1 *.r2 *.r3 *.rs *~ dep text.* TEXT.* *.log a.out a.exe38

39 dep:40 -$(CC) -MM *.c > dep41 -$(CXX) -MM *.cpp >> dep42

Datei 3: itor0.c, 29.6.2016 11:57:501 /* stl/string/itor0.c */2

3 #include <stdio.h>4 #include <string.h>5 #include <stdlib.h>6

7 int cmp (const void * v1, const void * v2)8 {9 unsigned char c1, c2;10 c1 = *(unsigned char *)v1;11 c2 = *(unsigned char *)v2;12 return c1 - c2;13 }14

15 int main (void)16 {17 char * text = "Perched atop a high mountain on the other side, its windows sparkling "18 "in the starry sky, was a vast castle with many turrets and towers.";19 char * m;20 int i, j, h;21

1

Page 2: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

2 itor0.c, 29.6.2016 11:57:50

22 printf ("text: %s\n", text);23

24 m = (char *) malloc ((strlen (text) + 1) * sizeof (char));25 strcpy (m, text);26 printf ("text: %s\n", m);27 qsort ((void *)m, strlen (m), sizeof (char), &cmp);28 /*29 for (i = 0; i < strlen (m) - 1; i++)30 {31 for (j = i+1; j < strlen (m); j++)32 {33 if (m [i] > m [j])34 {35 h = m [i];36 m [i] = m [j];37 m [j] = h;38 } } }39 */40 printf ("ettx: %s\n", m);41

42 for (i = 0, j = 1; j <= strlen (m); j++)43 {44 if (m [i] != m [j]) { i++; m [i] = m [j]; }45 }46 printf ("etx: %s (%d)\n", m, (int)strlen (m));47

48 free (m);49

50 return 0;51 }52

Datei 4: itor0.res, 26.4.2017 12:01:141 text: Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.2 text: Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.3 ettx: ,,.Paaaaaaaaaaaccddddeeeeeeeeegghhhhhhhiiiiiiiikkllmmnnnnnnnnoooooopprrrrrrrrssssssssssstttttttttttttuuvwwwwwyyy4 etx: ,.Pacdeghiklmnoprstuvwy (24)5

Datei 5: itor1.cpp, 29.6.2016 11:57:501 // stl/string/itor1.cpp2

3 #include <iostream>4 #include <cstring>5

6 using namespace std;7

8 int main ()9 {10 char * text = (char*)"Perched atop a high mountain on the other side, its windows sparkling "11 "in the starry sky, was a vast castle with many turrets and towers.";12 char * m;13 int i, j, h;14

15 cout << "text: " << text << endl;16

17 m = new char [strlen (text) + 1];18 strcpy (m, text);19 cout << "text: " << m << endl;20

21 for (i = 0; i < (int)strlen (m) - 1; i++)22 {23 for (j = i+1; j < (int)strlen (m); j++)24 {25 if (m [i] > m [j])26 {27 h = m [i];28 m [i] = m [j];29 m [j] = h;30 }31 }32 }33 cout << "ettx: " << m << endl;34

35 for (i = 0, j = 1; j <= (int)strlen (m); j++)36 {37 if (m [i] != m [j]) { i++; m [i] = m [j]; }38 }39 cout << "etx: " << m << endl;

Page 3: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

itor5.cpp, 29.6.2016 11:57:50 3

40

41 delete [] m;42 }43

Datei 6: itor1.res, 26.4.2017 12:01:141 text: Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.2 text: Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.3 ettx: ,,.Paaaaaaaaaaaccddddeeeeeeeeegghhhhhhhiiiiiiiikkllmmnnnnnnnnoooooopprrrrrrrrssssssssssstttttttttttttuuvwwwwwyyy4 etx: ,.Pacdeghiklmnoprstuvwy5

Datei 7: itor3.cpp, 29.6.2016 11:57:501 // stl/string/itor3.cpp2

3 #include <iostream>4 #include <string>5 #include <set>6 #include <algorithm>7

8 using namespace std;9

10 void pr (char ch) { cout << ch; }11

12 int main ()13 {14 string text ("Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.");15 cout << "text: " << text << endl;16

17 set<char> m (text.begin(), text.end());18 cout << "etx: "; for_each (m.begin(), m.end(), pr);19 cout << " (" << m.size() << ")" << endl;20 }21

Datei 8: itor3.res, 26.4.2017 12:01:141 text: Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.2 etx: ,.Pacdeghiklmnoprstuvwy (24)3

Datei 9: itor4.cpp, 29.6.2016 11:57:501 // stl/string/itor4.cpp2

3 #include <iostream>4 #include <string>5 #include <set>6 #include <algorithm>7

8 using namespace std;9

10 int main ()11 {12 string text ("Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.");13 cout << "text: " << text << endl;14

15 set<char> m (text.begin(), text.end());16 cout << "etx: "; for_each (m.begin(), m.end(), [](char ch) {cout << ch;});17 cout << " (" << m.size() << ")" << endl;18 }19

Datei 10: itor4.res, 26.4.2017 12:01:161 text: Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.2 etx: ,.Pacdeghiklmnoprstuvwy (24)3

Datei 11: itor5.cpp, 29.6.2016 11:57:501 �2 // stl/string/itor5.cpp3 // without a gcc 4.9 try4 // http://en.cppreference.com/w/cpp/regex/regex_match5 #include <iostream>6 #include <string>7 #include <set>8 #include <algorithm>9 #include <regex>10 #include <vector>11

12 using namespace std;13

Page 4: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

4 itor5.cpp, 29.6.2016 11:57:50

14 int main ()15 {16 string text ("Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.");17 cout << "text: " << text << endl;18 regex r ("\\w+\\W*"); // word nonword19 vector<string> v;20

21 smatch m;22 while (regex_search (text, m, r))23 {24 for (auto x:m) {cout << x << endl;25 v.push_back (x); }26 text = m.suffix().str();27 }28

29 set<string> M (v.begin(), v.end());30 cout << "etx: "; for_each (M.begin(), M.end(), [](string ch) {cout << ch;});31 cout << " (" << M.size() << ")" << endl;32

33 }34

35

Datei 12: itor5.res, 26.4.2017 12:01:181 text: Perched atop a high mountain on the other side, its windows sparkling in the starry sky, was a vast castle with many turrets and towers.2 Perched3 atop4 a5 high6 mountain7 on8 the9 other10 side,11 its12 windows13 sparkling14 in15 the16 starry17 sky,18 was19 a20 vast21 castle22 with23 many24 turrets25 and26 towers.27 etx: Perched a and atop castle high in its many mountain on other side, sky, sparkling starry the towers.turrets vast was windows with (23)28

Datei 13: nichts.cpp, 29.6.2016 11:57:361 // procprog/nichts/nichts.cpp2

3 // Das einfachste C++-Programm hat die folgende Form4

5 int main (/*void entfaellt immer*/)6 { // return 0; darf in C++ entfallen7 }8

9 /* Alternativ ist wie in C erlaubt:10 * int main (int argc, char* argv []) { }11 *12 * Zur Vermeidung von exit(1);13 * ist in main ein function-try-block mit return 1; noetig:14 * int main()15 * try { return 0; }16 * catch (...) { return 1; }17 */

Datei 14: hallo.cpp, 29.6.2016 11:57:361 // progproc/hallo/hallo.cpp2

3 #include <iostream>4

5 using namespace std;6

7 int main ()

Page 5: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

output.cpp, 29.6.2016 11:57:38 5

8 { cout << "C++: Hallo\n";9 }10

Datei 15: hallo.res, 26.4.2017 10:05:161 C++: Hallo2

Datei 16: cpp1.a2t, 29.6.2016 11:57:341 stl\string\itor0.c2 stl\string\itor0.res3 stl\string\itor1.cpp4 stl\string\itor1.res5 stl\string\itor3.cpp6 stl\string\itor3.res7 stl\string\itor4.cpp8 stl\string\itor4.res9 stl\string\itor5.cpp10 stl\string\itor5.res11 procprog\nichts\nichts.cpp12 procprog\hallo\hallo.cpp13 procprog\hallo\hallo.res14

Datei 17: input.cpp, 29.6.2016 11:57:381 /* progproc/inout/input.cpp */2

3 #include <iostream>4 #include <iomanip>5

6 using namespace std;7

8 int main ()9 { int i;10

11 cout << "\nOktalzahl eingeben: "; cin >> oct >> i >> dec; // zurueckstellen!12 cout << "\nGelesen wurde " << i << " = " << oct << i << "\n"; // ab jetzt alles oktal13

14 do15 { cin >> i; // dezimal16 cout << " i = " << i << "\n"; // oktal17 if (cin.eof ()) { cout << "\nDateiende\n"; }18 } while (i && cin.good());19

20 cout << "\nLetztes i (dezimal): " << dec << i;21 }22

Datei 18: input.in, 29.6.2016 11:57:381 -792 713 ab4 0435 24 236 12347 Hallo % 23Hallo%238

9

Datei 19: input.rs, 26.4.2017 10:05:181

2 Oktalzahl eingeben:3 Gelesen wurde -7 = 377777777714 i = 115 i = 1076 i = 07

8 Letztes i (dezimal): 0

Datei 20: output.cpp, 29.6.2016 11:57:381 /* progproc/inout/output.cpp */2

3 #include <iostream>4 #include <iomanip>5

6 using namespace std;7

8 int main ()9 { int i, j;10 ios::fmtflags f = cout.flags();

Page 6: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

6 output.cpp, 29.6.2016 11:57:38

11

12 i = 342;13 j = 173;14 cout << i << " - " << j << " = " << i - j << " (dezimal)\n";15 i = 0342;16 j = 0173;17 cout << oct << i << " - " << j << " = " << i - j << " (oktal)\n";18 i = 0x342;19 j = 0x173;20 cout << hex << i << " - " << j << " = " << i - j << " (sedezimal)\n";21

22 cout << dec << setw (10) << i << " " << i << "\n";23 cout << dec << setw (10) << setfill ('#') << i << "\n";24

25 double pi = 3.141592653589793;26 cout << oct << pi << dec << endl;27 cout << setw (20) << pi << endl;28 cout << setw (20) << setfill (' ') << pi << endl;29 cout << setw (20) << setprecision (15) << pi << endl;30 cout.setf (ios::scientific, ios::floatfield);31 cout << pi << endl;32 cout << setw (15) << setprecision (7) << pi << endl;33 cout.flags (f);34 cout << pi << endl;35 }36

Datei 21: output.res, 26.4.2017 10:05:181 342 - 173 = 169 (dezimal)2 342 - 173 = 147 (oktal)3 342 - 173 = 1cf (sedezimal)4 834 8345 #######8346 3.141597 #############3.141598 3.141599 3.1415926535897910 3.141592653589793e+0011 3.1415927e+0012 3.14159313

Datei 22: konvert1.cpp, 29.6.2016 11:57:381 /* progproc/inout/konvert1.cpp (ntmbs statt string in konvert.cpp) */2

3 #include <iostream>4 #include <iomanip>5 #include <string>6

7 using namespace std;8

9 void Store (char ch, string & s)10 { s += ch;11 }12

13 void KonvRek (int n, int b, string & s)14 { int q, r;15 q = n / b;16 r = n % b;17 if (q) KonvRek (q, b, s);18 if (b <= 10) Store (static_cast <char> (r + '0'), s);19 else if (b <= 16)20 { if (r < 10) Store (static_cast <char> (r + '0'), s);21 else Store (static_cast <char> (r + 'A' - 10), s);22 }23 else24 { KonvRek (r, 10, s);25 Store (',', s);26 } }27

28 void Konvertiere (int n, int b, string & s)29 { s.clear ();30 KonvRek (n, b, s);31 }32

33 int main ()34 { int i;35 string b8, b16, b60;36

Page 7: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

stringio.cpp, 29.6.2016 11:57:38 7

37 do38 { cin >> i;39 Konvertiere (i, 8, b8);40 Konvertiere (i, 16, b16);41 Konvertiere (i, 60, b60);42 cout << "i = " << i << "(10) = "43 << b8 << "(8) = "44 << b16 << "(16) = "45 << b60 << "(60)"46 << endl;47 } while (cin.good());48 }

Datei 23: konvert1.in, 29.6.2016 11:57:381 02 13 24 75 86 97 108 159 1610 2011 5912 6013 6114 10015 100016 102417 360018 1000019 1638420 3000021 3276722

Datei 24: konvert1.rs, 26.4.2017 10:05:181 i = 0(10) = 0(8) = 0(16) = 0,(60)2 i = 1(10) = 1(8) = 1(16) = 1,(60)3 i = 2(10) = 2(8) = 2(16) = 2,(60)4 i = 7(10) = 7(8) = 7(16) = 7,(60)5 i = 8(10) = 10(8) = 8(16) = 8,(60)6 i = 9(10) = 11(8) = 9(16) = 9,(60)7 i = 10(10) = 12(8) = A(16) = 10,(60)8 i = 15(10) = 17(8) = F(16) = 15,(60)9 i = 16(10) = 20(8) = 10(16) = 16,(60)10 i = 20(10) = 24(8) = 14(16) = 20,(60)11 i = 59(10) = 73(8) = 3B(16) = 59,(60)12 i = 60(10) = 74(8) = 3C(16) = 1,0,(60)13 i = 61(10) = 75(8) = 3D(16) = 1,1,(60)14 i = 100(10) = 144(8) = 64(16) = 1,40,(60)15 i = 1000(10) = 1750(8) = 3E8(16) = 16,40,(60)16 i = 1024(10) = 2000(8) = 400(16) = 17,4,(60)17 i = 3600(10) = 7020(8) = E10(16) = 1,0,0,(60)18 i = 10000(10) = 23420(8) = 2710(16) = 2,46,40,(60)19 i = 16384(10) = 40000(8) = 4000(16) = 4,33,4,(60)20 i = 30000(10) = 72460(8) = 7530(16) = 8,20,0,(60)21 i = 32767(10) = 77777(8) = 7FFF(16) = 9,6,7,(60)22 i = 0(10) = 0(8) = 0(16) = 0,(60)23

Datei 25: stringio.cpp, 29.6.2016 11:57:381 /* progproc/inout/stringio.cpp: ein- und ausgabe von strings */2

3 #include <iostream>4 #include <string>5

6 using namespace std;7

8 int main ()9 { string s;10 cout << "ASCII/" << L"vielleicht Unicode/" << u8"UTF-8/" << u"UTF-16/" << U"UTF-32" << endl;11 // String Pointer String Pointer Pointer12 cin >> s;13 cout << endl << "s= " << s << "." << endl;14 do15 { getline (cin, s);16 cout << endl << "(Schleife) s= " << s << "." << endl;

Page 8: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

8 stringio.cpp, 29.6.2016 11:57:38

17 } while (cin);18 }19

Datei 26: stringio.in, 29.6.2016 11:57:381 die erste Zeile2 die 2. Zeile3

4 vorher eine Leerzeile5 die letzte Zeile6

Datei 27: stringio.rs, 26.4.2017 10:05:181 ASCII/0x400ef0UTF-8/0x400f480x400f582

3 s= die.4

5 (Schleife) s= erste Zeile.6

7 (Schleife) s= die 2. Zeile.8

9 (Schleife) s= .10

11 (Schleife) s= vorher eine Leerzeile.12

13 (Schleife) s= die letzte Zeile.14

15 (Schleife) s= .16

Datei 28: cpp2.a2t, 29.6.2016 11:57:341 procprog\inout\input.cpp2 procprog\inout\input.in3 procprog\inout\input.rs4 procprog\inout\output.cpp5 procprog\inout\output.res6 procprog\inout\konvert1.cpp7 procprog\inout\konvert1.in8 procprog\inout\konvert1.rs9 procprog\inout\stringio.cpp10 procprog\inout\stringio.in11 procprog\inout\stringio.rs12

Datei 29: �les1.a2t, 29.6.2016 11:57:381 procprog\referenc\files1.a2t2 procprog\referenc\makefile.3

4 procprog\referenc\flanders.txt5 procprog\referenc\wortcnt.cpp6 /m 47 procprog\referenc\wortcnt.res8 /m 09 procprog\referenc\wortcnti.cpp10 /m 411 procprog\referenc\wortcnti.res12 /m 013 procprog\referenc\wortcnts.cpp14 /m 415 procprog\referenc\wortcnts.res16 /m 017 procprog\referenc\wortcntx.cpp18 /m 419 procprog\referenc\wortcntx.res20 /m 021

22 procprog\referenc\icstrng.hpp23 procprog\referenc\icstrng.cpp24 procprog\referenc\icstrng.rs25

26 procprog\referenc\destrng.cpp27 procprog\referenc\destrng.hpp28 procprog\referenc\destrng.rs29 procprog\referenc\sort1.cpp30 procprog\referenc\sort1.res31 procprog\referenc\unique.cpp32 procprog\referenc\unique.rs33 procprog\referenc\vor.cpp34 procprog\referenc\vor.h

Page 9: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

wortcnt.cpp, 29.6.2016 11:57:36 9

35 procprog\referenc\vor.rs36

Datei 30: make�le., 29.6.2016 11:57:381 include ../../mkincl2 include dep3

4 all: wortcnt.res wortcnti.res wortcnts.res wortcntx.res \5 chaos.res chaosi.res chaoss.res chaosx.res \6 icstrng.rs destrng.rs sort1.res vor.rs unique.rs7

8 destring.res : destring.exe namen.dat9 ./destring.exe < namen.dat > destring.res10

11 chaos.res : wortcnt.exe chaos.txt12 ./wortcnt.exe < chaos.txt > chaos.res13

14

15 chaosi.res : wortcnti.exe chaos.txt16 ./wortcnti.exe < chaos.txt > chaosi.res17

18

19 chaoss.res : wortcnts.exe chaos.txt20 ./wortcnts.exe < chaos.txt > chaoss.res21

22

23 chaosx.res : wortcntx.exe chaos.txt24 ./wortcntx.exe < chaos.txt > chaosx.res25

26

27 wortcnt.res : wortcnt.exe flanders.txt28 ./wortcnt.exe < flanders.txt > wortcnt.res29

30

31 wortcnti.res : wortcnti.exe flanders.txt32 ./wortcnti.exe < flanders.txt > wortcnti.res33

34

35 wortcnts.res : wortcnts.exe flanders.txt36 ./wortcnts.exe < flanders.txt > wortcnts.res37

38

39 wortcntx.res : wortcntx.exe flanders.txt40 ./wortcntx.exe < flanders.txt > wortcntx.res41

42

43

Datei 31: �anders.txt, 29.6.2016 11:57:381 http://en.wikipedia.org/wiki/In_Flanders_Fields_%28poem%292 In Flanders Fields and Other Poems, 1919, by John McCrae3

4 In Flanders fields the poppies blow5 Between the crosses, row on row,6 That mark our place; and in the sky7 The larks, still bravely singing, fly8 Scarce heard amid the guns below.9

10 We are the Dead. Short days ago11 We lived, felt dawn, saw sunset glow,12 Loved and were loved, and now we lie13 In Flanders fields.14

15 Take up our quarrel with the foe:16 To you from failing hands we throw17 The torch; be yours to hold it high.18 If ye break faith with us who die19 We shall not sleep, though poppies grow20 In Flanders fields.21

Datei 32: wortcnt.cpp, 29.6.2016 11:57:361 // progproc/referenc/wortcnt.cpp2 // Anzahl von Woertern in einem gegebenen Text3 // Beispiel fuer Referenzen in C++4

5 #include <iostream>6 #include <string>7 #include <cstdlib>8

Page 10: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

10 wortcnt.cpp, 29.6.2016 11:57:36

9 using namespace std;10

11 int & Anzahl (string);12 void Drucke ();13 void Sortiere();14

15 int main ()16 { string wort;17 int ctr = 0;18

19 while (cin.good())20 { cin >> wort;21 if (cin.good() || cin.eof())22 { Anzahl (wort) ++;23 ctr++;24 } }25 Sortiere ();26 Drucke ();27 cout << "\nEingelesene Woerter: " << ctr;28 }29

30 struct Eintrag31 { string w;32 int a;33 };34

35 Eintrag & Suche (string);36

37 int & Anzahl (string w)38 { Eintrag & p = Suche (w);39 return p.a;40 }41

42 const int tmax = 10000;43

44 static Eintrag Tabelle [tmax];45 static int tanz = 0;46

47 Eintrag & Suche (string s)48 { int i;49 for (i = 0; i < tanz; i++)50 { if (s == Tabelle [i] . w) return Tabelle [i];51 }52 if (tanz++ >= tmax) { cout << "Tabellenueberlauf"; exit (1); }53 Tabelle [tanz-1].w = s;54 Tabelle [tanz-1].a = 0;55 return Tabelle [tanz-1];56 }57

58 void Drucke ()59 { int i;60 int ctr1 = 0;61 int ctr2 = 0;62 for (i = 0; i < tanz; i++)63 { cout << Tabelle [i] . w << ": " << Tabelle [i] . a << endl;64 ctr1 += Tabelle [i] . a;65 ctr2++;66 }67 cout << "\nVerschiedene Woerter: " << ctr2;68 cout << "\nGespeicherte Woerter: " << ctr1;69 }70

71 void Sortiere()72 { int i, j;73 Eintrag e;74 for (i = 0; i < tanz - 1; i++)75 { for (j = i + 1; j < tanz; j++)76 { if (Tabelle [i] . w > Tabelle [j] . w)77 { e = Tabelle [i];78 Tabelle [i] = Tabelle [j];79 Tabelle [j] = e;80 } } } }81

Datei 33: wortcnt.res, 26.4.2017 10:05:20

Page 11: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

wortcnti.cpp, 29.6.2016 11:57:38 11

1 1919,: 12 Between: 13 Dead.: 14 Fields: 15 Flanders: 46 If: 17 In: 48 John: 19 Loved: 110 McCrae: 111 Other: 112 Poems,: 113 Scarce: 114 Short: 115 Take: 116 That: 117 The: 218 To: 119 We: 320 ago: 121 amid: 122 and: 423 are: 1

24 be: 125 below.: 126 blow: 127 bravely: 128 break: 129 by: 130 crosses,: 131 dawn,: 132 days: 133 die: 134 failing: 135 faith: 136 felt: 137 fields: 138 fields.: 339 fly: 140 foe:: 141 from: 142 glow,: 143 grow: 144 guns: 145 hands: 146 heard: 1

47 high.: 148 hold: 149 http://en.wikipedia.org/wiki/In_Flanders_Fields_%28poem%29: 150 in: 151 it: 152 larks,: 153 lie: 154 lived,: 155 loved,: 156 mark: 157 not: 158 now: 159 on: 160 our: 261 place;: 162 poppies: 263 quarrel: 164 row: 165 row,: 166 saw: 167 shall: 168 singing,: 169 sky: 1

70 sleep,: 171 still: 172 sunset: 173 the: 674 though: 175 throw: 176 to: 177 torch;: 178 up: 179 us: 180 we: 281 were: 182 who: 183 with: 284 ye: 185 you: 186 yours: 187

88 Verschiedene Woerter: 8689 Gespeicherte Woerter: 10990 Eingelesene Woerter: 109

Datei 34: wortcnti.cpp, 29.6.2016 11:57:381 // progproc/referenc/wortcnti.cpp2 // Anzahl von Woertern (case-insensitive) in einem gegebenen Text3 // Beispiel fuer Referenzen in C++4

5 #include <iostream>6 #include <string>7 #include <cstdlib>8 #include "icstrng.hpp"9

10 using namespace std;11

12 int & Anzahl (icstring);13 void Drucke ();14 void Sortiere();15

16 int main ()17 { icstring wort;18 int ctr = 0;19

20 while (cin.good())21 { cin >> wort;22 if (cin.good() || cin.eof())23 { Anzahl (wort) ++;24 ctr++;25 } }26 Sortiere ();27 Drucke ();28 cout << "\nEingelesene Woerter: " << ctr;29 }30

31 struct Eintrag32 { icstring w;33 int a;34 };35

36 Eintrag & Suche (icstring);37

38 int & Anzahl (icstring w)39 { Eintrag & p = Suche (w);40 return p.a;41 }42

43 const int tmax = 10000;44

45 static Eintrag Tabelle [tmax];46 static int tanz = 0;47

48 Eintrag & Suche (icstring s)49 { int i;50 for (i = 0; i < tanz; i++)51 { if (s == Tabelle [i] . w) return Tabelle [i];52 }53 if (tanz++ >= tmax) { cout << "Tabellenueberlauf"; exit (1); }54 Tabelle [tanz-1].w = s;

Page 12: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

12 wortcnti.res, 26.4.2017 10:05:20

55 Tabelle [tanz-1].a = 0;56 return Tabelle [tanz-1];57 }58

59 void Drucke ()60 { int i;61 int ctr1 = 0;62 int ctr2 = 0;63 for (i = 0; i < tanz; i++)64 { cout << Tabelle [i] . w << ": " << Tabelle [i] . a << endl;65 ctr1 += Tabelle [i] . a;66 ctr2++;67 }68 cout << "\nVerschiedene Woerter: " << ctr2;69 cout << "\nGespeicherte Woerter: " << ctr1;70 }71

72 void Sortiere()73 { int i, j;74 Eintrag e;75 for (i = 0; i < tanz - 1; i++)76 { for (j = i + 1; j < tanz; j++)77 { if (Tabelle [i] . w > Tabelle [j] . w)78 { e = Tabelle [i];79 Tabelle [i] = Tabelle [j];80 Tabelle [j] = e;81 } } } }82

Datei 35: wortcnti.res, 26.4.2017 10:05:20

1 : 12 1919,: 13 ago: 14 amid: 15 and: 46 are: 17 be: 18 below.: 19 Between: 110 blow: 111 bravely: 112 break: 113 by: 114 crosses,: 115 dawn,: 116 days: 117 Dead.: 118 die: 119 failing: 120 faith: 121 felt: 122 Fields: 2

23 fields.: 224 Flanders: 425 fly: 126 foe:: 127 from: 128 glow,: 129 grow: 130 guns: 131 hands: 132 heard: 133 high.: 134 hold: 135 http://en.wikipedia.org/wiki/In_Flanders_Fields_%28poem%29: 136 If: 137 In: 538 it: 139 John: 140 larks,: 141 lie: 142 lived,: 143 Loved: 144 loved,: 1

45 mark: 146 McCrae: 147 not: 148 now: 149 on: 150 Other: 151 our: 252 place;: 153 Poems,: 154 poppies: 255 quarrel: 156 row: 157 row,: 158 saw: 159 Scarce: 160 shall: 161 Short: 162 singing,: 163 sky: 164 sleep,: 165 still: 166 sunset: 1

67 Take: 168 That: 169 the: 870 though: 171 throw: 172 To: 273 torch;: 174 up: 175 us: 176 We: 577 were: 178 who: 179 with: 280 ye: 181 you: 182 yours: 183

84 Verschiedene Woerter: 8285 Gespeicherte Woerter: 10986 Eingelesene Woerter: 109

Datei 36: wortcnts.cpp, 29.6.2016 11:57:381 // progproc/referenc/wortcnts.cpp2 // Anzahl von Woertern in einem gegebenen Text3 // Beispiel fuer Referenzen in C++;4 // Benutzung der STL, insb. von string, iterator und vector5

6 #include <iostream>7 #include <string>8 #include <vector>9 #include <algorithm>10 #include <cstdlib>11

12 using namespace std;13

14 int & Anzahl (string);15 void Drucke ();16 void Sortiere();17

18 int main ()19 { string wort;20 int ctr = 0;21

22 while (cin.good())23 { cin >> wort;24 cout << " " << wort << " " << flush;

Page 13: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

wortcnts.res, 26.4.2017 10:05:22 13

25 if (cin.good() || cin.eof())26 { Anzahl (wort) ++;27 ctr++;28 }29 }30 cout << endl << "Vor Sortieren" << endl;31 Sortiere ();32 cout << "nach Sortieren" << endl;33 Drucke ();34 cout << "\nEingelesene Woerter: " << ctr;35 }36

37 struct Eintrag38 { string w;39 int a;40 friend ostream & operator << (ostream & s, Eintrag b);41 };42

43 ostream & operator << (ostream & s, Eintrag b)44 { ostream::sentry se(s);45 if (se)46 { s << b . w << ": " << b . a;47 }48 return s;49 }50

51

52 Eintrag & Suche (string);53

54 int & Anzahl (string w)55 { Eintrag & p = Suche (w);56 return p.a;57 }58

59 static vector<Eintrag> Tabelle;60

61 #include "vor.h"62

63 Eintrag & Suche (string s)64 { vector<Eintrag> :: iterator p;65 for (p = Tabelle.begin(); p != Tabelle.end(); ++p)66 { if (! svor ((*p) . w, s) && ! svor (s, (*p) . w) ) return (*p);67 }68 Eintrag e; e.w = s; e.a = 0;69 Tabelle.push_back (e);70 return Tabelle.back();71 }72

73 void Drucke ()74 {75 // copy (Tabelle.begin (), Tabelle.end (), ostream_iterator<int>(cout, " / "));76 vector<Eintrag> :: iterator p;77 int ctr1 = 0;78 int ctr2 = 0;79 for (p = Tabelle.begin(); p != Tabelle.end(); ++p)80 { cout << *p << endl;81 ctr1 += (*p) . a;82 ctr2++;83 }84 cout << "\nVerschiedene Woerter: " << ctr2;85 cout << "\nGespeicherte Woerter: " << ctr1;86 //{ ostream_iterator<Eintrag> p (cout);87 // copy (Tabelle.begin(), Tabelle.end(), p);88 // siehe Josuttis, S. 279 !!!!!!89 }90

91 void Sortiere()92 { sort (Tabelle.begin(), Tabelle.end(), &evor);93 }94

Datei 37: wortcnts.res, 26.4.2017 10:05:22

1 http://en.wikipedia.org/wiki/In_Flanders_Fields_%28poem%29 In Flanders Fields and Other Poems, 1919, by John McCrae In Flanders fields the poppies blow Between the crosses, row on row, That mark our place; and in the sky The larks, still bravely singing, fly Scarce heard amid the guns below. We are the Dead. Short days ago We lived, felt dawn, saw sunset glow, Loved and were loved, and now we lie In Flanders fields. Take up our quarrel with the foe: To you from failing hands we throw The torch; be yours to hold it high. If ye break faith with us who die We shall not sleep, though poppies grow In Flanders fields. fields.2 Vor Sortieren3 nach Sortieren4 ago: 15 amid: 16 and: 4

7 are: 18 be: 19 below.: 110 Between: 111 blow: 112 bravely: 1

13 break: 114 by: 115 crosses,: 116 dawn,: 117 days: 118 Dead.: 1

19 die: 120 failing: 121 faith: 122 felt: 123 Fields: 224 fields.: 3

Page 14: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

14 wortcntx.res, 26.4.2017 10:05:22

25 Flanders: 426 fly: 127 foe:: 128 from: 129 glow,: 130 grow: 131 guns: 132 hands: 133 heard: 134 high.: 135 hold: 136 http://en.wikipedia.org/wiki/In_Flanders_Fields_%28poem%29: 237 If: 138 In: 539 it: 140 John: 1

41 larks,: 142 lie: 143 lived,: 144 Loved: 145 loved,: 146 mark: 147 McCrae: 148 not: 149 now: 150 on: 151 Other: 152 our: 253 place;: 154 Poems,: 155 poppies: 256 quarrel: 1

57 row: 158 row,: 159 saw: 160 Scarce: 161 shall: 162 Short: 163 singing,: 164 sky: 165 sleep,: 166 still: 167 sunset: 168 Take: 169 That: 170 the: 871 though: 172 throw: 1

73 To: 274 torch;: 175 up: 176 us: 177 We: 578 were: 179 who: 180 with: 281 ye: 182 you: 183 yours: 184

85 Verschiedene Woerter: 8086 Gespeicherte Woerter: 10987 Eingelesene Woerter: 109

Datei 38: wortcntx.cpp, 29.6.2016 11:57:381 // progproc/referenc/wortcntx.cpp2 // Anzahl von Woertern in einem gegebenen Text3 // Benutzung der STL, insb. von string, iterator und map4

5 #include <iostream>6 #include <string>7 #include <map>8 #include <algorithm>9 #include <cstdlib>10

11 using namespace std;12

13 void Drucke ();14

15 int main ()16 { string wort;17 map < string, int > worte;18 int ctr = 0;19

20 while (cin.good())21 { cin >> wort;22 cout << " " << wort << " " << flush;23 if (cin.good() || cin.eof())24 {25 worte [wort] = worte [wort] + 1;26 ctr++;27 }28 }29 cout << "\n\nmap-Inhalt:\n" << flush;30 int ctr1 = 0;31 int ctr2 = 0;32 map < string, int > :: iterator i;33 for (i = worte.begin(); i != worte.end(); ++i)34 {35 cout << "\n" << (*i).first << " " << (*i).second;36 ctr1 += i->second;37 ctr2 ++;38 }39 cout << "\nEingelesene Woerter: " << ctr;40 cout << "\nEingelesene Woerter: " << ctr1;41 cout << "\nVerschiedene Woerter: " << ctr2;42 }43

Datei 39: wortcntx.res, 26.4.2017 10:05:22

1 http://en.wikipedia.org/wiki/In_Flanders_Fields_%28poem%29 In Flanders Fields and Other Poems, 1919, by John McCrae In Flanders fields the poppies blow Between the crosses, row on row, That mark our place; and in the sky The larks, still bravely singing, fly Scarce heard amid the guns below. We are the Dead. Short days ago We lived, felt dawn, saw sunset glow, Loved and were loved, and now we lie In Flanders fields. Take up our quarrel with the foe: To you from failing hands we throw The torch; be yours to hold it high. If ye break faith with us who die We shall not sleep, though poppies grow In Flanders fields. fields.2

3 map-Inhalt:4

5 1919, 16 Between 17 Dead. 18 Fields 19 Flanders 410 If 111 In 412 John 113 Loved 114 McCrae 115 Other 1

16 Poems, 117 Scarce 118 Short 119 Take 120 That 121 The 222 To 123 We 324 ago 125 amid 126 and 427 are 128 be 129 below. 130 blow 1

31 bravely 132 break 133 by 134 crosses, 135 dawn, 136 days 137 die 138 failing 139 faith 140 felt 141 fields 142 fields. 343 fly 144 foe: 145 from 1

46 glow, 147 grow 148 guns 149 hands 150 heard 151 high. 152 hold 153 http://en.wikipedia.org/wiki/In_Flanders_Fields_%28poem%29 154 in 155 it 156 larks, 157 lie 158 lived, 159 loved, 160 mark 1

Page 15: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

icstrng.hpp, 29.6.2016 11:57:38 15

61 not 162 now 163 on 164 our 265 place; 166 poppies 267 quarrel 168 row 169 row, 1

70 saw 171 shall 172 singing, 173 sky 174 sleep, 175 still 176 sunset 177 the 678 though 1

79 throw 180 to 181 torch; 182 up 183 us 184 we 285 were 186 who 187 with 2

88 ye 189 you 190 yours 191 Eingelesene Woerter: 10992 Eingelesene Woerter: 10993 Verschiedene Woerter: 86

Datei 40: icstrng.hpp, 29.6.2016 11:57:381 /*2 progproc/referenc/icstring.hpp3

4 The following code example is taken from the book5 The C++ Standard Library - A Tutorial and Reference6 by Nicolai M. Josuttis, Addison-Wesley, 19997 © Copyright Nicolai M. Josuttis 19998 */9

10 #ifndef ICSTRING_HPP11 #define ICSTRING_HPP12

13 #include <string>14 #include <iostream>15 #include <cctype>16

17 /* replace functions of the standard char_traits<char>18 * so that strings behave in a case-insensitive way19 */20 struct ignorecase_traits : public std::char_traits<char> {21 // return whether c1 and c2 are equal22 static bool eq(const char& c1, const char& c2) {23 return std::toupper(c1)==std::toupper(c2);24 }25 // return whether c1 is less than c226 static bool lt(const char& c1, const char& c2) {27 return std::toupper(c1)<std::toupper(c2);28 }29 // compare up to n characters of s1 and s230 static int compare(const char* s1, const char* s2,31 std::size_t n) {32 for (std::size_t i=0; i<n; ++i) {33 if (!eq(s1[i],s2[i])) {34 return lt(s1[i],s2[i])?-1:1;35 }36 }37 return 0;38 }39 // search c in s40 static const char* find(const char* s, std::size_t n,41 const char& c) {42 for (std::size_t i=0; i<n; ++i) {43 if (eq(s[i],c)) {44 return &(s[i]);45 }46 }47 return 0;48 }49 };50

51 // define a special type for such strings52 typedef std::basic_string<char,ignorecase_traits> icstring;53

54 /* define an output operator55 * because the traits type is different than that for std::ostream56 */57 inline58 std::ostream& operator << (std::ostream& strm, const icstring& s)59 {60 // simply convert the icstring into a normal string61 return strm << std::string(s.data(),s.length());62 }63

64 inline65 std::istream& operator >> (std::istream& strm, icstring& ics)66 {67 std::string s;

Page 16: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

16 icstrng.hpp, 29.6.2016 11:57:38

68 strm >> s;69 ics = icstring (s.data(),s.length());70 return strm;71 }72

73 #endif // ICSTRING_HPP74

Datei 41: icstrng.cpp, 29.6.2016 11:57:381 /*2 progproc/referenc/icstrng.cpp3

4 The following code example is taken from the book5 The C++ Standard Library - A Tutorial and Reference6 by Nicolai M. Josuttis, Addison-Wesley, 19997 © Copyright Nicolai M. Josuttis 19998 */9

10 #include "icstrng.hpp"11

12 int main()13 {14 using std::cout;15 using std::endl;16

17 icstring s1("hallo");18 icstring s2("otto");19 icstring s3("hALLo");20

21 cout << std::boolalpha;22 cout << s1 << " == " << s2 << " : " << (s1==s2) << endl;23 cout << s1 << " == " << s3 << " : " << (s1==s3) << endl;24

25 icstring::size_type idx = s1.find("All");26 if (idx != icstring::npos) {27 cout << "index of \"All\" in \"" << s1 << "\": "28 << idx << endl;29 }30

31 else {32 cout << "\"All\" not found in \"" << s1 << endl;33 }34 }35

Datei 42: icstrng.rs, 26.4.2017 10:05:221 hallo == otto : false2 hallo == hALLo : true3 index of "All" in "hallo": 14

Datei 43: destrng.cpp, 29.6.2016 11:57:381 // progproc/referenc/destrng.cpp2

3 #include <iostream>4

5 using namespace std;6

7 #include "destrng.hpp"8

9 int main()10 {11 using std::cout;12 using std::endl;13

14 destring s [100];15 int i, j, n;16 for (i = 0; i < 100 && (cin >> s [i]); i++)17 {18 cout << endl << s [i];19 }20 cout << endl;21 n = i;22 for (i = 0; i < n-1; i++)23 {24 for (j = i+1; j < n; j++)25 {26 if (s [i] > s [j])27 {

Page 17: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

destrng.hpp, 29.6.2016 11:57:38 17

28 destring h;29 h = s [i];30 s [i] = s [j];31 s [j] = h;32 }33 }34 }35 for (i = 0; i < n; i++)36 {37 cout << endl << s [i];38 }39 return 0;40 }41

Datei 44: destrng.hpp, 29.6.2016 11:57:381 // progproc/referenc/destring.hpp2

3 #ifndef _DESTRING_HPP4 #define _DESTRING_HPP5

6 #include <string>7 #include <iostream>8 #include <cctype>9

10 /* In den Standard char_traits<char>11 * werden Funktionen gezielt nach den deutschen Dudenregeln12 * ersetzt13 */14 struct de_traits: public std::char_traits<char>15 {16 static char tode (char c)17 { if (c == 'Ä') return 'a';18 if (c == 'Ö') return 'o';19 if (c == 'Ü') return 'u';20 if (c == 'ä') return 'a';21 if (c == 'ö') return 'o';22 if (c == 'ü') return 'u';23 return std :: tolower (c);24 }25

26 /*27 Die Anordnung der Stichwoerter ist alphabetisch. Die Umlaute ä, ö, ü, äu28 werden wie die nichtumgelauteten Selbstlaute a, o, u, au behandelt. Die29 Schreibungen ae, oe, ue werden nach ad usw. eingeordnet. Der Buchstabe ÿ30 wird wie ss eingeordnet. Bei gleichlautenden Wörtern steht das ÿ vor dem31 ss.32 */33

34 static bool eq(const char& c1, const char& c2)35 { return tode (c1) == tode (c2);36 }37

38 // return whether c1 is less than c239 static bool lt(const char& c1, const char& c2)40 { return tode (c1) < tode (c2);41 }42

43 // compare up to n characters of s1 and s244 static int compare(const char* s1, const char* s2, std::size_t n)45 { for (std::size_t i=0; i<n; ++i)46 { if (!eq(s1[i],s2[i]))47 { return lt(s1[i],s2[i])?-1:1;48 } }49 return 0;50 }51 };52

53 // Definition eines Spezialtyps fuer deutsche Strings54 typedef std::basic_string<char,de_traits> destring;55

56 /* Definition des output operators (output inserters)57 * da globale Funktionen nicht mit der Klasse generiert werden.58 */59 inline60 std::ostream& operator << (std::ostream& strm, const destring& s)61 { // Konversion des destrings mit member-Funktionen in einen string62 return strm << std::string(s.data(),s.length());

Page 18: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

18 destrng.hpp, 29.6.2016 11:57:38

63 }64

65 /* Definition des input operators (input extractors)66 */67 inline68 std::istream& operator >> (std::istream& strm, destring& des)69 { std::string s;70 strm >> s;71 des = destring (s.data(),s.length());72 return strm;73 }74

75 #endif // _DESTRING_HPP76

Datei 45: destrng.rs, 26.4.2017 10:05:241

2 Ein3 paar4 Worte5 in6 zwei7 Zeilen8

9 Ein10 in11 paar12 Worte13 Zeilen14 zwei

Datei 46: sort1.cpp, 29.6.2016 11:57:381 // progproc/referenc/sort1.cpp2

3 #include <algorithm>4 #include <functional>5 #include <vector>6 #include <string>7 #include <iostream>8 #include <sstream>9

10 using namespace std;11

12 void pr (string s)13 {14 cout << s << ' ';15 }16

17 bool le (string s1, string s2)18 {19 return s1 < s2;20 }21

22 int main ()23 {24 vector<string> l;25 int i;26

27 for (i = 0; i < 15; i++)28 {29 ostringstream os;30 os << i;31 l.push_back (os.str());32 }33 for_each (l.begin (), l.end (), pr); cout << endl;34 stable_sort (l.begin (), l.end (), le);35 for_each (l.begin (), l.end (), pr); cout << endl;36 sort (l.begin (), l.end ());37 for_each (l.begin (), l.end (), pr); cout << endl;38 }39

Datei 47: sort1.res, 26.4.2017 10:05:241 0 1 2 3 4 5 6 7 8 9 10 11 12 13 142 0 1 10 11 12 13 14 2 3 4 5 6 7 8 93 0 1 10 11 12 13 14 2 3 4 5 6 7 8 94

Datei 48: unique.cpp, 29.6.2016 11:57:381 /*

Page 19: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

vor.cpp, 29.6.2016 11:57:38 19

2 progproc/referenc/unique.cpp3

4 The following code example is taken from the book5 The C++ Standard Library - A Tutorial and Reference6 by Nicolai M. Josuttis, Addison-Wesley, 19997 © Copyright Nicolai M. Josuttis 19998 */9

10 #include <iostream>11 #include <string>12 #include <algorithm>13 #include <locale>14 #include <iterator>15

16 using namespace std;17

18 class bothWhiteSpaces {19 private:20 const locale& loc; // locale21 public:22 /* constructor23 * - save the locale object24 */25 bothWhiteSpaces (const locale& l) : loc(l) {26 }27 /* function call28 * - returns whether both characters are whitespaces29 */30 bool operator() (char elem1, char elem2) {31 return isspace(elem1,loc) && isspace(elem2,loc);32 }33 };34

35 int main()36 {37 string contents;38

39 // don't skip leading whitespaces40 cin.unsetf (ios::skipws);41

42 // read all characters while compressing whitespaces43 unique_copy(istream_iterator<char>(cin), // beginning of source44 istream_iterator<char>(), // end of source45 back_inserter(contents), // destination46 bothWhiteSpaces(cin.getloc())); // criterion for removing47

48 // process contents49 // - here: write it to the standard output50 cout << contents;51 }52

Datei 49: unique.rs, 26.4.2017 10:05:261 Zwei Zeilen2 mit Text

Datei 50: vor.cpp, 29.6.2016 11:57:381 // progproc/referenc/vor.cpp2

3 #include <iostream>4 #include <string>5 #include <vector>6 #include <algorithm>7 #include <cstdlib>8

9 using namespace std;10

11 struct Eintrag12 { string w;13 int a;14 friend ostream & operator << (ostream & s, Eintrag b);15 };16

17 #include "vor.h"18

19 int main ()20 { Eintrag w1, w2;21 for (;;)22 { if (!cin.good()) return 0;

Page 20: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

20 vor.cpp, 29.6.2016 11:57:38

23 cin >> w1.w;24 cin >> w2.w;25 cout << endl << w1.w << " und " << w2.w << evor (w1, w2) << " " << evor (w2, w1);26 }27 }28

Datei 51: vor.h, 29.6.2016 11:57:381 // progproc/referenc/vor.h2

3 bool svor (const string & s1, const string & s2)4 {5 /**/6 unsigned int i1, i2;7 for (i1 = 0, i2 = 0; i1 < s1.length() && i2 < s2.length(); i1++, i2++)8 { while (i1 < s1.length() && !isalpha (s1 [i1])) i1++;9 while (i2 < s2.length() && !isalpha (s2 [i2])) i2++;10 if (i1 < s1.length() && i2 < s2.length())11 { char c1, c2;12 c1 = tolower (s1 [i1]);13 c2 = tolower (s2 [i2]);14 if (c1 != c2)15 return c1 < c2;16 } }17 return i1 == s1.length() && i2 < s2.length();18 /* */19 /*20 string :: const_iterator i1, i2;21 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end(); i1++, i2++)22 { while (i1 != s1.end() && !isalpha (*i1)) i1++;23 while (i2 != s2.end() && !isalpha (*i2)) i2++;24 if (i1 != s1.end() && i2 != s2.end())25 { char c1, c2;26 c1 = tolower (*i1);27 c2 = tolower (*i2);28 if (c1 != c2)29 return c1 < c2;30 } }31 return i1 == s1.end() && i2 != s2.end() ;32 */33 }34

35 bool evor (const Eintrag & s1, const Eintrag & s2)36 { return svor (s1.w, s2.w);37 }38

Datei 52: vor.rs, 26.4.2017 10:05:241

2 Balken und Balkon1 03 Balkon und Balken0 14 Balkon und Balkonpflanze1 05 Balkon und Balkon0 06 Balkon und Balkon0 0

Datei 53: cpp3.a2t, 29.6.2016 11:57:341 /r procprog\referenc\files1.a2t2

Datei 54: vector.cpp, 29.6.2016 11:57:501 // stl\vector\vector.cpp2 // beispiel fuer Container, Iteratoren und Algorithmen3

4 #include <cmath>5 #include <iostream>6 #include <vector>7 #include <iterator>8 #include <algorithm>9 #include <functional>10

11 using namespace std;12

13 void raus (int i, bool first = false, bool print = false)14 { static int last = 0;15 static int nmbr = 0;16 if (print) { cout << endl << "Anzahl: " << nmbr << endl; return; }17 if (first) { last = 3141592; nmbr = 0; return; }18 if (last != i) cout << " " << i;19 last = i;

Page 21: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

cpp3a.a2t, 29.6.2016 11:57:34 21

20 nmbr++;21 }22

23 void rausf (int i)24 {25 raus (i, false, false);26 }27

28 class inc29 { public:30 inc (int i = 1) : v(i) {}31 void operator () (int & x) { x += v; }32 private:33 int v;34 };35

36 int main ()37 { vector<int> v;38 int i;39

40 cout << endl << "Erzeugen (capacity/size)" << endl;41 for (i = 0; i < 100; i++)42 { int k;43 v.insert (v.end (), k=(int) (sin ((double)i) * 150));44 cout << " " << v.capacity() << "/" << v.size() << "(" << k << ")";45 }46

47 cout << endl << "Inhalt des Vectors" << endl;48 raus (0, true);49 for_each (v.begin (), v.end (), rausf);50 raus (0, false, true);51

52 cout << endl << "Sortieren" << endl;53 sort (v.begin (), v.end ());54

55 cout << endl << "Inhalt des Vectors" << endl;56 raus (0, true);57 for_each (v.begin (), v.end (), rausf);58 raus (0, false, true);59

60 cout << endl << "um 2 erhoehen" << endl;61 for_each (v.begin (), v.end (), inc (2));62

63 cout << endl << "Inhalt des Vectors" << endl;64 raus (0, true);65 for_each (v.begin (), v.end (), rausf);66 raus (0, false, true);67

68 cout << endl << "Inhalt des Vectors (mit copy statt mit raus)" << endl;69 copy (v.begin (), v.end (), ostream_iterator<int>(cout, " / "));70 }71

Datei 55: vector.res, 26.4.2017 10:05:361

2 Erzeugen (capacity/size)3 1/1(0) 2/2(126) 4/3(136) 4/4(21) 8/5(-113) 8/6(-143) 8/7(-41) 8/8(98) 16/9(148) 16/10(61) 16/11(-81) 16/12(-149) 16/13(-80) 16/14(63) 16/15(148) 16/16(97) 32/17(-43) 32/18(-144) 32/19(-112) 32/20(22) 32/21(136) 32/22(125) 32/23(-1) 32/24(-126) 32/25(-135) 32/26(-19) 32/27(114) 32/28(143) 32/29(40) 32/30(-99) 32/31(-148) 32/32(-60) 64/33(82) 64/34(149) 64/35(79) 64/36(-64) 64/37(-148) 64/38(-96) 64/39(44) 64/40(144) 64/41(111) 64/42(-23) 64/43(-137) 64/44(-124) 64/45(2) 64/46(127) 64/47(135) 64/48(18) 64/49(-115) 64/50(-143) 64/51(-39) 64/52(100) 64/53(147) 64/54(59) 64/55(-83) 64/56(-149) 64/57(-78) 64/58(65) 64/59(148) 64/60(95) 64/61(-45) 64/62(-144) 64/63(-110) 64/64(25) 128/65(138) 128/66(124) 128/67(-3) 128/68(-128) 128/69(-134) 128/70(-17) 128/71(116) 128/72(142) 128/73(38) 128/74(-101) 128/75(-147) 128/76(-58) 128/77(84) 128/78(149) 128/79(77) 128/80(-66) 128/81(-149) 128/82(-94) 128/83(46) 128/84(145) 128/85(109) 128/86(-26) 128/87(-138) 128/88(-123) 128/89(5) 128/90(129) 128/91(134) 128/92(15) 128/93(-116) 128/94(-142) 128/95(-36) 128/96(102) 128/97(147) 128/98(56) 128/99(-86) 128/100(-149)4 Inhalt des Vectors5 0 126 136 21 -113 -143 -41 98 148 61 -81 -149 -80 63 148 97 -43 -144 -112 22 136 125 -1 -126 -135 -19 114 143 40 -99 -148 -60 82 149 79 -64 -148 -96 44 144 111 -23 -137 -124 2 127 135 18 -115 -143 -39 100 147 59 -83 -149 -78 65 148 95 -45 -144 -110 25 138 124 -3 -128 -134 -17 116 142 38 -101 -147 -58 84 149 77 -66 -149 -94 46 145 109 -26 -138 -123 5 129 134 15 -116 -142 -36 102 147 56 -86 -1496 Anzahl: 1007

8 Sortieren9

10 Inhalt des Vectors11 -149 -148 -147 -144 -143 -142 -138 -137 -135 -134 -128 -126 -124 -123 -116 -115 -113 -112 -110 -101 -99 -96 -94 -86 -83 -81 -80 -78 -66 -64 -60 -58 -45 -43 -41 -39 -36 -26 -23 -19 -17 -3 -1 0 2 5 15 18 21 22 25 38 40 44 46 56 59 61 63 65 77 79 82 84 95 97 98 100 102 109 111 114 116 124 125 126 127 129 134 135 136 138 142 143 144 145 147 148 14912 Anzahl: 10013

14 um 2 erhoehen15

16 Inhalt des Vectors17 -147 -146 -145 -142 -141 -140 -136 -135 -133 -132 -126 -124 -122 -121 -114 -113 -111 -110 -108 -99 -97 -94 -92 -84 -81 -79 -78 -76 -64 -62 -58 -56 -43 -41 -39 -37 -34 -24 -21 -17 -15 -1 1 2 4 7 17 20 23 24 27 40 42 46 48 58 61 63 65 67 79 81 84 86 97 99 100 102 104 111 113 116 118 126 127 128 129 131 136 137 138 140 144 145 146 147 149 150 15118 Anzahl: 10019

20 Inhalt des Vectors (mit copy statt mit raus)21 -147 / -147 / -147 / -147 / -146 / -146 / -145 / -142 / -142 / -141 / -141 / -140 / -136 / -135 / -133 / -132 / -126 / -124 / -122 / -121 / -114 / -113 / -111 / -110 / -108 / -99 / -97 / -94 / -92 / -84 / -81 / -79 / -78 / -76 / -64 / -62 / -58 / -56 / -43 / -41 / -39 / -37 / -34 / -24 / -21 / -17 / -15 / -1 / 1 / 2 / 4 / 7 / 17 / 20 / 23 / 24 / 27 / 40 / 42 / 46 / 48 / 58 / 61 / 63 / 65 / 67 / 79 / 81 / 84 / 86 / 97 / 99 / 100 / 102 / 104 / 111 / 113 / 116 / 118 / 126 / 127 / 128 / 129 / 131 / 136 / 137 / 138 / 138 / 140 / 144 / 145 / 146 / 147 / 149 / 149 / 150 / 150 / 150 / 151 / 151 /

Datei 56: cpp3a.a2t, 29.6.2016 11:57:341 stl\vector\vector.cpp2 stl\vector\vector.res

Page 22: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

22 cpp3a.a2t, 29.6.2016 11:57:34

3

Datei 57: SCHNITT.C, 29.6.2016 11:58:021 /* ./ooprog/geom/SCHNITT.C; Schnitt zweier Geraden in C (komplett in einer Datei) */2

3 #include <stdio.h>4 #include <math.h>5

6 double sqr (double x)7 { return x * x;8 }9

10 double det (double a, double b, double c, double d)11 { return a * d - b * c;12 }13

14 typedef struct vek { double x, y; } Vektor, *pVektor;15

16 double Norm (Vektor x)17 { return sqrt (sqr (x.x) + sqr (x.y));18 }19

20 Vektor sum (Vektor a, Vektor b)21 { Vektor s;22 s.x = a.x + b.x;23 s.y = a.y + b.y;24 return s;25 }26

27 Vektor diff (Vektor a, Vektor b)28 { Vektor d;29 d.x = a.x - b.x;30 d.y = a.y - b.y;31 return d;32 }33

34 Vektor skal_mult (double k, Vektor a)35 { Vektor r;36 r.x = k * a.x;37 r.y = k * a.y;38 return r;39 }40

41 Vektor solve (Vektor a1, Vektor a2, Vektor b)42 { Vektor h;43 double d;44 d = det (a1.x, a2.x, a1.y, a2.y);45 h.x = det (b.x, a2.x, b.y, a2.y) / d;46 h.y = det (a1.x, b.x, a1.y, b.y) / d;47 return h;48 }49

50 typedef struct ger { Vektor p1, p2; } Gerade, *pGerade;51

52 double StreckenLaenge (Gerade g)53 { Vektor h;54 h = diff (g.p1, g.p2);55 return Norm (h);56 }57

58 Vektor Schnitt (Gerade g1, Gerade g2)59

60 /* Schnittpunkt x = g1.p1 + l * (g1.p2-g1.p1) = g2.p1 - m * (g2.p1-g2.p2) */61 /* = g1.p1 + l * r1 = g2.p1 - m * r2 */62 /* l * r1 + m * r2 = g2.p1 - g1.p1 = h --solve-> l, m -> x = g1.p1 + l * r1 */63

64 { Vektor r1, r2, h, x, s;65

66 r1 = diff (g1.p2, g1.p1);67 r2 = diff (g2.p1, g2.p2);68 h = diff (g2.p1, g1.p1);69

70 x = solve (r1, r2, h);71

72 h = skal_mult (x.x, r1); /* x.x = l; x.y = m */73 return sum (g1.p1, h);74 }75

76 void fprVektor (FILE * f, Vektor x)

Page 23: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

VEKTOR.C, 29.6.2016 11:58:02 23

77 { fprintf (f, "[%f/%f]", x.x, x.y);78 }79

80 void fprGerade (FILE * f, Gerade g)81 { fprintf (f, "x = (1-lambda) * ");82 fprVektor (f, g.p1);83 fprintf (f, " + lambda * ");84 fprVektor (f, g.p2);85 }86

87 int main (void)88 { Gerade g, h;89 Vektor s;90

91 g.p1.x = 2; g.p1.y = 4;92 g.p2.x = 5; g.p2.y = 6;93 h.p1.x = 7; h.p1.y = 5;94 h.p2.x = 6; h.p2.y = 9;95 printf ("\ng: "); fprGerade (stdout, g);96 printf ("\n Streckenlaenge von g = %f", StreckenLaenge (g));97 printf ("\nh: "); fprGerade (stdout, h);98 printf ("\n Streckenlaenge von h = %f", StreckenLaenge (h));99

100 s = Schnitt (g, h);101 printf ("\nSchnittpunkt:"); fprVektor (stdout, s);102

103 return 0;104 }105

Datei 58: SCHNITT.RES, 26.4.2017 10:05:261

2 g: x = (1-lambda) * [2.000000/4.000000] + lambda * [5.000000/6.000000]3 Streckenlaenge von g = 3.6055514 h: x = (1-lambda) * [7.000000/5.000000] + lambda * [6.000000/9.000000]5 Streckenlaenge von h = 4.1231066 Schnittpunkt:[6.500000/7.000000]

Datei 59: MATH1.H, 29.6.2016 11:58:021 #ifndef __MATH1_H2 #define __MATH1_H3

4 double sqr (double x);5 double det (double a, double b, double c, double d);6

7 #endif8

Datei 60: MATH1.C, 29.6.2016 11:58:021 /* ./ooprog/geom/MATH1.C; C-Code: math.h-Erweiterung aus SCHNITT.C */2

3 /* Unterschied zu math1a.c: Reines ANSII-C auch in der Headerdatei */4

5 #include "math1.h"6

7 double sqr (double x)8 { return x * x;9 }10

11 double det (double a, double b, double c, double d)12 { return a * d - b * c;13 }14

Datei 61: VEKTOR.H, 29.6.2016 11:58:021 #ifndef __VEKTOR_H2 #define __VEKTOR_H3

4 typedef struct vek { double x, y; } Vektor, *pVektor;5

6 double Norm (Vektor x);7 Vektor sum (Vektor a, Vektor b);8 Vektor diff (Vektor a, Vektor b);9 Vektor skal_mult (double k, Vektor a);10 Vektor solve (Vektor a1, Vektor a2, Vektor b);11

12 #endif13

Datei 62: VEKTOR.C, 29.6.2016 11:58:02

Page 24: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

24 VEKTOR.C, 29.6.2016 11:58:02

1 /* ./ooprog/geom/GERADE.C; C-Code fuer Punkte und Vektoren */2

3 #include <math.h>4 #include "vektor.h"5 #include "math1.h"6

7 double Norm (Vektor x)8

9 { return sqrt (sqr (x.x) + sqr (x.y));10 }11

12 Vektor sum (Vektor a, Vektor b)13

14 { Vektor s;15 s.x = a.x + b.x;16 s.y = a.y + b.y;17 return s;18 }19

20 Vektor diff (Vektor a, Vektor b)21

22 { Vektor d;23 d.x = a.x - b.x;24 d.y = a.y - b.y;25 return d;26 }27

28 Vektor skal_mult (double k, Vektor a)29

30 { Vektor r;31 r.x = k * a.x;32 r.y = k * a.y;33 return r;34 }35

36 Vektor solve (Vektor a1, Vektor a2, Vektor b)37

38 { Vektor h;39 double d;40 d = det (a1.x, a2.x, a1.y, a2.y);41 h.x = det (b.x, a2.x, b.y, a2.y) / d;42 h.y = det (a1.x, b.x, a1.y, b.y) / d;43 return h;44 }45

Datei 63: GERADE.H, 29.6.2016 11:58:021 #ifndef __GERADE_H2 #define __GERADE_H3

4 #include "vektor.h"5

6 typedef struct ger { Vektor p1, p2; } Gerade, *pGerade;7

8 double StreckenLaenge (Gerade g);9 Vektor Schnitt (Gerade g1, Gerade g2);10

11 #endif12

Datei 64: GERADE.C, 29.6.2016 11:58:021 /* ./ooprog/geom/GERADE.C; C-Code fuer Geraden */2

3 #include "gerade.h"4

5 double StreckenLaenge (Gerade g)6 { Vektor h;7 h = diff (g.p1, g.p2);8 return Norm (h);9 }10

11 Vektor Schnitt (Gerade g1, Gerade g2)12

13 /* Schnittpunkt x = g1.p1 + l * (g1.p2-g1.p1) = g2.p1 - m * (g2.p1-g2.p2) */14 /* = g1.p1 + l * r1 = g2.p1 - m * r2 */15 /* l * r1 + m * r2 = g2.p1 - g1.p1 = h --solve-> l, m -> x = g1.p1 + l * r1 */16

17 { Vektor r1, r2, h, x, s;18

Page 25: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

SCHNITTA.C, 29.6.2016 11:58:02 25

19 r1 = diff (g1.p2, g1.p1);20 r2 = diff (g2.p1, g2.p2);21 h = diff (g2.p1, g1.p1);22

23 x = solve (r1, r2, h);24

25 h = skal_mult (x.x, r1); /* x.x = l; x.y = m */26 return sum (g1.p1, h);27 }28

Datei 65: PUNKT.C, 29.6.2016 11:58:021 /* ./ooprog/geom/PUNKT.C; C-Code fuer Punkte und Vektoren aus SCHNITT.C */2

3 #include <stdio.h>4 #include "gerade.h"5

6 void fprVektor (FILE * f, Vektor x)7 { fprintf (f, "[%f/%f]", x.x, x.y);8 }9

10 void fprGerade (FILE * f, Gerade g)11 { fprintf (f, "x = (1-lambda) * ");12 fprVektor (f, g.p1);13 fprintf (f, " + lambda * ");14 fprVektor (f, g.p2);15 }16

17 int main (void)18 { Gerade g, h = { {7, 5}, {6, 9} };19 Vektor s;20

21 g.p1.x = 2; g.p1.y = 4;22 g.p2.x = 5; g.p2.y = 6;23 printf ("\ng: "); fprGerade (stdout, g);24 printf ("\n Streckenlaenge von g = %f", StreckenLaenge (g));25 printf ("\nh: "); fprGerade (stdout, h);26 printf ("\n Streckenlaenge von h = %f", StreckenLaenge (h));27

28 s = Schnitt (g, h);29 printf ("\nSchnittpunkt:"); fprVektor (stdout, s);30

31 return 0;32 }33

Datei 66: PUNKT.RES, 26.4.2017 10:05:261

2 g: x = (1-lambda) * [2.000000/4.000000] + lambda * [5.000000/6.000000]3 Streckenlaenge von g = 3.6055514 h: x = (1-lambda) * [7.000000/5.000000] + lambda * [6.000000/9.000000]5 Streckenlaenge von h = 4.1231066 Schnittpunkt:[6.500000/7.000000]

Datei 67: SCHNITTA.C, 29.6.2016 11:58:021 /* ./ooprog/geom/SCHNITTA.C; Schnitt zweier Geraden in C */2 /* (ausser dem C++tauglichen MATH1A komplett in einer Datei) */3

4 #include <stdio.h>5 #include <math.h>6 #include "math1a.h"7

8 typedef struct vek { double x, y; } Vektor, *pVektor;9

10 double Norm (Vektor x)11 { return sqrt (sqr (x.x) + sqr (x.y));12 }13

14 Vektor sum (Vektor a, Vektor b)15 { Vektor s;16 s.x = a.x + b.x;17 s.y = a.y + b.y;18 return s;19 }20

21 Vektor diff (Vektor a, Vektor b)22 { Vektor d;23 d.x = a.x - b.x;24 d.y = a.y - b.y;

Page 26: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

26 SCHNITTA.C, 29.6.2016 11:58:02

25 return d;26 }27

28 Vektor skal_mult (double k, Vektor a)29 { Vektor r;30 r.x = k * a.x;31 r.y = k * a.y;32 return r;33 }34

35 Vektor solve (Vektor a1, Vektor a2, Vektor b)36 { Vektor h;37 double d;38 d = det (a1.x, a2.x, a1.y, a2.y);39 h.x = det (b.x, a2.x, b.y, a2.y) / d;40 h.y = det (a1.x, b.x, a1.y, b.y) / d;41 return h;42 }43

44 typedef struct ger { Vektor p1, p2; } Gerade, *pGerade;45

46 double StreckenLaenge (Gerade g)47 { Vektor h;48 h = diff (g.p1, g.p2);49 return Norm (h);50 }51

52 Vektor Schnitt (Gerade g1, Gerade g2)53

54 /* Schnittpunkt x = g1.p1 + l * (g1.p2-g1.p1) = g2.p1 - m * (g2.p1-g2.p2) */55 /* = g1.p1 + l * r1 = g2.p1 - m * r2 */56 /* l * r1 + m * r2 = g2.p1 - g1.p1 = h --solve-> l, m -> x = g1.p1 + l * r1 */57

58 { Vektor r1, r2, h, x;59

60 r1 = diff (g1.p2, g1.p1);61 r2 = diff (g2.p1, g2.p2);62 h = diff (g2.p1, g1.p1);63

64 x = solve (r1, r2, h);65

66 h = skal_mult (x.x, r1); /* x.x = l; x.y = m */67 return sum (g1.p1, h);68 }69

70 void fprVektor (FILE * f, Vektor x)71 { fprintf (f, "[%f/%f]", x.x, x.y);72 }73

74 void fprGerade (FILE * f, Gerade g)75 { fprintf (f, "x = (1-lambda) * ");76 fprVektor (f, g.p1);77 fprintf (f, " + lambda * ");78 fprVektor (f, g.p2);79 }80

81 int main (void)82 { Gerade g, h;83 Vektor s;84

85 g.p1.x = 2; g.p1.y = 4;86 g.p2.x = 5; g.p2.y = 6;87 h.p1.x = 7; h.p1.y = 5;88 h.p2.x = 6; h.p2.y = 9;89 printf ("\ng: "); fprGerade (stdout, g);90 printf ("\n Streckenlaenge von g = %f", StreckenLaenge (g));91 printf ("\nh: "); fprGerade (stdout, h);92 printf ("\n Streckenlaenge von h = %f", StreckenLaenge (h));93

94 s = Schnitt (g, h);95 printf ("\nSchnittpunkt:"); fprVektor (stdout, s);96

97 return 0;98 }99

Datei 68: SCHNITTA.RES, 26.4.2017 10:05:261

Page 27: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

SCHNITT1.CPP, 29.6.2016 11:58:02 27

2 g: x = (1-lambda) * [2.000000/4.000000] + lambda * [5.000000/6.000000]3 Streckenlaenge von g = 3.6055514 h: x = (1-lambda) * [7.000000/5.000000] + lambda * [6.000000/9.000000]5 Streckenlaenge von h = 4.1231066 Schnittpunkt:[6.500000/7.000000]

Datei 69: MATH1A.H, 29.6.2016 11:58:021 #ifndef __MATH1A_H2 #define __MATH1A_H3

4 #ifdef __cplusplus5 extern "C" {6 #endif7

8 double sqr (double x);9 double det (double a, double b, double c, double d);10

11 #ifdef __cplusplus12 }13 #endif14

15 #endif16

Datei 70: MATH1A.C, 29.6.2016 11:58:021 /* ./ooprog/geom/MATH1A.C; C-Code, C++ tauglich: math.h-Erweiterung aus SCHNITT.C */2

3 /* Unterschied zu math1.c: Die Headerdatei beruecksichtig C++ */4

5 #include "math1a.h"6

7 double sqr (double x)8 { return x * x;9 }10

11 double det (double a, double b, double c, double d)12 { return a * d - b * c;13 }14

Datei 71: SCHNITT1.CPP, 29.6.2016 11:58:021 /* ./ooprog/geom/SCHNITT1.CPP; Schnitt zweier Geraden in C++ */2

3 // Uebersetzung der C-Version nach C++4

5 #include <iostream>6 #include <cmath>7

8 using namespace std;9

10 double sqr (double x)11 { return x * x;12 }13

14 double det (double a, double b, double c, double d)15 { return a * d - b * c;16 }17

18 struct Vektor19 { double x, y;20

21 double Norm () { return sqrt (sqr (x) + sqr (y)); }22 void normiere () { double n; n = Norm (); x /= n; y /= n; }23 Vektor plus (Vektor b);24 Vektor minus (Vektor b);25 Vektor times (double k);26 double dot (Vektor b) { return x * b.x + y * b.y; }27 };28

29 Vektor Vektor :: plus (Vektor b)30 { Vektor s;31 s.x = x + b.x;32 s.y = y + b.y;33 return s;34 }35

36 Vektor Vektor :: minus (Vektor b)37 { Vektor d;38 d.x = x - b.x;

Page 28: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

28 SCHNITT1.CPP, 29.6.2016 11:58:02

39 d.y = y - b.y;40 return d;41 }42

43 Vektor Vektor :: times (double k)44 { Vektor r;45 r.x = k * x;46 r.y = k * y;47 return r;48 }49

50 Vektor solve (Vektor a1, Vektor a2, Vektor b)51 { Vektor h;52 double d;53 d = det (a1.x, a2.x, a1.y, a2.y);54 h.x = det (b.x, a2.x, b.y, a2.y) / d;55 h.y = det (a1.x, b.x, a1.y, b.y) / d;56 return h;57 }58

59 struct Gerade60 { Vektor p1, p2;61 double StreckenLaenge () { Vektor h; h = p1.minus (p2); return h.Norm (); }62 Vektor Schnitt (Gerade h);63 };64

65 Vektor Gerade :: Schnitt (Gerade g)66

67 /* Schnittpunkt x = p1 + l * (p2-p1) = g.p1 - m * (g.p1-g.p2) */68 /* = p1 + l * r1 = g.p1 - m * r2 */69 /* l * r1 + m * r2 = g.p1 - p1 = h --solve-> l, m -> x = p1 + l * r1 */70

71 { Vektor r1, r2, h, x;72

73 r1 = p2.minus (p1);74 r2 = g.p1.minus (g.p2);75 h = g.p1.minus (p1);76

77 x = solve (r1, r2, h);78

79 h = r1.times (x.x); /* x.x = l; x.y = m */80 return p1.plus (h);81 }82

83 void prVektor (Vektor x)84 { cout << "[" << x.x << "/" << x.y << "]";85 }86

87 void prGerade (Gerade g)88 { cout << "x = (1-lambda) * ";89 prVektor (g.p1);90 cout << " + lambda * ";91 prVektor (g.p2);92 }93

94 int main ()95 { Gerade g, h;96 Vektor s;97

98 g.p1.x = 2; g.p1.y = 4;99 g.p2.x = 5; g.p2.y = 6;100 h.p1.x = 7; h.p1.y = 5;101 h.p2.x = 6; h.p2.y = 9;102 cout << "\ng: "; prGerade (g);103 cout << "\n Streckenlaenge von g = " << g.StreckenLaenge ();104 cout << "\nh: "; prGerade (h);105 cout << "\n Streckenlaenge von h = " << h.StreckenLaenge ();106

107 s = g.Schnitt (h);108 cout << "\nSchnittpunkt:"; prVektor (s);109

110 return 0;111 }112

Datei 72: SCHNITT1.RES, 26.4.2017 10:05:281

2 g: x = (1-lambda) * [2/4] + lambda * [5/6]3 Streckenlaenge von g = 3.60555

Page 29: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

SCHNITT2.CPP, 29.6.2016 11:58:02 29

4 h: x = (1-lambda) * [7/5] + lambda * [6/9]5 Streckenlaenge von h = 4.123116 Schnittpunkt:[6.5/7]

Datei 73: SCHNITT2.CPP, 29.6.2016 11:58:021 /* ./ooprog/geom/SCHNITT2.CPP; Schnitt zweier Geraden in C++ */2

3 // Verwendung der C-Datei math1a.h und math1a.c4 // Operator-Funktionen5

6 // Uebersetzung mit gnu c/c++: gpp -o schnitt2 schnitt2.cpp math1a.c7

8 #include <iostream>9 #include <cmath>10 #include "math1a.h"11

12 using namespace std;13

14 class Vektor15 {16 public:17

18 // Konstruktoren und Destruktoren19 Vektor (const double a = 0, const double b = 0) : x (a), y (b) { }20 // defaults problematisch wegen int-Konversionen!21 Vektor (const Vektor & a) : x (a.x), y (a.y) { }22

23 // Zugriffsoperationen24 double xKoor () const { return x; }25 double yKoor () const { return y; }26

27 // Operator-Funktionen (sinnlos sind ++ --)28 Vektor operator += (const Vektor b) { x += b.x; y += b.y; return *this; }29 Vektor operator -= (const Vektor b) { x -= b.x; y -= b.y; return *this; }30 Vektor operator *= (const double b) { x *= b; y *= b; return *this; }31 double operator * (const Vektor b) const32 { double h; h = x * b.x + y * b.y; return h; }33 // Andere member-Funktionen34 double Norm () const { return sqrt (sqr (x) + sqr (y)); }35 void normiere () { double n; n = Norm (); x /= n; y /= n; }36 bool kollinear (const Vektor b) const37 { return x * b.y == y * b.x; }38 // friend-Funktionen39 friend Vektor solve (Vektor a1, Vektor a2, Vektor b);40 friend ostream & operator << (ostream &, const Vektor);41

42 private:43 double x, y;44 };45

46 // Operatoren ohne Zugriff auf private member47

48 inline Vektor operator + (const Vektor a, const Vektor b) { Vektor h (a); h += b; return h; }49 inline Vektor operator - (const Vektor a, const Vektor b) { Vektor h (a); h -= b; return h; }50 inline Vektor operator * (const Vektor a, const double b) { Vektor h (a); h *= b; return h; }51 inline Vektor operator * (const double b, const Vektor a) { Vektor h (a); h *= b; return h; }52

53 // Funktionen ohne Zugriff auf private member54

55 Vektor solve (Vektor a1, Vektor a2, Vektor b)56 { Vektor h;57 double d;58 d = det (a1.x, a2.x, a1.y, a2.y);59 h.x = det (b.x, a2.x, b.y, a2.y) / d;60 h.y = det (a1.x, b.x, a1.y, b.y) / d;61 return h;62 }63

64 // Friend Operatoren65

66 ostream & operator << (ostream & s, const Vektor b)67 { ostream::sentry se(s);68 if (se)69 { s << b.x << " " << b.y;70 }71 /****************************** so war das vor dem C++ Standard72 if (s.opfx ())73 { s << b.x << " " << b.y;

Page 30: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

30 SCHNITT2.CPP, 29.6.2016 11:58:02

74 s.osfx ();75 }76 ******************************/77 return s;78 }79

80 class Gerade81 {82 public:83 // Konstruktoren und Destruktoren:84 Gerade (const double a = 0, const double b = 0, const double c = 1, const double d = 0)85 : p1 (a, b), p2 (c, d) { }86 // Operator-Funktionen87 bool operator || (const Gerade) const;88 Vektor operator * (const Gerade) const;89

90 // Andere member-Funktionen91 double StreckenLaenge () const { Vektor h (p1); h -= p2; return h.Norm (); }92 Vektor Schnitt (const Gerade) const;93

94 // friend-Funktionen95 friend ostream & operator << (ostream &, const Gerade);96

97 private:98

99 Vektor p1, p2;100 };101

102 Vektor Gerade :: Schnitt (const Gerade g) const103

104 /* Schnittpunkt x = p1 + l * (p2-p1) = g.p1 - m * (g.p1-g.p2) */105 /* = p1 + l * r1 = g.p1 - m * r2 */106 /* l * r1 + m * r2 = g.p1 - p1 = h --solve-> l, m -> x = p1 + l * r1 */107

108 { Vektor r1, r2, h, x;109

110 r1 = p2 - p1;111 r2 = g.p1 - g.p2;112 h = g.p1 - p1;113

114 x = solve (r1, r2, h);115

116 h = r1 * x.xKoor (); /* x.x = l(ambda); x.y = m(ue) */117 return p1 + h;118 }119

120 Vektor Gerade :: operator * (const Gerade g) const121 {122 return this->Schnitt (g);123 }124

125 bool Gerade :: operator || (const Gerade h) const126 {127 Vektor r, s;128 r = this->p1 - this->p2;129 s = h.p1 - h.p2;130 return r.kollinear(s);131 }132

133 ostream & operator << (ostream & s, const Gerade g)134 {135 ostream::sentry se(s);136 if (se)137 { s << "x = (1-lambda) * " << g.p1 << " + lambda * " << g.p2;138 }139 return s;140 }141

142 int main (void)143 { Gerade g (2, 4, 5, 6), h (7, 5, 6, 9);144 Vektor s;145

146 cout << "\ng: " << g;147 cout << "\n Streckenlaenge von g = " << g.StreckenLaenge ();148 cout << "\nh: " << h;149 cout << "\n Streckenlaenge von h = " << h.StreckenLaenge ();150

151 s = g * h;

Page 31: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

SCHNITT4.CPP, 29.6.2016 11:58:02 31

152 cout << "\nSchnittpunkt:" << s;153

154 cout << "\ng // h: " << (g || h);155

156 Gerade h1 (7, 5, 13, 9);157 cout << "\ng: " << g;158 cout << "\nh: " << h1;159 cout << "\ng // h: " << (g || h1);160

161 return 0;162 }163

Datei 74: SCHNITT2.RES, 26.4.2017 10:05:281

2 g: x = (1-lambda) * 2 4 + lambda * 5 63 Streckenlaenge von g = 3.605554 h: x = (1-lambda) * 7 5 + lambda * 6 95 Streckenlaenge von h = 4.123116 Schnittpunkt:6.5 77 g // h: 08 g: x = (1-lambda) * 2 4 + lambda * 5 69 h: x = (1-lambda) * 7 5 + lambda * 13 910 g // h: 1

Datei 75: SCHNITT4.CPP, 29.6.2016 11:58:021 /* ./ooprog/geom/SCHNITT4.CPP; Schnitt zweier Geraden in C++ */2

3 // Uebersetzung mit gnu c/c++: gxx -o schnitt4 schnitt4.cpp geradea.cpp vektora.cpp math1a.c4

5 #include <iostream>6 #include <cmath>7 #include "math1a.h"8 #include "vektora.h"9 #include "geradea.h"10

11 using namespace std;12

13 int main (void)14 { Vektor p1 (2, 4), p2 (5, 6);15 Gerade g (p1, p2), h (7, 5, 6, 9);16 Vektor s;17

18 cout << "\ng: " << g;19 cout << "\n Streckenlaenge von g = " << g.StreckenLaenge ();20 cout << "\nh: " << h;21 cout << "\n Streckenlaenge von h = " << h.StreckenLaenge ();22

23 s = g * h;24 cout << "\nSchnittpunkt:" << s;25

26 cout << boolalpha << "\ng // h: " << (g || h);27

28 Gerade h1 (7, 5, 13, 9);29 cout << "\ng: " << g;30 cout << "\nh: " << h1;31 cout << boolalpha << "\ng // h: " << (g || h1);32

33 // Test von Vektoren:34

35 Vektor a, b (1), c (2, 3), d (c), e, f;36 cout << "\n" << a << b << c << d << endl;37 if (a) cout << "a nicht 0" << endl;38 if (!a) cout << "a ist 0" << endl;39 if (b) cout << "b nicht 0" << endl;40 if (!b) cout << "b ist 0" << endl;41 if (c) cout << "c nicht 0" << endl;42 if (!c) cout << "c ist 0" << endl;43 if (d) cout << "d nicht 0" << endl;44 if (!d) cout << "d ist 0" << endl;45 cout << d << +d << -d << endl;46 e = +d;47 f = -d;48 cout << d << e << f << endl;49 cout << b << " += " << c << " = ";50 b += c;51 cout << b << endl;52

53 cout << b << " -= " << f << " = ";

Page 32: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

32 SCHNITT4.CPP, 29.6.2016 11:58:02

54 b -= f;55 cout << b << endl;56

57 c *= 5;58 cout << c << endl;59

60 cout << b << " * " << c << " = " << b * c << endl;61 cout << b << " + " << c << " = " << b + c << endl;62 cout << b << " - " << c << " = " << b - c << endl;63 cout << 3 << " * " << c << " = " << 3.0 * c << endl;64 cout << b << " * " << 3 << " = " << b * 3.0 << endl;65 cout << "Koordinaten von b: " << b.xKoor () << " " << b.yKoor () << endl;66 cout << "Norm von b: " << b.Norm () << endl;67 b.normiere ();68 cout << "normiertes b: " << b << endl;69

70 return 0;71 }72

Datei 76: SCHNITT4.RES, 26.4.2017 10:05:281

2 g: x = (1-lambda) * 2 4 + lambda * 5 63 Streckenlaenge von g = 3.605554 h: x = (1-lambda) * 7 5 + lambda * 6 95 Streckenlaenge von h = 4.123116 Schnittpunkt:6.5 77 g // h: false8 g: x = (1-lambda) * 2 4 + lambda * 5 69 h: x = (1-lambda) * 7 5 + lambda * 13 910 g // h: true11 0 01 02 32 312 a ist 013 b nicht 014 c nicht 015 d nicht 016 2 32 3-2 -317 2 32 3-2 -318 1 0 += 2 3 = 3 319 3 3 -= -2 -3 = 5 620 10 1521 5 6 * 10 15 = 14022 5 6 + 10 15 = 15 2123 5 6 - 10 15 = -5 -924 3 * 10 15 = 30 4525 5 6 * 3 = 15 1826 Koordinaten von b: 5 627 Norm von b: 7.8102528 normiertes b: 0.640184 0.76822129

Datei 77: GERADEA.CPP, 29.6.2016 11:58:021 /* ./ooprog/geom/GERADEA.CPP; Schnitt zweier Geraden in C++ */2

3 #include "geradea.h"4

5 Vektor Gerade :: Schnitt (const Gerade g) const6

7 /* Schnittpunkt x = p1 + l * (p2-p1) = g.p1 - m * (g.p1-g.p2) */8 /* = p1 + l * r1 = g.p1 - m * r2 */9 /* l * r1 + m * r2 = g.p1 - p1 = h --solve-> l, m -> x = p1 + l * r1 */10

11 { Vektor r1, r2, h, x;12

13 r1 = p2 - p1;14 r2 = g.p1 - g.p2;15 h = g.p1 - p1;16

17 x = solve (r1, r2, h);18

19 h = r1 * x.xKoor (); /* x.x = l(ambda); x.y = m(ue) */20 return p1 + h;21 }22

23 Vektor Gerade :: operator * (const Gerade g) const24 {25 return this->Schnitt (g);26 }27

28 bool Gerade :: operator || (const Gerade h) const

Page 33: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

VEKTORA.CPP, 29.6.2016 11:58:02 33

29 {30 Vektor r, s;31 r = this->p1 - this->p2;32 s = h.p1 - h.p2;33 return r.kollinear(s);34 }35

36 ostream & operator << (ostream & s, const Gerade g)37 { ostream::sentry se(s);38 if (se)39 { s << "x = (1-lambda) * " << g.p1 << " + lambda * " << g.p2;40 }41 return s;42 }43

44 istream & operator >> (istream & s, Gerade & b)45 { return s; // fehlt einfach noch46 }47

Datei 78: GERADEA.H, 29.6.2016 11:58:021 #ifndef __GERADEA_H2 #define __GERADEA_H3

4 #include <iostream>5 #include "vektora.h"6

7 class Gerade8 {9 public:10 // Konstruktoren und Destruktoren:11 Gerade (const double a = 0, const double b = 0, const double c = 1, const double d = 0)12 : p1 (a, b), p2 (c, d) { }13 Gerade (const Vektor v1, const Vektor v2) : p1 (v1), p2 (v2) { }14 Gerade (const Gerade & g) : p1 (g.p1), p2 (g.p2) { }15

16 // Operator-Funktionen17 bool operator || (const Gerade) const;18 Vektor operator * (const Gerade) const;19

20 // Andere member-Funktionen21 double StreckenLaenge () const { Vektor h (p1); h -= p2; return h.Norm (); }22 Vektor Schnitt (const Gerade) const;23

24 // friend-Funktionen25 friend ostream & operator << (ostream &, const Gerade);26 friend istream & operator >> (istream &, Gerade &);27

28 private:29

30 Vektor p1, p2;31 };32

33 #endif34

Datei 79: VEKTORA.CPP, 29.6.2016 11:58:021 /* ./ooprog/geom/VEKTORA.CPP; C++-Code fuer Punkte und Vektoren */2

3 #include "vektora.h"4

5 // Funktionen ohne Zugriff auf private member6

7 Vektor solve (Vektor a1, Vektor a2, Vektor b)8 { Vektor h;9 double d;10 d = det (a1.x, a2.x, a1.y, a2.y);11 h.x = det (b.x, a2.x, b.y, a2.y) / d;12 h.y = det (a1.x, b.x, a1.y, b.y) / d;13 return h;14 }15

16 ostream & operator << (ostream & s, const Vektor b)17 { ostream::sentry se(s);18 if (se)19 { s << b.x << " " << b.y;20 }21 return s;22 }

Page 34: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

34 VEKTORA.CPP, 29.6.2016 11:58:02

23

24 istream & operator >> (istream & s, Vektor & b)25 { return s;26 }27

Datei 80: VEKTORA.H, 29.6.2016 11:58:021 #ifndef __VEKTORA_H2 #define __VEKTORA_H3

4 #include <iostream>5 #include <cmath>6 #include "math1a.h"7

8 using namespace std;9

10 class Vektor11 {12 public:13

14 // Konstruktoren und Destruktoren15 Vektor (const double a = 0, const double b = 0) : x (a), y (b) { }16 // defaults problematisch wegen int-Konversionen!17 Vektor (const Vektor & a) : x (a.x), y (a.y) { }18

19 // Zugriffsoperationen20 double xKoor () const { return x; }21 double yKoor () const { return y; }22

23 // Konversionen mit cast-Operatoren24 operator bool () const { return x != 0 || y != 0; }25

26 // Operator-Funktionen (sinnlos sind ++ --)27 Vektor operator + () const { Vektor h (*this); return h; }28 Vektor operator - () const { Vektor h (-x, -y); return h; }29 bool operator ! () const { return x == 0 && y == 0; }30 Vektor operator += (const Vektor b) { x += b.x; y += b.y; return *this; }31 Vektor operator -= (const Vektor b) { x -= b.x; y -= b.y; return *this; }32 Vektor operator *= (const double b) { x *= b; y *= b; return *this; }33 double operator * (const Vektor b) const34 { double h; h = x * b.x + y * b.y; return h; }35 // Andere member-Funktionen36 double Norm () const { return sqrt (sqr (x) + sqr (y)); }37 void normiere () { double n; n = Norm (); x /= n; y /= n; }38 bool kollinear (const Vektor b) const39 { return x * b.y == y * b.x; }40 // friend-Funktionen41 friend Vektor solve (Vektor a1, Vektor a2, Vektor b);42 friend ostream & operator << (ostream &, const Vektor);43 friend istream & operator >> (istream &, Vektor &);44

45 private:46 double x, y;47 };48

49 // Operatoren ohne Zugriff auf private member50

51 inline Vektor operator + (const Vektor a, const Vektor b) { Vektor h (a); h += b; return h; }52 inline Vektor operator - (const Vektor a, const Vektor b) { Vektor h (a); h -= b; return h; }53 inline Vektor operator * (const Vektor a, const double b) { Vektor h (a); h *= b; return h; }54 inline Vektor operator * (const double b, const Vektor a) { Vektor h (a); h *= b; return h; }55

56 #endif57

Datei 81: uebc.BAT, 29.6.2016 11:58:021 gcc -o schnitt schnitt.c2 gcc -o schnitta schnitta.c math1a.c3 gcc -o punkt punkt.c gerade.c vektor.c math1.c4 schnitt >schnitt.res5 schnitta >schnitta.res6 punkt >punkt.res7

Datei 82: uebcpp.BAT, 29.6.2016 11:58:021 del *.bak2 del s*.exe3 g++ -o schnitt1 schnitt1.cpp4 if errorlevel 1 goto alt

Page 35: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

doc.doc, 13.7.2016 15:39:44 35

5 g++ -o schnitt2 schnitt2.cpp math1a.c6 if errorlevel 1 goto alt7 g++ -o schnitt4 schnitt4.cpp geradea.cpp vektora.cpp math1a.c8 if errorlevel 1 goto alt9 schnitt1 >schnitt1.rs10 schnitt2 >schnitt2.rs11 schnitt4 >schnitt4.rs12 goto ende13 :alt14 del s*.exe15 gxx -o schnitt1 schnitt1.cpp16 gxx -o schnitt2 schnitt2.cpp math1a.c17 gxx -o schnitt4 schnitt4.cpp geradea.cpp vektora.cpp math1a.c18 schnitt1 >schnitt1.res19 schnitt2 >schnitt2.res20 schnitt4 >schnitt4.res21 :ende22

Datei 83: Makef., 29.6.2016 11:58:021 schnitt.res : schnitt.c2 gcc -o schnitt schnitt.c3 ./schnitt >schnitt.res4 punkt.res : punkt.c5 gcc -o punkt punkt.c math1.c vektor.c gerade.c6 ./punkt >punkt.res7 schnitta.res : schnitta.c math1a.c8 gcc -o schnitta schnitta.c math1a.c9 ./schnitta >schnitta.res10 schnitt1.res : schnitt1.cpp11 g++ -o schnitt1 schnitt1.cpp12 ./schnitt1 >schnitt1.res13 schnitt2.res : schnitt2.cpp math1a.c14 g++ -o schnitt2 schnitt2.cpp math1a.c15 ./schnitt2 >schnitt2.res16 schnitt4.res : schnitt4.cpp geradea.cpp vektora.cpp math1a.c17 g++ -o schnitt4 schnitt4.cpp geradea.cpp vektora.cpp math1a.c18 ./schnitt4 >schnitt4.res19

20 clean :21 rm *.o *.exe *.bak *.BAK *~22

23 all : schnitt.res punkt.res schnitta.res schnitt1.res schnitt2.res schnitt4.res24

Datei 84: cpp4.a2t, 29.6.2016 11:57:341 ooprog\geom\SCHNITT.C2 ooprog\geom\SCHNITT.RES3 ooprog\geom\MATH1.H4 ooprog\geom\MATH1.C5 ooprog\geom\VEKTOR.H6 ooprog\geom\VEKTOR.C7 ooprog\geom\GERADE.H8 ooprog\geom\GERADE.C9 ooprog\geom\PUNKT.C10 ooprog\geom\PUNKT.RES11 ooprog\geom\SCHNITTA.C12 ooprog\geom\SCHNITTA.RES13 ooprog\geom\MATH1A.H14 ooprog\geom\MATH1A.C15 ooprog\geom\SCHNITT1.CPP16 ooprog\geom\SCHNITT1.RES17 ooprog\geom\SCHNITT2.CPP18 ooprog\geom\SCHNITT2.RES19 ooprog\geom\SCHNITT4.CPP20 ooprog\geom\SCHNITT4.RES21 ooprog\geom\GERADEA.CPP22 ooprog\geom\GERADEA.H23 ooprog\geom\VEKTORA.CPP24 ooprog\geom\VEKTORA.H25 ooprog\geom\uebc.BAT26 ooprog\geom\uebcpp.BAT27 ooprog\geom\Makef.28

Datei 85: doc.doc, 13.7.2016 15:39:441 Die Compilation des rat-systems benötigt Gnu Multiple Precision Arithmetik (gmp).2

3 http://gmplib.org/

Page 36: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

36 doc.doc, 13.7.2016 15:39:44

4

5 Installationsanleitung in http://gmplib.org/gmp-man-4.3.0.pdf6

7 Die letzte Version wurde nicht mehr mit DJGPP sondern mit MSYS installiert;8

9 download10 Auspacken in /gmp-4.2.4 (gmp-5.0.1)11 ./configure --enable-cxx12 make13 make check14 make install15

16 Test mit ratgmp:17 cd /c/vectra/C_KURS/BRUCH18 g++ -I /usr/local/include -o ratgmp -O2 ratmain.cpp rat.cpp rzeit.c -L /usr/local/lib -l gmpxx -l gmp19 (Reihenfolge ist wichtig: erst libgmpxx dann libgmp!)20

21

22 Test in einer komplexen Situation:23 cd /c/vectra/c_lib/mathlib/matrix24 $ g++ -I /usr/local/include -I ../../../C_KURS/BRUCH/ -o gstest -O225 gstest.cpp ../../../C_KURS/BRUCH/rat.cpp ../../../C_KURS/BRUCH/rzeit.c -L26 /usr/local/lib -l gmpxx -l gmp27

28

29 Eine Alternative ist apfloat.30 tar.gz Datei auspacken31 cd src32 make apfloat.a33

34 Auch die 'Numerical recipes' bieten eine Implementierung langer ganzer Zahlen.35

Datei 86: FILES.A2T, 26.4.2017 15:04:341 /O2 bruch\doc.doc3 bruch\FILES.A2T4

5 bruch\rzeit.tim6

7 bruch\ueblinux.8

9 bruch\ratc.c10 bruch\ratc.r11

12 bruch\bruch.cpp13 bruch\bruch.in14 bruch\bruch.res15

16 bruch\intext.hh17 bruch\rat.hh18 bruch\ratmain.cpp19 bruch\rzeit.h20 bruch\rzeit.c21

22 bruch\ulintmt.h23 bruch\apx.h24 bruch\ulintgmp.h25 bruch\gmpx.h26

27 bruch\ulintnr.hh28 bruch\ulintnr.cpp29

30 bruch\nrmpx.c31 bruch\nrmpx.h32 bruch\nrtst.c33 bruch\ratnr.res34 bruch\uebnr.bat35 bruch\ulintnrt.cpp36

37

Datei 87: rzeit.tim, 29.6.2016 11:57:561 1. Rechenzeiten verschiedener Versionen der Brucharithmetik (Stand Juli 2010)2 ============================================================================3

4 1.1 Aktuelle Ergebnisse5 -----------------------6

Page 37: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

rzeit.tim, 29.6.2016 11:57:56 37

7 Die Ergebnisse werden bis MAX = 19 berechnet.8 Die Eingabe (cin >> ) und Ausgabe (cout << ) geht nicht in die Rechenzeit ein.9 Die Berechnung der Bernoulli-Zahlen wird ANZ = 1..1000 mal wiederholt, um10 groessere Meágenauigkeit zu erreichen.11

12 Fuer lange Zahlen wurde eine Freeware13 Multiprecision Arithmetic benutzt (Apfloat, Mikko Tommila, apfloat v. 2.41,14 http://www.apfloat.org/).15 C:\Download\apfloat\djgpp: make -f makefile16

17 Eine weitere MP-Arithmetik steht mit GMP (free library for arbitrary18 precision arithmetic, operating on signed integers, rational numbers, and19 floating point numbers) zur Verfuegung.20 http://gmplib.org/21 http://gmplib.org/manual/Installing-GMP.html#Installing-GMP22 /c/Download/gmp/gmp-5.0.123 MSYS: ./configure --enable-cxx / make / make check / make install24 /usr/local/include/gmp.h25 /usr/local/lib/libgmp.a libgmp.la26

27 Rechner: Dell Optiplex GX 620, Intel rrzvm074 pc52121 pc51315 vm07428 Pentium 4-2800 (Prescott) 2.8 GHz Intel Xeon E5430 2.66 GHz Celeron Pent 4 Xeon29

30 Compiler Gnu C++ Gnu C++ Gnu C++ Gnu C++ Gnu C++ Gnu C++31 4.4.0 (MingW) 4.3.2 (DJGPP) 4.3.2 4.3.2 4.4.4 4.3.232 gmp 4.3.1 gmp 4.3.1 gmp422 gmp432 gmp43133 apfloat 2.41 apfloat 2.4134 -O2 -O2 -O235

36 ratc 0.009259 0.015824 0.0057237

38 Bruch 0.009174 0.0152 0.0055739 ratmlong 0.0000754 0.000076940 ratmapx 0.0098901 0.014141 ratmulap 0.0108791 0.0146142 ratmgmp 0.007719 0.00461 0.00575 0.0017543 ratmgmpx 0.009376 0.00294 0.00359 0.0011544 ratmmpa45 ratmnr 0.048351646

47 Bernoulli[2].java (mit BigInteger) 0.012248

49 Groesse des .exe-Files in Byte:50

51 ratc 304473452

53 Bruch 873754 2723154 ratlong 932488 3356455 ratulint 874356 2778356 ratgmp 1052937 5223757 ratmt 804627458

59 1.2 Ergebnisse von ratgnu/ratmt/Bernoulli[2].java in Abhaengigkeit von der max. Bernoullizahl60 ---------------------------------------------------------------------------------------------61

62 const int anz 19 51 101 151 201 50163

64 GX620mw ratc65 GX620dj ratmapx 3.29666 GX620dj ratmulap67 GX620mw ratmgmpx 0.68868 GX620mw ratmulgm 2.09369 GX620mw ratmmpa70 GX620mw ratmnr71 gx620 Bernoulli[2].java 0.0122 0.014 0.095 0.34 0.823 20.88872

73 GX620dj ratc74 GX620dj ratmapx75 GX620dj ratmulap76 GX620dj ratmgmpx77 GX620dj ratmulgm78 GX620dj ratmmpa79 GX620dj ratmnr80

81 vm074 ratc.c 0.00566 0.02254 0.0901 0.361 1.44 5.73 23.0382 vm074 ratgmp.cpp 0.31 1.22 4.98 20.1 80.8 319.11 1267.1383 vm074 ratmt.cpp 1.99 8.32 32.91 132.1 526.82 2115.97 8440.5984 vm074 Bernoulli[2].java85

86 1.3 Schluessel der Bezeichnungen

Page 38: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

38 rzeit.tim, 29.6.2016 11:57:56

87 --------------------------------88

89 GX620mw Dell Optiplex GX 620, Intel, Pentium 4-2800 (Prescott) 2.8 GHz (MinGW)90 GX620dj Dell Optiplex GX 620, Intel, Pentium 4-2800 (Prescott) 2.8 GHz (DJGPP)91 rrzvm074 Intel Xeon E5430 2.66 GHz92 HP Vektra Pentium II93

94 Gnu C++ gcc version 2.7.2.1 - 4.4 mit djgpp/MinGW95

96 Bruch bruch.cpp + rzeit.cpp97 Einfache Version mit direkter long int Arithmetik98 ratlong ratmain.cpp + rat[long].cpp + long.cpp + rzeit.cpp99 Version mit modularer direkter long int Arithmetik100 ratul ratmain.cpp + rat[ulint].cpp + ulint[1].cpp + rzeit.cpp101 Version mit modularer eigener Klasse fuer die (indirekte) long int Arithmetik102 ratgnu ratmain.cpp + rat[gnu].cpp + gnuint.cpp + rzeit.cpp + stdcpp.a + gpp.a103 Version mit Gnu Integer Arithmetik104 ratgmp ratmain.cpp + rat[gmp].cpp + rzeit.cpp + libgmpxx.a + libgmp.a105 Version mit gmp Arithmetik106 ratmt ratmain.cpp + rat[ulint].cpp + ulint[mt].cpp + rzeit.cpp + apfloat.a107 Version mit apfloat Arithmetik108

109 1.4 Genaue Darstellung der Optionen110 -----------------------------------111

112 [Dateien in eckigen Klammern muessen vor der Uebersetzung kopiert werden!]113 [Beispiel: ratlong: copy ratlong.* rat.* ]114

115 HP Vektra, Gnu C++, bis Juni 2001116

117 Bruch gcc bruch.cpp rzeit.cpp -lstdcpp118 ratlong gcc ratmain.cpp rat[long].cpp long.cpp rzeit.cpp -lstdcpp119 ratmain gcc ratmain.cpp rat[ulint].cpp ulint[1].cpp rzeit.cpp -lstdcpp -lgpp120 ratgnu gcc ratmain.cpp rat[gnu].cpp gnuint.cpp rzeit.cpp -lstdcpp -lgpp121

122

123 HP Vektra, Gnu C++, ab Mai 2003124

125 Bruch gxx -o bruch -O2 bruch.cpp rzeit.c -s126 ratlong gxx -o ratlong -O2 ratmain.cpp rat[long].cpp long.cpp rzeit.c -s127 ratul gxx -o ratul -O2 ratmain.cpp rat[ulint].cpp ulint[1].cpp rzeit.c -s128 ratgmp gxx -o ratgmp -O2 ratmain.cpp rat[gmp].cpp rzeit.c -s -lgmpxx -lgmp129 ratmt gxx -o ratmt -O2 -I /Download/mp-arith/apfloat/apfloat ratmain.cpp rat.cpp ulint.cpp rzeit.c -s /Download/mp-arith/apfloat/apfloat/apfloat.a130

131 2. Rechenzeiten verschiedener Versionen der Brucharithmetik (Stand Mai 2003)132 ============================================================================133

134 2.1 Aktuelle Ergebnisse135 -----------------------136

137 Die Ergebnisse werden bis MAX = 19 berechnet.138 Die Eingabe (cin >> ) und Ausgabe (cout << ) geht nicht in die Rechenzeit ein.139 Die Berechnung der Bernoulli-Zahlen wird ANZ = 1..1000 mal wiederholt, um140 groessere Meágenauigkeit zu erreichen.141

142 Am 19.6.2001 wurden die urspruenglich mit Gnu C++ 2.8.1 gewonnenen143 Ergebnisse erneut mit Gnu C++ 2.95 (DJ) gemessen, wobei sich kaum144 Abweichungen ergaben.145 Die neuen Werte stehen in Klammern.146 Am 19.6.2001 wurden die Ergebnisse mit Gnu C++ 2.95.2 und Forte CC 5.2 auf147 einer Sun Ultra 10 gemessen.148 Am 9.5.2003 wurden die Ergebnisse mit Gnu C++ 3.2 (DJ) gemessen. Wieder149 ergaben sich kaum Abweichungen. Bei der neuen Messung wurde eine Freeware150 Multiprecision Arithmetic benutzt (Apfloat, Mikko Tommila,151 http://www.apfloat.org/), um wieder lange Bernoullizahlen berechnen zu152 koennen.153 Eine weitere MP-Arithmetik steht mit GMP (free library for arbitrary154 precision arithmetic, operating on signed integers, rational numbers, and155 floating point numbers) zur Verfuegung, die die alte Klasse Integer156 ersetzt. Auch diese Arithmetik wurde in die aktuelle Messung einbezogen.157 Alle Messungen wurden mit der Grundcompilation und zusaetzlich mit der158 Optimierung -O2 durchgefuehrt.159

160 Rechner: HP Vectra VL, Pentium II, MMX, 233 MHz Sun Ultra 10161

162 Compiler Gnu C++ (Gnu C++) MS-VCC-5 MS-VCC-5 Java Gnu C++ CC 5.2 Java163 2.8.1 (2.95/3.2/-O2) Debug Release JDK 1.3 2.92.3 JDK 1.2.2164

165 Bruch 0.142 (0.147/0.138/0.150) 0.181 0.160 0.135 0.097

Page 39: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

rzeit.tim, 29.6.2016 11:57:56 39

166 ratlong 0.142 (0.142/0.138/0.151) 0.182 0.154 0.134 0.097167 ratulint 1.604 (1.848/1.801/0.201) 1.637 0.203 1.283 0.579168 ratgnu 8.263 (8.440/Integer not longer compilable) 6.939169 ratgmp ----- (----/10.893/6.813)170 ratmt (60.275/62.473)171

172 Bernoulli[0].java (mit double) 0.140 0.108173 Bernoulli[1].java (mit BigInteger) 5.052 82.277174

175 ratc.res + gmp 0.156593176

177 Groesse des .exe-Files in Byte:178

179 Bruch 287116(256512) 717512 454420180 ratlong 303223(273408) 787124 498864181 ratulint 294378(258048) 727360 475936182 ratgnu 358640183 ratgmp (335360)184 ratmt (472576)185

186 2.2 Ergebnisse von ratgnu/Bernoulli[1].java in Abhaengigkeit von der max. Bernoullizahl187 ------------------------------------------------------------------------------------188

189 Rechner: HP Vectra VL, Pentium II, MMX, 233 MHz190 Compiler Gnu C++191

192 const int anz 19 21 23 25 27 29 31193

194 ratgnu.cpp 8.26 32.41 129.06 374.61 1854.83 2727.58195 ratgmp.cpp 6.81 27.53 109.78 439.67 1761.87 7201.26196 ratmt.cpp 62.47 255.66 998.24 3836.10197 Bernoulli[1].java 5.05 19.86 79.79 317.56 1273.20 5081.57198

199 Rechner: Dell Optiplex 620200 Compiler Gnu C++ 3.4.5; gmp 4.2.4; MSYS;201 Datum: 2.12.2008202

203 ratgmp.cpp 1.81 7.28 28.94 115.62 463.76 1855.78204

205 2.3 Genaue Darstellung der Optionen206 -----------------------------------207

208 [Dateien in eckigen Klammern muessen vor der Uebersetzung kopiert werden!]209 [Beispiel: ratlong: copy ratlong.* rat.* ]210

211 HP Vektra, Gnu C++, bis Juni 2001212

213 Bruch gcc bruch.cpp rzeit.cpp -lstdcpp214 ratlong gcc ratmain.cpp rat[long].cpp long.cpp rzeit.cpp -lstdcpp215 ratmain gcc ratmain.cpp rat[ulint].cpp ulint[1].cpp rzeit.cpp -lstdcpp -lgpp216 ratgnu gcc ratmain.cpp rat[gnu].cpp gnuint.cpp rzeit.cpp -lstdcpp -lgpp217

218

219 HP Vektra, Gnu C++, ab Mai 2003220

221 Bruch gxx -o bruch -O2 bruch.cpp rzeit.c -s222 ratlong gxx -o ratlong -O2 ratmain.cpp rat[long].cpp long.cpp rzeit.c -s223 ratul gxx -o ratul -O2 ratmain.cpp rat[ulint].cpp ulint[1].cpp rzeit.c -s224 ratgmp gxx -o ratgmp -O2 ratmain.cpp rat[gmp].cpp rzeit.c -s -lgmpxx -lgmp225 ratmt gxx -o ratmt -O2 -I /Download/mp-arith/apfloat/apfloat ratmain.cpp rat.cpp ulint.cpp rzeit.c -s /Download/mp-arith/apfloat/apfloat/apfloat.a226

227 3. Rechenzeiten verschiedener Versionen der Brucharithmetik (Stand 1997)228 ========================================================================229

230 3.2 Programme:231 --------------232

233 Bruch Einfache Version mit direkter long int Arithmetik234 rat Version mit eigener Klasse fuer die (indirekte) long int Arithmetik235 ratnb wie rat, nur ohne bool236 ratmain wie rat, nur mit getrennter Uebersetzung fuer ulint und rat237

238 3.2 Rechenzeiten bei den verschiedenen Brucharithmetiken (16.6.1997):239 ---------------------------------------------------------------------240

241 Rechner: 80486 DX2-66 Sun Sparc242

243 Programm: Gnu C++ 2.7.2.1 Borland C++ 3.1 Gnu C++ 2.6.3 Sun CC 4.0244

Page 40: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

40 rzeit.tim, 29.6.2016 11:57:56

245 Bruch 1.37 2.03 0.62 0.43246 rat 20.65 bool 4.85 bool247 ratnb Ambiguities 3.19248 ratmain 21.26249

Datei 88: ueblinux., 26.4.2017 13:48:141 #!/bin/bash2 # 2015, rz412: 2h (3103.692u 7.700s 52:25.26 98.9% 0+0k 60560+657816io 140pf+0w)3 # ueblinux: compile and measure time4 # nohup ./ueblinux & runs in the backdroung5

6 # tested on7 # rz411/rz4128 # rrzvm0349 # pc51315, debian linux, Uebersetzung:10

11 # preparations:12 # apfloat.a compile and build13 # libnr.a compile and build14 # nr/other/hr.h comment float select (15

16 # 505 apt-get install libgmp3-dev17 # 514 find / -name gmp.h18 # 524 find / -name libgmp.a19

20 echo compilation and run of examples with rational numbers21 echo last update: 26.4.201722 echo caution: some runs will take up to an hour23

24 if [ ! -d src ]; then25 echo apfloat26 gzip -d apfloat.tar.gz27 tar -xf apfloat.tar28 cd src29 make30 cd ..31 fi32

33 if [ ! -d ../../../../clib/trunk/c_lib/nr/other ]; then34 echo nr other35 cd ../../../../clib/trunk/c_lib/nr/36 mkdir other37 cd other38 tar -xf ../other.tar39 cd ../../../../cplusplus/trunk/cplusplus/bruch/40 fi41

42 if [ ! -d ../../../../clib/trunk/c_lib/nr/ansi ]; then43 echo nr libnr.a in ansi44 cd ../../../../clib/trunk/c_lib/nr/45 mkdir ansi46 cd ansi47 tar -xf ../ansi.tar48 make libnr.a49 cd ../../../../cplusplus/trunk/cplusplus/bruch/50 fi51

52 rm -fr *.o *.r *.res53

54 gcc -c rzeit.c55 echo ratc.c56 gcc -O2 ratc.c rzeit.o -lgmp57 ./a.out > ratc.r58 echo bruch.cpp59 g++ -O2 bruch.cpp rzeit.o60 ./a.out < bruch.in > bruch.res61 echo ratmain + long62 g++ -O2 ratmain.cpp long.cpp rzeit.o63 ./a.out 19 10000 < bruch.in > ratlong.res64 echo ratmain + apfloat65 g++ -O2 -DRAT_APFLOAT -I ./src ratmain.cpp ulintmt.cpp rzeit.o ./src/apfloat.a66 ./a.out 150 1 < bruch.in > ratap.res67 echo ratmain + apx + apfloat68 g++ -O2 -DRAT_APX -I ./src ratmain.cpp rzeit.o ./src/apfloat.a69 ./a.out 150 1 < bruch.in > ratapx.res70 echo ratmain + gmp71 g++ -O2 -DRAT_GMP ratmain.cpp ulintgmp.cpp rzeit.o -lgmp72 ./a.out 150 1 < bruch.in > ratgmp.res73 echo ratmain + gmp

Page 41: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratc.c, 26.4.2017 12:06:54 41

74 g++ -O2 -DRAT_GMPX ratmain.cpp rzeit.o -lgmpxx -lgmp75 ./a.out 150 1 < bruch.in > ratgmpx.res76 echo ratmain + nr77 gcc -c -I ../../../../clib/trunk/c_lib/nr/other nrmpx.c78 rm -fr nr.h79 sed '/select/d' ../../../../clib/trunk/c_lib/nr/other/nr.h > nr.h80 g++ -O2 -DRAT_NR -I . -I ../../../../clib/trunk/c_lib/nr/other ratmain.cpp ulintnr.cpp nrmpx.o rzeit.o -L ../../../../clib/trunk/c_lib/nr/ansi -lnr81 ./a.out 150 1 < bruch.in > ratnr.res82

Datei 89: ratc.c, 26.4.2017 12:06:541 // bruch/ratc.c2 // gcc ratc.c rzeit.c -lgmp3

4 #include <stdio.h>5 #include "gmp.h"6 #include "rzeit.h"7

8 //#include "ratc.h"9

10 #define anz 10011 #define bmax 15012

13 void binom (mpq_t b, long n, long k)14 { if (k < 0 || k > n) { mpq_set_si (b, 0, 1); return; }15 if (k == 0 || k == n) { mpq_set_si (b, 1, 1); return; }16 if (k == 1 || k == n - 1) { mpq_set_si (b, n, 1); return; }17

18 // 1 2 3 .. (n-k)(n-k+1) .. n (n-k+1) .. n (n+1-1)(n+1-2) .. (n+1-k)19 // (n k) = -------------------------- = ------------ = -------------------------20 // 1 2 .. k * 1 2 .. (n-k) 1 2 .. k 1 2 .. k21

22 mpq_t h1, h2, h3, h4, h5, h6;23

24 mpq_init (h1); // produkt25 mpq_init (h2); // nenner26 mpq_init (h3); //27 mpq_init (h4); //28 mpq_init (h5); // n+129 mpq_init (h6); // 130 //printf ("\n(%d %d)", n, k);31 // if k > n/2 <=> 2k > n then (n k) = (n (n-k))32 //h1 = k+k;33 if (k+k > n) { k = n - k; }34 //printf ("\n(%d %d)", n, k);35

36 mpq_set_si (h1, n, 1);37 mpq_set_si (h2, 2, 1);38 mpq_set_si (h4, n, 1);39 mpq_set_si (h6, 1, 1);40 mpq_add (h5, h4, h6); // n++;41 while (k > 1)42 {43 //putchar ('-'); mpq_out_str (stdout, 10, h1);44 mpq_sub (h3, h5, h2); // h1 *= n - h2; // one of h2 consecutive values is divisable by h245 mpq_mul (h4, h1, h3);46 mpq_div (h1, h4, h2); // h1 /= h2;47 mpq_add (h3, h2, h6);48 mpq_set (h2, h3); // h2++;49 k--;50 }51 mpq_set (b, h1);52

53 mpq_clear (h1);54 mpq_clear (h2);55 mpq_clear (h3);56 mpq_clear (h4);57 mpq_clear (h5);58 mpq_clear (h6);59

60 }61

62 void Bernoulli (void)63 { volatile int nn;64 volatile long n, k;65 mpq_t a [bmax];66 mpq_t s;67 double t;

Page 42: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

42 ratc.c, 26.4.2017 12:06:54

68 mpq_t h1, h2;69

70 mpq_init (h1);71 mpq_init (h2);72

73 for (n = 0; n < bmax; n++) mpq_init (a [n]);74 mpq_init (s);75

76 printf ("Bernoulli-Messung, anz= %d, bmax= %d", (int) anz, (int) bmax);77

78 t = RZeit ();79 for (nn = 0; nn < anz; nn++)80 { mpq_set_ui (a [0], 1, 1);81 for (n = 1; n < bmax; n++)82 { mpq_set (s, a [0]);83 for (k = 1; k <= n-1; k++)84 {85 binom (h1, n+1, k);86 mpq_mul (h2, h1, a [k]);87 mpq_add (s, s, h2);88 }89 binom (h1, n+1, n);90 mpq_div (h2, s, h1);91 mpq_neg (a [n], h2);92 } }93 t = RZeit () - t;94 printf ("Bernoulli-Zahlen\n ");95 for (n = 0; n < bmax; n++)96 {97 printf ("%ld : ", n);98 mpq_out_str (stdout, 10, a [n]);99 printf ("\n");100 }101 printf ("\nVerbrauchte Gesamtzeit: %f", t);102 t /= anz;103 printf ("\nVerbrauchte Rechenzeit: %f", t);104 printf ("\nanz = %d, bmax = %d\n", (int) anz, (int) bmax);105 mpq_clear (h1);106 mpq_clear (h2);107 }108

109 int main (void)110 {111 long n, k;112 mpq_t b;113 mpq_init (b);114 for (n = 0; n < 8; n++)115 {116 for (k = 0; k <= n; k++)117 {118 putchar (' ');119 binom (b, n, k);120 mpq_out_str (stdout, 10, b);121 }122 putchar ('\n');123 }124 Bernoulli ();125

126 return 0;127 }128

Datei 90: ratc.r, 26.4.2017 14:21:021 12 1 13 1 2 14 1 3 3 15 1 4 6 4 16 1 5 10 10 5 17 1 6 15 20 15 6 18 1 7 21 35 35 21 7 19 Bernoulli-Messung, anz= 100, bmax= 150Bernoulli-Zahlen10 0 : 111 1 : -1/212 2 : 1/613 3 : 014 4 : -1/3015 5 : 0

Page 43: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratc.r, 26.4.2017 14:21:02 43

16 6 : 1/4217 7 : 018 8 : -1/3019 9 : 020 10 : 5/6621 11 : 022 12 : -691/273023 13 : 024 14 : 7/625 15 : 026 16 : -3617/51027 17 : 028 18 : 43867/79829 19 : 030 20 : -174611/33031 21 : 032 22 : 854513/13833 23 : 034 24 : -236364091/273035 25 : 036 26 : 8553103/637 27 : 038 28 : -23749461029/87039 29 : 040 30 : 8615841276005/1432241 31 : 042 32 : -7709321041217/51043 33 : 044 34 : 2577687858367/645 35 : 046 36 : -26315271553053477373/191919047 37 : 048 38 : 2929993913841559/649 39 : 050 40 : -261082718496449122051/1353051 41 : 052 42 : 1520097643918070802691/180653 43 : 054 44 : -27833269579301024235023/69055 45 : 056 46 : 596451111593912163277961/28257 47 : 058 48 : -5609403368997817686249127547/4641059 49 : 060 50 : 495057205241079648212477525/6661 51 : 062 52 : -801165718135489957347924991853/159063 53 : 064 54 : 29149963634884862421418123812691/79865 55 : 066 56 : -2479392929313226753685415739663229/87067 57 : 068 58 : 84483613348880041862046775994036021/35469 59 : 070 60 : -1215233140483755572040304994079820246041491/5678673071 61 : 072 62 : 12300585434086858541953039857403386151/673 63 : 074 64 : -106783830147866529886385444979142647942017/51075 65 : 076 66 : 1472600022126335654051619428551932342241899101/6472277 67 : 078 68 : -78773130858718728141909149208474606244347001/3079 69 : 080 70 : 1505381347333367003803076567377857208511438160235/468681 71 : 082 72 : -5827954961669944110438277244641067365282488301844260429/14010087083 73 : 084 74 : 34152417289221168014330073731472635186688307783087/685 75 : 086 76 : -24655088825935372707687196040585199904365267828865801/3087 77 : 088 78 : 414846365575400828295179035549542073492199375372400483487/331889 79 : 090 80 : -4603784299479457646935574969019046849794257872751288919656867/23001091 81 : 092 82 : 1677014149185145836823154509786269900207736027570253414881613/49893 83 : 094 84 : -2024576195935290360231131160111731009989917391198090877281083932477/3404310

Page 44: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

44 ratc.r, 26.4.2017 14:21:02

95 85 : 096 86 : 660714619417678653573847847426261496277830686653388931761996983/697 87 : 098 88 : -1311426488674017507995511424019311843345750275572028644296919890574047/6141099 89 : 0100 90 : 1179057279021082799884123351249215083775254949669647116231545215727922535/272118101 91 : 0102 92 : -1295585948207537527989427828538576749659341483719435143023316326829946247/1410103 93 : 0104 94 : 1220813806579744469607301679413201203958508415202696621436215105284649447/6105 95 : 0106 96 : -211600449597266513097597728109824233673043954389060234150638733420050668349987259/4501770107 97 : 0108 98 : 67908260672905495624051117546403605607342195728504487509073961249992947058239/6109 99 : 0110 100 : -94598037819122125295227433069493721872702841533066936133385696204311395415197247711/33330111 101 : 0112 102 : 3204019410860907078243020782116241775491817197152717450679002501086861530836678158791/4326113 103 : 0114 104 : -319533631363830011287103352796174274671189606078272738327103470162849568365549721224053/1590115 105 : 0116 106 : 36373903172617414408151820151593427169231298640581690038930816378281879873386202346572901/642117 107 : 0118 108 : -3469342247847828789552088659323852541399766785760491146870005891371501266319724897592306597338057/209191710119 109 : 0120 110 : 7645992940484742892248134246724347500528752413412307906683593870759797606269585779977930217515/1518121 111 : 0122 112 : -2650879602155099713352597214685162014443151499192509896451788427680966756514875515366781203552600109/1671270123 113 : 0124 114 : 21737832319369163333310761086652991475721156679090831360806110114933605484234593650904188618562649/42125 115 : 0126 116 : -309553916571842976912513458033841416869004128064329844245504045721008957524571968271388199595754752259/1770127 117 : 0128 118 : 366963119969713111534947151585585006684606361080699204301059440676414485045806461889371776354517095799/6129 119 : 0130 120 : -51507486535079109061843996857849983274095170353262675213092869167199297474922985358811329367077682677803282070131/2328255930131 121 : 0132 122 : 49633666079262581912532637475990757438722790311060139770309311793150683214100431329033113678098037968564431/6133 123 : 0134 124 : -95876775334247128750774903107542444620578830013297336819553512729358593354435944413631943610268472689094609001/30135 125 : 0136 126 : 5556330281949274850616324408918951380525567307126747246796782304333594286400508981287241419934529638692081513802696639/4357878137 127 : 0138 128 : -267754707742548082886954405585282394779291459592551740629978686063357792734863530145362663093519862048495908453718017/510139 129 : 0140 130 : 1928215175136130915645299522271596435307611010164728458783733020528548622403504078595174411693893882739334735142562418015/8646141 131 : 0142 132 : -410951945846993378209020486523571938123258077870477502433469747962650070754704863812646392801863686694106805747335370312946831/4206930143 133 : 0144 134 : 264590171870717725633635737248879015151254525593168688411918554840667765591690540727987316391252434348664694639349484190167/6145 135 : 0146 136 : -84290226343367405131287578060366193649336612397547435767189206912230442242628212786558235455817749737691517685781164837036649737/4110147 137 : 0148 138 : 2694866548990880936043851683724113040849078494664282483862150893060478501559546243423633375693325757795709438325907154973590288136429/274386149 139 : 0150 140 : -3289490986435898803930699548851884006880537476931130981307467085162504802973618096693859598125274741604181467826651144393874696601946049/679470151 141 : 0152 142 : 14731853280888589565870080442453214239804217023990642676194878997407546061581643106569966189211748270209483494554402556608073385149191/6153 143 : 0154 144 : -3050244698373607565035155836901726357405007104256566761884191852434851033744761276392695669329626855965183503295793517411526056244431024612640493/2381714790155 145 : 0156 146 : 4120570026280114871526113315907864026165545608808541153973817680034790262683524284855810008621905238290240143481403022987037271683989824863/6157 147 : 0158 148 : -1691737145614018979865561095112166189607682852147301400816480675916957871178648433284821493606361235973346584667336181793937950344828557898347149/4470159 149 : 0160

161 Verbrauchte Gesamtzeit: 14.250300162 Verbrauchte Rechenzeit: 0.142503163 anz = 100, bmax = 150164

Datei 91: bruch.cpp, 29.6.2016 11:57:581 // bruch/BRUCH.CPP: Grundversion2

3 #include <iostream>4 #include <iomanip>5 #include <cstdlib>6 #include "rzeit.h"7

Page 45: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

bruch.cpp, 29.6.2016 11:57:58 45

8 using namespace std;9

10 long ggt (long a, long b)11 { if (a < 0) a = -a;12 if (b < 0) b = -b;13 for (;;)14 if (!a) return b;15 else if (!b) return a;16 else if (a == 1 || b == 1) return 1;17 else if (a == b) return a;18 else if (a > b) a %= b;19 else b %= a;20 }21

22 long binom (long n, long k)23 { if (k < 0 || k > n) return 0;24 if (k == 0 || k == n) return 1;25 if (n == 1 || k == n - 1) return n;26 return binom (n - 1, k - 1) + binom (n - 1, k);27 }28

29 void Kuerz (long & x, long & y)30 { long g;31

32 g = ggt (x, y);33 x /= g;34 y /= g;35 }36

37 class rat38 { private:39 long z, n;40 public:41 // Konstruktoren und Destruktoren42 rat () { z = 0; n = 1; }43 rat (long a) { z = a; n = 1; }44 rat (long a, long b);45 // Zugriffsoperationen46 long Zaehler () { return z; }47 long Nenner () { return n; }48 long operator [] (int i) { if (!i) return z; else return n; }49 operator long ()50 { if (n != 1) { cout << "(long)"; exit (4); } return z; }51 operator long double ()52 { return (long double) z / (long double) n; }53 rat operator - ();54 rat operator + (rat);55 rat operator - (rat);56 rat operator * (rat);57 rat operator / (rat);58 rat operator += (long i);59 rat operator += (rat b);60 friend ostream & operator << (ostream & s, rat b);61 friend istream & operator >> (istream & s, rat & b);62 // % ^ & | ~ !63 // = < > += -= *= /= %= ^= &=64 // |= << >> <<= >>= == != <= >= &&65 // || ++ -- ->* , -> () new delete66 };67

68 rat::rat (long a, long b)69 { if (!b) { cout << "+++ rat (a, b) " << endl; exit (1); }70 if (b < 0) { a = - a; b = - b; }71 z = a; n = b; Kuerz (z, n);72 }73

74 rat rat::operator - ()75 { rat r;76 r.z = -z;77 r.n = n;78 return r;79 }80

81 rat rat::operator + (rat b)82 { rat r;83 r.z = z * b.n + n * b.z;84 r.n = n * b.n;85 Kuerz (r.z, r.n);

Page 46: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

46 bruch.cpp, 29.6.2016 11:57:58

86 return r;87 }88

89 rat rat::operator - (rat b)90 { rat r;91 r.z = z * b.n - n * b.z;92 r.n = n * b.n;93 Kuerz (r.z, r.n);94 return r;95 }96

97 rat rat::operator * (rat b)98 { rat r;99 r.z = z * b.z;100 r.n = n * b.n;101 Kuerz (r.z, r.n);102 return r;103 }104

105 rat rat::operator / (rat b)106

107 { rat r;108 if (!b.z) { cout << "+++ / " << endl; exit (2); }109 r.z = z * b.n;110 r.n = n * b.z;111 if (r.n < 0)112 {113 r.z = - r.z;114 r.n = - r.n;115 }116 Kuerz (r.z, r.n);117 return r;118 }119

120 rat rat::operator += (long i)121 { rat b (i, 1);122 z = z * b.n + n * b.z;123 n = n * b.n;124 Kuerz (z, n);125 return *this;126 }127

128 rat rat::operator += (rat b)129 { z = z * b.n + n * b.z;130 n = n * b.n;131 Kuerz (z, n);132 return *this;133 }134

135 ostream & operator << (ostream & s, rat b)136 { return s << b.z << ' ' << b.n;137 }138

139 istream & operator >> (istream & s, rat & b)140 { s >> b.z;141 s >> b.n;142 if (!b.n) { cout << "+++ >> " << endl; exit (3); }143 if (b.n < 0) { b.z = - b.z; b.n = - b.n; }144 Kuerz (b.z, b.n);145 return s;146 }147

148 void Bernoulli (double & t)149 { const int max = 19;150 const int anz = 10000;151 volatile int nn;152

153 long n, k;154 rat a [max];155 rat s;156

157 t = RZeit ();158 for (nn = 0; nn < anz; nn++)159 { a [0] = rat (1);160 for (n = 1; n < max; n++)161 { s = a [0];162 for (k = 1; k <= n-1; k++)163 { s += rat (binom (n+1, k)) * a [k];164 }

Page 47: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

bruch.res, 26.4.2017 14:21:32 47

165 a [n] = - s / (rat (binom (n+1, n)));166 } }167 t = RZeit () - t;168 t /= anz;169 cout << endl << "Verbrauchte Rechenzeit: " << t;170 cout << endl << "anz = " << anz << endl;171 cout << "Bernoulli-Zahlen " << endl;172 for (n = 0; n < max; n++)173 { cout << n << ": " << setw (20) << setprecision (15) << (long double) a [n] << " = " << a [n] << endl;174 } }175

176 int main ()177 { double t;178 rat a, b (35, 49), c, d;179 long double x;180

181 cout << "Gib Bruch: " << flush;182 cin >> a;183

184 cout << "a (gelesen) = " << a << " = " << a.Zaehler () << ":" << a.Nenner () << endl;185 cout << "b (vorbesetzt) = " << b << " = " << b.Zaehler () << ":" << b.Nenner () << endl;186 cout << "a = " << a << " = " << a [0] << ":" << a [1] << endl;187 cout << "a + b = " << a << " + " << b << " = " << a + b << endl;188 cout << "a - b = " << a << " - " << b << " = " << a - b << endl;189 cout << "a * b = " << a << " * " << b << " = " << a * b << endl;190 cout << "a / b = " << a << " / " << b << " = " << a / b << endl;191

192 a = rat (31415926, 27182818);193 d = c = a + b;194 cout << " d = c = a + b = " << a << " + " << b << " = " << c << " = " << d << endl;195 x = c;196 cout.width (20);197 cout.precision (15);198 cout << "x = c = " << x << endl;199

200 c += 1;201 cout << "c = " << c << endl;202 x = c;203 cout.width (20);204 cout.precision (15);205 cout << "x = c = " << x << endl;206

207 b = rat (2, 3);208 c += b;209 cout << "c = " << c << endl;210 x = c;211 cout.width (20);212 cout.precision (15);213 cout << "x = c = " << x << endl;214

215 b = rat (12, 6);216 cout << "b = " << b << endl;217 cout << "(long) b = " << (long) b << endl;218

219 // Berechnung der Bernoullizahlen220

221 Bernoulli (t);222

223 cout << endl << "Verbrauchte Rechenzeit: " << t << endl;224

225 // Dieses Testbeispiel steht bewusst hier, da dabei das Programm mit226 // einer Fehlermeldung abgebrochen wird227

228 b = rat (12, 18);229 cout << "Die folgende Konversion bringt das Programm zu einem Fehlerhalt" << endl;230 cout << "b = " << b << endl;231 cout << "(long) b = " << (long) b << endl;232 cout << "Wird wegen Fehlerhalt nicht mehr ausgegeben!" << endl;233 }234

Datei 92: bruch.in, 29.6.2016 11:57:561 2 32

Datei 93: bruch.res, 26.4.2017 14:21:321 Gib Bruch: a (gelesen) = 2 3 = 2:32 b (vorbesetzt) = 5 7 = 5:73 a = 2 3 = 2:3

Page 48: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

48 bruch.res, 26.4.2017 14:21:32

4 a + b = 2 3 + 5 7 = 29 215 a - b = 2 3 - 5 7 = -1 216 a * b = 2 3 * 5 7 = 10 217 a / b = 2 3 / 5 7 = 14 158 d = c = a + b = 15707963 13591409 + 5 7 = 177912786 95139863 = 177912786 951398639 x = c = 1.8700130564619410 c = 273052649 9513986311 x = c = 2.8700130564619412 c = 1009437673 28541958913 x = c = 3.536679723128614 b = 2 115 (long) b = 216

17 Verbrauchte Rechenzeit: 0.002927210718 anz = 1000019 Bernoulli-Zahlen20 0: 1 = 1 121 1: -0.5 = -1 222 2: 0.166666666666667 = 1 623 3: 0 = 0 124 4: -0.0333333333333333 = -1 3025 5: 0 = 0 126 6: 0.0238095238095238 = 1 4227 7: 0 = 0 128 8: -0.0333333333333333 = -1 3029 9: 0 = 0 130 10: 0.0757575757575758 = 5 6631 11: 0 = 0 132 12: -0.253113553113553 = -691 273033 13: 0 = 0 134 14: 1.16666666666667 = 7 635 15: 0 = 0 136 16: -7.0921568627451 = -3617 51037 17: 0 = 0 138 18: 54.9711779448622 = 43867 79839

40 Verbrauchte Rechenzeit: 0.002927210741 Die folgende Konversion bringt das Programm zu einem Fehlerhalt42 b = 2 343 (long)

Datei 94: intext.hh, 27.2.2017 14:13:561 // bruch/intext.hh integer extension2

3 #if ! defined INTEXT_HH4

5 #define INTEXT_HH6

7 #include<iostream>8

9 template<typename T>10 T intx_gcd (T a, T b)11 { if (a < T (0)) a = -a;12 if (b < T (0)) b = -b;13 for (;;)14 {15 if (!a) return b;16 else if (!b) return a;17 else if (a == T (1) || b == T (1)) return T (1);18 else if (a == b) return a;19 else if (a > b) a %= b;20 else b %= a;21 } }22

23 template<typename T>24 T intx_binom (T n, T k)25 { if (k < T(0) || k > n) return 0;26 if (k == T(0) || k == n) return 1;27 if (k == T(1) || k == n - T(1)) return n;28

29 // 1 2 3 .. (n-k)(n-k+1) .. n (n-k+1) .. n (n+1-1)(n+1-2) .. (n+1-k)30 // (n k) = -------------------------- = ------------ = -------------------------31 // 1 2 .. k * 1 2 .. (n-k) 1 2 .. k 1 2 .. k32

33 T h1, h2;34

35 // if k > n/2 <=> 2k > n then (n k) = (n (n-k))36 h1 = k+k;37 if (h1 > n) { k = n - k; }38

Page 49: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

rat.hh, 27.2.2017 14:13:56 49

39 h1 = n;40 h2 = T(2);41 n++;42 while (h2 <= k)43 { h1 *= n - h2; // one of h2 consecutive values is divisable by h244 h1 /= h2;45 h2++;46 }47 return h1;48 }49

50 template<typename T>51 void intx_simplify (T & x, T & y)52 { T g;53

54 g = intx_gcd (x, y);55 x /= g;56 y /= g;57 }58

59 #endif60

Datei 95: rat.hh, 27.2.2017 14:13:561 // bruch/rat.hh2

3 // short dictionary for rational numbers:4 // en de fr5 // rational number=fraction Bruch fraction6 // numerator Zaehler numerateur7 // denominator Nenner denominateur8 // reduce=simplify kuerzen simplifier9 // irreducible=lowest/simplest fraction10 // vollstaendig gekuerzter Bruch irreductible11 // gcd (greatest common divisor)12 // ggt (groesster gemeinsamer Teiler)13 // pgcd (plus grand commun diviseur)14 // Euclidean algorithm euklidischer Algorithmus Algorithme d'Euclide15

16 #if ! defined RAT_HH17

18 #define RAT_HH19

20 #include <string>21 #include <iostream>22 #include <iomanip>23 #include <sstream>24 #include <exception>25

26 #include "intext.hh"27

28 using namespace std;29

30 /** A elaborated template class for rational numbers. As far as possible31 * any class rat<INT> should work given a sufficient class INT for32 * integral values.33 */34

35 template<typename T>36 class rat37 {38 private:39 // STL::pair has no real benefits for fractions40 T num, den; ///< numerator and denominator with d > 041 int cmp (const rat b) const42 { T h; h = this->num * b.den - this->den * b.num;43 if (h > T(0)) return 1;44 if (h < T(0)) return -1;45 return 0;46 }47 void emergencyStop (int i) const;48 public:49 // Konstruktoren und Destruktoren50 rat () : num (0), den (1) { } ///<argumentless constructor generates value zero51 rat (int a) : num (a), den (1) { }52 rat (int, int);53 rat (T a) : num (a), den (1) { }54 rat (T, T);55 rat (const char *);

Page 50: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

50 rat.hh, 27.2.2017 14:13:56

56 rat (const std::string);57

58 // The big three copy ctor, dtor, op=59 rat (const rat & b) : num (b.num), den (b.den) {}60 rat (rat & b) : num (b.num), den (b.den) {}61 ~rat () {}62 rat & operator= (const rat & b);63

64 // access methods65 T numerator () const { return this->num; }66 T denominator () const { return this->den; }67

68 // cast operators (except bool)69 operator long () const70 { if (den != T(1)) emergencyStop (1); return (long) this->num; }71 operator long double () const72 { return (long double) this->num / (long double) this->den; }73 std::string stringz () const;74 std::string stringn () const;75 operator std::string () const;76

77 // bool operators78 bool operator ! () const { return this->num == T(0); } // ! a79 operator bool () const { return this->num != T( 0); }80

81 // member operators with private access82 rat operator ++ (int) { rat<T> h(*this); this->num += this->den; return h; } // a ++83 rat operator -- (int) { rat<T> h(*this); this->num -= this->den; return h; } // a --84 rat operator ++ () { this->num += this->den; return *this; } // ++ a85 rat operator -- () { this->num -= this->den; return *this; } // -- a86

87 rat operator + () const { return *this; } // + a88 rat operator - () const { rat h(*this); h.num = - h.num; return h; }89 // - a90 rat operator += (const rat b) { this->num = this->num * b.den + this->den * b.num; this->den *= b.den; intx_simplify (num, den); return *this; } // a += b91 rat operator -= (const rat b) { this->num = this->num * b.den - this->den * b.num; this->den *= b.den; intx_simplify (num, den); return *this; } // a -= b92 rat operator *= (const rat b) { this->num *= b.num; this->den *= b.den; intx_simplify (num, den); return *this; } // a *= b93 rat operator /= (const rat b) { if (b.num == T(0)) emergencyStop (2); this->num *= b.den; den *= b.num; if (den < T(0)) {this->num = -this->num; den = -den;} intx_simplify (num, den); return *this; }94 // a /= b95 bool operator < (const rat b) const { return cmp (b) < 0; } // a < b96 bool operator == (const rat b) const { return cmp (b) == 0; } // a == b97 bool operator > (const rat b) const { return cmp (b) > 0; } // a > b98 bool operator <= (const rat b) const { return cmp (b) <= 0; } // a <= b99 bool operator != (const rat b) const { return cmp (b) != 0; } // a != b100 bool operator >= (const rat b) const { return cmp (b) >= 0; } // a >= b101

102 // stream inserters103 template<typename TT>104 friend std::ostream & operator << (std::ostream &, rat<TT>);105 template<typename TT>106 friend std::istream & operator >> (std::istream &, rat<TT> &);107

108 // member functions with private access109 void abs () { if (this->num < T(0)) { this->num = - this->num; } }110 void neg () { this->num = - this->num; }111 };112

113 // global operators without private access114 template<typename T>115 inline rat<T> operator + (const rat<T> a, const rat<T> b) { rat<T> h(a); h += b; return h; }116 template<typename T>117 inline rat<T> operator - (const rat<T> a, const rat<T> b) { rat<T> h(a); h -= b; return h; }118 template<typename T>119 inline rat<T> operator * (const rat<T> a, const rat<T> b) { rat<T> h(a); h *= b; return h; }120 template<typename T>121 inline rat<T> operator / (const rat<T> a, const rat<T> b) { rat<T> h(a); h /= b; return h; }122

123 // global functions without private access124 template<typename T>125 inline rat<T> abs (const rat<T> a) { rat<T> h (a); h.abs (); return h; }126 template<typename T>127 inline rat<T> neg (const rat<T> a) { rat<T> h (a); h.neg (); return h; }128

129 class RationalException : std::exception130 {131 };132

133 // error exit function

Page 51: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

rat.hh, 27.2.2017 14:13:56 51

134 template<typename T>135 void rat<T>::emergencyStop (int i) const136 { std::cout << std::endl << "+++ Error in arithmetic with rational numbers; error number: " << i << std::endl;137 throw new RationalException;138 }139

140 // Operatoren fuer rat, die auf private member zugreifen141 template<typename T>142 rat<T>::rat (int a, int b) : num (a), den (b)143 { if (!b) emergencyStop (3);144 if (b < 0) { this->num = -this->num; this->den = -this->den; }145 intx_simplify (num, den);146 }147

148 /*149 template<typename T>150 rat<T>::rat (T a, T b)151 { if (!b) emergencyStop (4);152 if (b < T(0)) { a = - a; b = - b; }153 num = a; den = b; intx_simplify (num, den);154 }155 */156

157 template<typename T>158 rat<T> & rat<T>::operator= (const rat<T> & b)159 {160 if (this != &b)161 {162 // dtor163 // ctor164 this->num = b.num;165 this->den = b.den;166 }167 return *this;168 }169

170 template<typename T>171 std::string rat<T>::stringz () const172 {173 std::ostringstream h;174 std::string t;175

176 h << this->num;177 t = h.str ();178

179 return t;180 }181

182 template<typename T>183 std::string rat<T>::stringn () const184 {185 std::ostringstream h;186 std::string t;187

188 h << this->den;189 t = h.str ();190

191 return t;192 }193

194 template<typename T>195 rat<T>::operator std::string () const196 {197 std::ostringstream h;198 std::string t;199

200 h << this->num;201 if (this->den != T(1))202 { h << ':';203 h << this->den;204 }205 t = h.str ();206

207 return t;208 }209

210 template<typename T>211 std::ostream & operator << (std::ostream & s, rat<T> b)212 { std::ostream::sentry se(s);

Page 52: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

52 rat.hh, 27.2.2017 14:13:56

213 if (se)214 { std::ios::fmtflags f = s.setf (ios::right, ios::adjustfield);215 std::ostringstream h;216 std::string t;217

218 h << b.num;219 if (b.den != T (1))220 { h << ':';221 h << b.den;222 }223 t = h.str ();224

225 s << t;226

227 s.flags (f);228 }229 return s;230 }231

232 template<typename T>233 std::istream & operator >> (std::istream & s, rat<T> & b)234 { std::istream::sentry se (s);235 if (se)236 {237 do {238 s >> b.num;239 s >> b.den;240 } while (!b.den);241 if (b.den < T(0)) { b.num = - b.num; b.den = - b.den; }242 intx_simplify (b.num, b.den);243 }244 return s;245 }246

247 #endif248

Datei 96: ratmain.cpp, 29.6.2016 11:57:561 // bruch/ratmain.cpp2 // Testergebnisse: http://www.gutenberg.org/dirs/etext01/brnll10.txt3

4 #include <iostream>5 #include <iomanip>6 #include <cstdlib>7 #include <limits>8

9 #if defined RAT_MINIFLOAT10 #include "ulintmf.h"11 #define INT_T ulintmf12 #elif defined RAT_APFLOAT13 #include "ulintmt.h"14 #define INT_T ulintmt15 #elif defined RAT_APX16 #include "apx.h"17 #define INT_T apx18 #elif defined RAT_GMPX19 #include "gmpx.h"20 #define INT_T gmpx21 #elif defined RAT_GMP22 #include "ulintgmp.h"23 #define INT_T ulintgmp24 #elif defined RAT_NR25 #include "ulintnr.hh"26 #define INT_T ulintnr27 #else28 #define INT_T long29 #endif30

31 #define RAT_T rat<INT_T>32

33 #include "rzeit.h"34 #include "rat.hh"35 #include "intext.hh"36

37 using namespace std;38

39 long double BernoulliLongDouble (int bmax)40 {41 long double * a;42 int n, k;

Page 53: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratmain.cpp, 29.6.2016 11:57:56 53

43 long double s, r;44

45 a = new long double [bmax+1];46

47 a [0] = 1;48 for (n = 1; n <= bmax; n++)49 { s = a [0];50 for (k = 1; k <= n-1; k++)51 {52 s += intx_binom<long double> (n+1, k) * a [k];53 }54 a [n] = - s / intx_binom<long double> (n+1, k);55 }56

57 r = a [bmax];58 delete [] a;59 return r;60 }61

62 void Bernoulli (int bmax, int & anz, int print)63 { volatile int nn;64 volatile long n, k;65 RAT_T * a;66 RAT_T s;67 double t;68

69 a = new RAT_T [bmax];70

71 cerr << "Bernoulli-Messung, anz=" << anz << ", bmax=" << bmax;72

73 t = RZeit ();74 for (nn = 0; nn < anz; nn++)75 { a [0] = RAT_T (1);76 for (n = 1; n < bmax; n++)77 { s = a [0];78 for (k = 1; k <= n-1; k++)79 {80 s += RAT_T (intx_binom (INT_T (n+1), INT_T (k))) * a [k];81 }82 a [n] = - s / RAT_T (intx_binom (INT_T (n+1), INT_T (k)));83 } }84 t = RZeit () - t;85

86 cerr << ", time = " << t << "/" << anz << "=" << (t/anz) << endl;87

88 if (print || bmax < 40)89 {90 cout << "Bernoulli-Zahlen " << endl;91 for (n = 0; n < bmax; n++)92 { cout << n << ": " << setw (20) << setprecision (15) << (long double) a [n]93 << " = " << setw (20) << a [n] << endl;94 }95 }96 cout << endl << "Verbrauchte Gesamtzeit: " << t << flush;97

98 t /= anz;99 cout << endl << "Verbrauchte Zeit pro B0-B" << bmax << ": " << t << flush;100 cout << endl << "anz = " << anz << ", bmax = " << bmax << endl << flush;101

102 if (t*anz > 3) { anz /= 10; if (anz <= 0) anz = 1; }103

104 // Check the results105 for (n = 0; n < bmax; n++)106 {107 if ((long double) a [n] == BernoulliLongDouble (n)) break;108 if (a [n] == RAT_T (0))109 {110 if (BernoulliLongDouble (n) <= numeric_limits<long double> :: epsilon ()) break;111

112 cout << "+++ Fehler; n = " << n << "; a [n] = " << a [n] << "; ld = " << BernoulliLongDouble (n) << endl;113 exit (1);114 }115 long double h;116 h = (long double) a [n];117 h /= BernoulliLongDouble (n);118 h -= 1;119 if (h < 0) h = - h;120 if (h > numeric_limits<long double> :: epsilon ())

Page 54: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

54 ratmain.cpp, 29.6.2016 11:57:56

121 {122 cout << "+++ Fehler; n = " << n << "; a [n] = " << a [n] << "; ld = " << BernoulliLongDouble (n) << endl;123 exit (1);124 }125 }126 cout << endl << "results checked" << endl;127 delete [] a;128 }129

130 int main (int argc, char * argv [])131 {132 RAT_T a, b (35, 49), c, d;133 long double x;134

135 cout << "a = " << a << endl;136 cout << "b = " << b << endl;137

138 cout << "Gib Bruch: " << flush;139 cin >> a;140

141 cout << "a (gelesen) = " << a << " = " << a.numerator () << ":" << a.denominator () << endl;142 cout << "b (vorbesetzt) = " << b << " = " << b.numerator () << ":" << b.denominator () << endl;143 cout << "a + b = " << a << " + " << b << " = " << a + b << endl;144 cout << "a - b = " << a << " - " << b << " = " << a - b << endl;145 cout << "a * b = " << a << " * " << b << " = " << a * b << endl;146 cout << "a / b = " << a << " / " << b << " = " << a / b << endl;147

148 a = RAT_T (31415926, 27182818);149 d = c = a + b;150 cout << " d = c = a + b = " << a << " + " << b << " = " << c << " = " << d << endl;151 x = c;152 cout.width (20);153 cout.precision (15);154 cout << "x = c = " << x << endl;155

156 c += 1;157 cout << "c = " << c << endl;158 x = c;159 cout.width (20);160 cout.precision (15);161 cout << "x = c = " << x << endl;162

163 b = RAT_T (2, 3);164 c += b;165 cout << "c = " << c << endl;166 x = c;167 cout.width (20);168 cout.precision (15);169 cout << "x = c = " << x << endl;170

171 b = RAT_T (12, 6);172 cout << "b = " << b << endl;173 cout << "(long) b = " << (long) b << endl;174

175 // Berechnung der Bernoullizahlen176

177 int bmax, anz, i;178 bmax = 19;179 anz = 1;180 if (argc > 1) { bmax = atoi (argv [1]); }181 if (argc > 2) { anz = atoi (argv [2]); }182 if (bmax < 19) bmax = 19;183 if (anz < 1) anz = 1;184 for (i = 19; i <= bmax; i += 2)185 { Bernoulli (i, anz, i == bmax);186 }187 }188

Datei 97: rzeit.h, 29.6.2016 11:57:561 // bruch/rzeit.h2 #if ! defined _RZEIT_H3

4 #define _RZEIT_H5

6 #ifdef __cplusplus7 extern "C" {8 #endif9

Page 55: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintmt.h, 29.6.2016 11:57:56 55

10 double RZeit ();11

12 #ifdef __cplusplus13 }14 #endif15

16 #endif17

Datei 98: rzeit.c, 29.6.2016 11:57:561 // bruch/rzeit.c2

3 #include <time.h>4 #include <stdlib.h>5 #include "rzeit.h"6

7 double RZeit (void)8 { clock_t t;9 t = clock ();10 if (t == (clock_t) -1)11 { // cout << "\nZeitmessung nicht durchfuehrbar\n";12 exit (1);13 }14 return (double) t / (double) CLOCKS_PER_SEC;15 }16

Datei 99: ulintmt.h, 29.6.2016 11:57:561 // bruch/ulintmt.h2 #if ! defined _ULINTMT_H3

4 #define _ULINTMT_H5

6 #include "apint.h"7 // http://www.apfloat.org/8 // Apfloat is a High Performance Arbitrary Precision Arithmetic Package for C++ and Java9 // by Mikko Tommila10

11 class ulintmt {12 private:13 //14 apint l;15 public:16 // Konstruktoren und Destruktoren17 ulintmt () { l = 0; } // Neu definierte Variable sind 018 ulintmt (const long a) { l = a; } // oder vorbesetzt mit long int19 // ulintmt (const char *); // oder vorbesetzt mit Dezimalzahl20 // besser waere ulintmt (const string);21 // Konversionen in andere Typen22 operator long () const;23 operator double () const;24 operator long double () const;25 // Operatoren fuer ulintmt, die auf private member zugreifen muessen26 ulintmt operator ++ (int) { ulintmt h; h = *this; l++; return h; } // a ++27 ulintmt operator -- (int) { ulintmt h; h = *this; l--; return h; } // a --28 ulintmt operator ++ () { l++; return *this; } // ++ a29 ulintmt operator -- () { l--; return *this; } // -- a30 ulintmt operator + () const { return *this; } // + a31 ulintmt operator - () const { ulintmt h; h = *this; h.l = -h.l; return h; }32 // - a33 bool operator ! () const { return l == 0; } // ! a34

35 ulintmt operator += (ulintmt b) { l += b.l; return *this; } // a += b36 ulintmt operator -= (ulintmt b) { l -= b.l; return *this; } // a -= b37 ulintmt operator *= (ulintmt b) { l *= b.l; return *this; } // a *= b38 ulintmt operator /= (ulintmt b) { l /= b.l; return *this; } // a /= b39 ulintmt operator %= (ulintmt b) { l %= b.l; return *this; } // a %= b40

41 bool operator < (ulintmt b) const { return l < b.l; } // a < b42 bool operator == (ulintmt b) const { return l == b.l; } // a == b43 bool operator > (ulintmt b) const { return l > b.l; } // a > b44 bool operator <= (ulintmt b) const { return l <= b.l; } // a <= b45 bool operator != (ulintmt b) const { return l != b.l; } // a != b46 bool operator >= (ulintmt b) const { return l >= b.l; } // a >= b47

48 // Ein- und Ausgabe49 friend std::ostream & operator << (std::ostream &, const ulintmt &); // s << a50 friend std::istream & operator >> (std::istream &, ulintmt &); // s >> a

Page 56: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

56 ulintmt.h, 29.6.2016 11:57:56

51 };52

53 // Operatoren fuer ulintmt, die nicht auf private member zugreifen54 inline ulintmt operator + (const ulintmt a, const ulintmt b) { ulintmt h; h = a; h += b; return h; }55 inline ulintmt operator - (const ulintmt a, const ulintmt b) { ulintmt h; h = a; h -= b; return h; }56 inline ulintmt operator * (const ulintmt a, const ulintmt b) { ulintmt h; h = a; h *= b; return h; }57 inline ulintmt operator / (const ulintmt a, const ulintmt b) { ulintmt h; h = a; h /= b; return h; }58 inline ulintmt operator % (const ulintmt a, const ulintmt b) { ulintmt h; h = a; h %= b; return h; }59

60 ulintmt ggt (ulintmt a, ulintmt b);61 ulintmt binom (ulintmt n, ulintmt k);62 void Kuerz (ulintmt & x, ulintmt & y);63

64 #endif65

Datei 100: apx.h, 29.6.2016 11:57:56

1 // bruch/apx.h2 // apx.h: apint.h extended with missing members3

4 #if ! defined _APX_H5

6 #define _APX_H7

8 #include <string>9 #include <stack>10 #include <iostream>11 #include <cstdlib>12

13 #include "ap.h"14 #include "apint.h"15

16 class apx : public apint17 {18 public:19 apx () : apint () { }20 apx (int a) : apint (a) { }21

22 // The big three copy ctor, dtor, op=23 apx (const apx & b) : apint (b) {}24 apx (apx & b) : apint (b) {}25

26 // no dtor ~apx () please27 apx & operator= (const apx & b) { (*((apint *) this)) = (apint) b; return *this; }28 apx & operator= (const apint & b) { (*((apint *) this)) = (apint) b; return *this; }29

30 // bool conversion (differently declared in apint)31 operator bool () const { if (*((apint*) this) != apint (0)) return true; return false; }32 bool operator ! () const { if (*((apint*) this) == apint (0)) return true; return false; }33

34 // Bit conversion35 operator std::stack<bool> () const;36 apx (std::stack<bool>);37

38 // other conversions39 operator long () const;40 operator long double () const;41

42 // Ein- und Ausgabe43 friend std::ostream & operator << (std::ostream & s, const apx & b);44 friend std::istream & operator >> (std::istream & s, apx & b);45 };46

47 std::ostream & operator << (std::ostream & s, const apx & b)48 { std::ostream::sentry se(s);49 if (se)50 {51 s << (apint) b;52 }53 return s;54 }55

56 std::istream & operator >> (std::istream & s, apx & b)57 { std::istream::sentry se (s);58 if (se)59 {60 std::string st;61 s >> st;

Page 57: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

apx.h, 29.6.2016 11:57:56 57

62 b = apint ((char*)st.c_str ());63 }64 return s;65 }66

67 apx::operator std::stack<bool> () const68 {69 std::stack<bool> s;70 apint a (*((apint*)this));71

72 // stack: empty() size() top() push(true) pop()73

74 if (a.sign () < 0)75 { s.push(true);76 a = -a;77 }78 else79 { s.push(false);80 }81

82 while (a != 0)83 {84 if (a % apint (2) != 0)85 { s.push(true);86 }87 else88 { s.push(false);89 }90 a /= apint (2);91 }92

93 apx b (s);94 if (*((apint*)this) != (apint)b)95 {96 std::cout << "Fehler" << std::endl;97 std::exit (1);98 }99 return s;100 }101

102 apx::apx (std::stack<bool> s) : apint ()103 {104 bool bit (false);105

106 (*(apint*)this) = 0;107 while (!s.empty())108 {109 bit = s.top();110 s.pop();111 if (s.empty()) break;112

113 *((apint*)this) *= apint(2);114 if (bit) (*((apint*)this)) ++;115 }116 if (bit) *((apint*)this) = - *((apint*)this);117 }118

119 apx::operator long () const120 {121 bool bit (false);122 std::stack<bool> s;123 s = (std::stack<bool>) (*this);124 long l;125 l = 0;126 while (!s.empty())127 {128 bit = s.top();129 s.pop();130 if (s.empty()) break;131

132 l *= 2;133 if (bit) l++;134 }135 if (bit) l = - l;136 return l;137 }138

139 apx::operator long double () const

Page 58: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

58 apx.h, 29.6.2016 11:57:56

140 {141 bool bit (false);142 std::stack<bool> s;143 s = (std::stack<bool>) (*this);144 long double l;145 l = 0;146 while (!s.empty())147 {148 bit = s.top();149 s.pop();150 if (s.empty()) break;151

152 l *= 2;153 if (bit) l++;154 }155 if (bit) l = - l;156 return l;157 }158

159 #endif160

Datei 101: ulintgmp.h, 29.6.2016 11:57:561 // bruch/ulintgmp.h2 #if ! defined _ULINTGMP_H3

4 #define _ULINTGMP_H5

6 #include <cstring>7 #include <string>8

9 using namespace std;10

11 #include "gmp.h"12

13 class ulintgmp {14 private:15 //16 mpz_t l;17 void ii () { mpz_init (l); }18 void cl () { mpz_clear (l); }19 void incr () { mpz_t h1, h2; mpz_init (h1); mpz_init (h2); mpz_set_si (h1, 1); mpz_add (h2, l, h1); mpz_set (l, h2); mpz_clear (h1); mpz_clear (h2); }20 void decr () { mpz_t h1, h2; mpz_init (h1); mpz_init (h2); mpz_set_si (h1, 1); mpz_sub (h2, l, h1); mpz_set (l, h2); mpz_clear (h1); mpz_clear (h2); }21 public:22 void neg () { mpz_t h1; mpz_init (h1); mpz_neg (h1, l); mpz_set (l, h1); mpz_clear (h1); }23

24 // Konstruktoren und Destruktoren25 ulintgmp () { ii (); mpz_set_si (l, 0); }26 ulintgmp (const long a) { ii (); mpz_set_si (l, a); }27 // ulintgmp (const char *); // oder vorbesetzt mit Dezimalzahl28 // ulintgmp (const string s);29 // The big three30 ulintgmp (const ulintgmp & b) { ii (); mpz_set (l, b.l); }31 ~ulintgmp () { cl (); }32 ulintgmp & operator= (const ulintgmp & b);33 // Konversionen in andere Typen34 operator long () const { return mpz_get_si (l); }35 operator double () const { return mpz_get_d (l); }36 operator long double () const { return mpz_get_d (l); }37 operator string () const;38 operator bool () const { return mpz_sgn (l) != 0; } // ! a39

40 // Operatoren fuer ulintgmp, die auf private member zugreifen muessen41 ulintgmp operator ++ (int) { ulintgmp h; h = *this; incr (); return h; } // a ++42 ulintgmp operator -- (int) { ulintgmp h; h = *this; decr (); return h; } // a --43 ulintgmp operator ++ () { incr (); return *this; } // ++ a44 ulintgmp operator -- () { decr (); return *this; } // -- a45

46 ulintgmp operator + () const { return *this; } // + a47 ulintgmp operator - () const { ulintgmp h; h = *this; h.neg (); return h; }48 // - a49 bool operator ! () const { return mpz_sgn (l) == 0; } // ! a50

51 ulintgmp operator + (ulintgmp b) const { ulintgmp h; mpz_add (h.l, this->l, b.l); return h; }52 ulintgmp operator - (ulintgmp b) const { ulintgmp h; mpz_sub (h.l, this->l, b.l); return h; }53 ulintgmp operator * (ulintgmp b) const { ulintgmp h; mpz_mul (h.l, this->l, b.l); return h; }54 ulintgmp operator / (ulintgmp b) const { ulintgmp h; mpz_cdiv_q (h.l, this->l, b.l); return h; }55 ulintgmp operator % (ulintgmp b) const { ulintgmp h; mpz_cdiv_r (h.l, this->l, b.l); return h; }

Page 59: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

gmpx.h, 29.6.2016 11:57:58 59

56

57 ulintgmp operator += (ulintgmp b) { ulintgmp h; mpz_add (h.l, this->l, b.l); mpz_set (this->l, h.l); return *this; }58 ulintgmp operator -= (ulintgmp b) { ulintgmp h; mpz_sub (h.l, this->l, b.l); mpz_set (this->l, h.l); return *this; }59 ulintgmp operator *= (ulintgmp b) { ulintgmp h; mpz_mul (h.l, this->l, b.l); mpz_set (this->l, h.l); return *this; }60 ulintgmp operator /= (ulintgmp b) { ulintgmp h; mpz_fdiv_q (h.l, this->l, b.l); mpz_set (this->l, h.l); return *this; }61 ulintgmp operator %= (ulintgmp b) { ulintgmp h; mpz_fdiv_r (h.l, this->l, b.l); mpz_set (this->l, h.l); return *this; }62

63 bool operator < (ulintgmp b) const { return mpz_cmp (l, b.l) < 0; }64 bool operator == (ulintgmp b) const { return mpz_cmp (l, b.l) == 0; }65 bool operator > (ulintgmp b) const { return mpz_cmp (l, b.l) > 0; }66 bool operator <= (ulintgmp b) const { return mpz_cmp (l, b.l) <= 0; }67 bool operator != (ulintgmp b) const { return mpz_cmp (l, b.l) != 0; }68 bool operator >= (ulintgmp b) const { return mpz_cmp (l, b.l) >= 0; }69

70 // Ein- und Ausgabe71 friend std::ostream & operator << (std::ostream &, const ulintgmp &); // s << a72 friend std::istream & operator >> (std::istream &, ulintgmp &); // s >> a73

74 void abs () { if (mpz_sgn (this->l) >= 0) return; neg (); }75 };76

77 ulintgmp ggt (ulintgmp a, ulintgmp b);78 ulintgmp binom (ulintgmp n, ulintgmp k);79 void Kuerz (ulintgmp & x, ulintgmp & y);80

81 #endif82

Datei 102: gmpx.h, 29.6.2016 11:57:581 // bruch/gmpx.h2 // gmpx.h: gmp.h extended with missing members3

4 #if ! defined _GMPX_H5

6 #define _GMPX_H7

8 #include <iostream>9 #include <stack>10

11 #include "gmp.h"12 #include "gmpxx.h"13

14 class gmpx : public mpz_class15 {16 public:17 gmpx () : mpz_class () { }18 gmpx (int a) : mpz_class (a) { }19

20 // The big three copy ctor, dtor, op=21 gmpx (const gmpx & b) : mpz_class (b) {}22 gmpx (gmpx & b) : mpz_class (b) {}23

24 // no dtor ~gmpx () please25 gmpx & operator= (const gmpx & b) { (*((mpz_class *) this)) = (mpz_class) b; return *this; }26 gmpx & operator= (const mpz_class & b) { (*((mpz_class *) this)) = (mpz_class) b; return *this; }27

28 // bool conversion (differently declared in mpz_class)29 operator bool () const { if (*((mpz_class*) this) != mpz_class (0)) return true; return false; }30 bool operator ! () const { if (*((mpz_class*) this) == mpz_class (0)) return true; return false; }31

32 // other conversions33 operator long () const;34 operator long double () const;35

36 // Ein- und Ausgabe37 friend std::ostream & operator << (std::ostream & s, const gmpx & b);38 friend std::istream & operator >> (std::istream & s, gmpx & b);39 };40

41 // friend input and output operators must be written42 std::ostream & operator << (std::ostream & s, const gmpx & b)43 { std::ostream::sentry se(s);44 if (se)45 {46 s << (mpz_class) b;47 }48 return s;49 }

Page 60: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

60 gmpx.h, 29.6.2016 11:57:58

50

51 std::istream & operator >> (std::istream & s, gmpx & b)52 { std::istream::sentry se (s);53 if (se)54 {55 std::string st;56 s >> st;57 b = mpz_class ((char*)st.c_str ());58 }59 return s;60 }61

62 gmpx::operator long () const63 {64 return this->get_si ();65

66 }67

68 gmpx::operator long double () const69 {70 double l;71 long double ld;72 l = this->get_d ();73 //std::cout << " D" << l << " ";74 ld = static_cast<long double>(l);75 //std::cout << " LD" << ld << " " << sizeof (l) << " " << sizeof (ld);76 return ld;77 }78

79 #endif80

Datei 103: ulintnr.hh, 29.6.2016 11:57:561 // bruch/ulintnr.h2 #if ! defined _ULINTNR_H3

4 #define _ULINTNR_H5

6 #include <string>7 #include <cstring>8

9 extern "C" {10 #include "nr.h"11 #include "nrutil.h"12 #include "nrmpx.h"13 }14

15 // to do: references to gain speed16 // const correctness17

18 class ulintnr19 {20 // 0 <= p <= 127; 0 <= x <= 255; 128 <= n <= 255; m = adig | udig21 // | 0 | 0 | ... | p | x | ... | x |22 // |255|255| ... | n | x | ... | x |23 // digs -> | 0 | 1 | ... | | | ... |m-1| adig24 // sdig ---------------> | 0 | 1 | ... |m-1| udig25 // adig - udig == sdig - digs26 //27 // elementary principle:28 // (xdig, adig) and (sdig, udig) both are correct NR integers29 // both have the same value including the sign30 // udig <= adig31 // udig == 0 means value 032 //33 // based on routines in NR34 // mpadd (w, u, v, n); w[1_n+1] = u[1_n] + v[1_n]35 // mpsub (&is, w, u, v, n); w[1_n] = u[1_n] - v[1_n], is = w<0 ? -1 : 036 // mpsad (w, u, n, iv); w[1_n+1] = u[1_n] + iv37 // mpsmu (w, u, n, iv); w[1_n+1] = u[1_n] * iv38 // mpsdv (w, u, n, iv, &ir); w[1_n] = u[1_n] / iv with remainder ir39 // mpneg (u, n); u[1_n] = -u[1_n]40 // mpmov (u, v, n); u[1_n] = v[1_n]41 // mplsh (u, n); u[1_n] = u[2_n+1]42 // mpmul (w, u, v, n, m); w[1_n+m] = u[1_n] * v[1_m]43 // mpinv (u, v, n, m); u[1._n] = 1 / v[1._m]44 // mpdiv (q, r, u, v, n, m); w[1_n-m+1] = u[1_n] / v[1_m] with remainder r[1_m]45 // mpsqrt (w, u, v, n, m); w[1._n] = sqrt (v[1._m])

Page 61: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintnr.hh, 29.6.2016 11:57:56 61

46 // u[.1_n] = 1 / sqrt (v[1._m])47 // mp2dfr (a, s, n, &m); s[1_m] = a[.1_n] destroying a48

49 // based on further necessary extensions50 // w = mpfirst (u, n); w = first nonzero of u[1_n] or u+n51 // if (mpiszero (u, n)) u[1_n] == 052 // s = mpsign (u, n); s = -1/0/+153 // s = mpsgn (u, n); s = 255/054 // mpval (u, v, n, m); u[1_n] = v[1_m] for v < 0 and v >= 055 // mpsvl (u, n, iv); u[1_n] = iv56

57

58 private:59 mutable unsigned char * xdig; // extended digits to base 256 with most significant left60 mutable unsigned char * sdig; // significant digits to base 256 with most significant left61 mutable int adig; // allocated digits62 mutable int udig; // used (significant) digits63

64 static int debug;65 static int completeout;66

67 void cp (unsigned char * d, int u);68 // *this undefined; *this = copy of d[1_u]69 void cl (); // *this defined; delete memory and set *this= 070

71 void incr ();72 void decr ();73

74 void shrink () const; // *this defined; reduce *this to minimal memory75 void extend (int n) const;76 // *this defined; extend memory to n chars77 int cmp (ulintnr b) const;78 int sign () const;79

80 public:81 // Konstruktoren und Destruktoren82 ulintnr () : xdig ((unsigned char*)0), sdig ((unsigned char*)0), adig (0), udig (0) { }83 // ulintnr (long i);84 ulintnr (long long i);85 ulintnr (const std::string);86

87 // The big three88 ulintnr (const ulintnr & b) { cp (b.sdig, b.udig); }89 ~ulintnr () { cl (); }90 const ulintnr & operator= (const ulintnr & b)91 { if (this != &b) { cl (); cp (b.sdig, b.udig); }92 return *this;93 }94

95 // Konversionen in andere Typen96 operator long () const;97 operator long double () const;98 operator std::string () const;99 operator bool () const { return sign () != 0; } // if (a)100

101 void neg () { extend (udig+1); mpneg (sdig, udig); shrink(); }102 void abs () { if (mpsign (sdig, udig) >= 0) return; neg (); }103

104 // Operatoren fuer ulintnr, die auf private member zugreifen muessen105 ulintnr operator++(int) { ulintnr h(*this); incr(); return h; } // a ++106 ulintnr operator--(int) { ulintnr h(*this); decr(); return h; } // a --107 ulintnr operator++() { incr(); return *this; } // ++ a108 ulintnr operator--() { decr(); return *this; } // -- a109

110 ulintnr operator+() const { return *this; } // + a111 ulintnr operator-() const { ulintnr h(*this); h.neg (); return h; }112 // - a113 bool operator!() const { return sign () == 0; } // ! a114

115 ulintnr operator+(ulintnr b) const { ulintnr h (*this); h += b; return h; }116 ulintnr operator-(ulintnr b) const { ulintnr h (*this); h -= b; return h; }117 ulintnr operator*(ulintnr b) const { ulintnr h (*this); h *= b; return h; }118 ulintnr operator/(ulintnr b) const { ulintnr h (*this); h /= b; return h; }119 ulintnr operator%(ulintnr b) const { ulintnr h (*this); h %= b; return h; }120

121 ulintnr operator+=(const ulintnr b);122 ulintnr operator-=(const ulintnr b);123 ulintnr operator*=(const ulintnr b);

Page 62: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

62 ulintnr.hh, 29.6.2016 11:57:56

124 ulintnr operator/=(const ulintnr b);125 ulintnr operator%=(const ulintnr b);126

127 bool operator < (ulintnr b) const { return cmp (b) < 0; }128 bool operator == (ulintnr b) const { return cmp (b) == 0; }129 bool operator > (ulintnr b) const { return cmp (b) > 0; }130 bool operator <= (ulintnr b) const { return cmp (b) <= 0; }131 bool operator != (ulintnr b) const { return cmp (b) != 0; }132 bool operator >= (ulintnr b) const { return cmp (b) >= 0; }133

134 // Ein- und Ausgabe135 friend std::ostream & operator << (std::ostream &, const ulintnr &); // s << a136 friend std::istream & operator >> (std::istream &, ulintnr &); // s >> a137 };138

139 #endif140

Datei 104: ulintnr.cpp, 29.6.2016 11:57:561 // bruch/ulintnr.cpp2 #include <iostream>3 #include <string>4 #include <cstdlib>5

6 #include "ulintnr.hh"7

8 int ulintnr::debug = 0;9 int ulintnr::completeout = 1;10

11 // *this is empty (as in a constructor or after cl()-ear) and will be filled12 // with a copy of the arguments13

14 void ulintnr::cp (unsigned char * d, int u)15 {16 adig = udig = u;17 xdig = sdig = (unsigned char *) 0;18 if (u != 0)19 {20 xdig = sdig = cvector (1, u);21 mpmov (xdig, d, u);22 }23 }24

25 // *this has a valid value, which will be deleted26

27 void ulintnr::cl ()28 {29 if (adig != 0) free_cvector (xdig, 1, adig);30 }31

32 // *this has a valid value which will be incremented33

34 void ulintnr::incr ()35 {36 unsigned char * h;37 int s;38 s = mpsign (sdig, udig);39 if (s == 0) { cl (); xdig = sdig = cvector (1, 1); xdig [1] = 1; adig = udig = 1; return; }40 h = cvector (1, udig+1);41 mpsad (h, sdig, udig, 1);42 if (s < 0) h [1] = mpsgn (h+1, udig);43 free_cvector (xdig, 1, adig);44 adig = udig = udig+1;45 xdig = sdig = h;46 shrink ();47 }48

49 // *this has a valid value which will be decremented50

51 void ulintnr::decr ()52 {53 neg();54 incr();55 neg();56 }57

58 // *this has a valid value which will be reduced in place59 // to the minimal memory space conserving its sign

Page 63: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintnr.cpp, 29.6.2016 11:57:56 63

60

61 void ulintnr::shrink () const62 {63 unsigned char s;64 s = mpsgn (sdig, udig);65 while (udig > 0)66 {67 if (sdig [1] != s) return;68 if (mpsgn (sdig+1, udig-1) != s) return;69 udig--; sdig++;70 }71 }72

73 // *this has a valid value which will be extended to n bytes74

75 void ulintnr::extend (int n) const76 {77 unsigned char * h;78 unsigned char s;79 if (debug) std::cout << "ext" << std::endl;80 if (debug) std::cout << *this << std::endl;81

82 if (n > adig)83 {84 h = cvector (1, n);85 mpval (h, sdig, n, udig);86 free_cvector (xdig, 1, adig);87 xdig = sdig = h;88 adig = udig = n;89 return;90 }91 if (n > udig)92 {93 s = mpsgn (sdig, udig);94 mpsvl (xdig+(adig-n), n-udig, s);95 sdig = xdig + (adig-n);96 udig = n;97 return;98 }99 }100

101 // compare *this and b resulting in -1/0/+1 for </==/>102

103 int ulintnr::cmp (ulintnr b) const104 {105 unsigned char * w;106 unsigned char * u;107 unsigned char * v;108 int st, sb;109 int n;110

111 st = sign ();112 sb = b.sign ();113

114 if (debug) std::cout << 'C' << *this << std::endl;115 if (debug) std::cout << 'b' << b << std::endl;116

117 if (sb == 0 && st == 0) { return 0; }118 if (sb == 0) { return sign(); }119 if (st == 0) { return -b.sign(); }120

121 if (debug) std::cout << 'C' << st << ' ' << sb << std::endl;122

123 n = udig; if (b.udig > n) n = b.udig; n++;124 int i;125 if (debug) {for (i = 1; i <= udig; i++) std::cout << ' ' << (int)sdig [i]; std::cout << std::endl;}126 if (debug) {for (i = 1; i <= b.udig; i++) std::cout << ' ' << (int)b.sdig [i]; std::cout << std::endl;}127 w = cvector (1, n+1);128 u = cvector (1, n);129 v = cvector (1, n);130 mpval (u, sdig, n, udig);131 mpval (v, b.sdig, n, b.udig);132 if (debug) {for (i = 1; i <= udig; i++) std::cout << ' ' << (int)sdig [i]; std::cout << std::endl;}133 if (debug) {for (i = 1; i <= b.udig; i++) std::cout << ' ' << (int)b.sdig [i]; std::cout << std::endl;}134 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)u [i]; std::cout << std::endl;}135 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)v [i]; std::cout << std::endl;}136

137 int iv;

Page 64: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

64 ulintnr.cpp, 29.6.2016 11:57:56

138 mpsub (&iv, w+1, u, v, n);139

140 w [1] = iv;141 iv = mpsign (w, n+1);142

143 free_cvector (u, 1, n);144 free_cvector (v, 1, n);145 free_cvector (w, 1, n+1);146

147 return iv;148 }149

150 /* first try of cmp151 if (debug) std::cout << "cmp" << std::endl;152 if (debug) std::cout << *this << std::endl;153 if (debug) std::cout << b << std::endl;154 unsigned char * h;155 int n, is;156 n = udig + 1;157 if (b.udig+1 > n) n = b.udig + 1;158 extend (n);159 b.extend (n);160 if (debug) std::cout << *this << std::endl;161 if (debug) std::cout << b << std::endl;162 h = cvector (1, n);163 mpsub (&is, h, sdig, b.sdig, n);164 n = mpsign (h, n);165 if (debug) std::cout << n << std::endl;166 free_cvector (h, 1, n);167 shrink();168 b.shrink();169 if (debug) std::cout << *this << std::endl;170 if (debug) std::cout << b << std::endl;171 if (debug) std::cout << "cmp end" << std::endl;172 return n;173 */174

175 // compare *this with 0 resulting in -1/0/+1 for <0/==0/>0176

177 int ulintnr::sign () const178 {179 if (udig <= 0) return 0;180 return mpsign (sdig, udig);181 }182

183 // construct ulintnr from long184

185 ulintnr::ulintnr (long long i)186 {187 if (debug) std::cout << "con long long " << i << std::endl;188 int s, k;189 s = 1;190 if (i < 0) { s = -1; i = -i; }191 adig = udig = sizeof (long long) + 1;192 xdig = sdig = cvector (1, adig);193 if (debug) std::cout << *this << std::endl;194 for (k = adig; k >= 1; k--)195 {196 xdig [k] = (unsigned int) (i % 256);197 i /= 256;198 }199 if (debug) std::cout << *this << std::endl;200 if (s < 0) neg ();201 if (debug) std::cout << *this << std::endl;202 shrink ();203 if (debug) std::cout << *this << std::endl;204 }205

206 // construct ulintnr from long207 /*208 ulintnr::ulintnr (long i)209 {210 if (debug) std::cout << "con long " << i << std::endl;211 int s, k;212 s = 1;213 if (i < 0) { s = -1; i = -i; }214 adig = udig = sizeof (long) + 1;215 xdig = sdig = cvector (1, adig);

Page 65: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintnr.cpp, 29.6.2016 11:57:56 65

216 if (debug) std::cout << *this << std::endl;217 for (k = adig; k >= 1; k--)218 {219 xdig [k] = (unsigned int) (i % 256);220 i /= 256;221 }222 if (debug) std::cout << *this << std::endl;223 if (s < 0) neg ();224 if (debug) std::cout << *this << std::endl;225 shrink ();226 if (debug) std::cout << *this << std::endl;227 }228 */229 // *this += b230

231 ulintnr ulintnr::operator+= (const ulintnr b)232 {233 unsigned char * w;234 unsigned char * u;235 unsigned char * v;236 int st, sb;237 int n;238

239 st = sign ();240 sb = b.sign ();241

242 if (debug) std::cout << 'A' << *this << std::endl;243 if (debug) std::cout << 'b' << b << std::endl;244

245 if (sb == 0) { return *this; }246 if (st == 0) { cl (); cp (b.sdig, b.udig); return *this; }247 if (debug) std::cout << 'A' << st << ' ' << sb << std::endl;248

249 n = udig; if (b.udig > n) n = b.udig; n++;250 int i;251 if (debug) {for (i = 1; i <= udig; i++) std::cout << ' ' << (int)sdig [i]; std::cout << std::endl;}252 if (debug) {for (i = 1; i <= b.udig; i++) std::cout << ' ' << (int)b.sdig [i]; std::cout << std::endl;}253 w = cvector (1, n+1);254 u = cvector (1, n);255 v = cvector (1, n);256 mpval (u, sdig, n, udig);257 mpval (v, b.sdig, n, b.udig);258 if (debug) {for (i = 1; i <= udig; i++) std::cout << ' ' << (int)sdig [i]; std::cout << std::endl;}259 if (debug) {for (i = 1; i <= b.udig; i++) std::cout << ' ' << (int)b.sdig [i]; std::cout << std::endl;}260 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)u [i]; std::cout << std::endl;}261 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)v [i]; std::cout << std::endl;}262

263 mpadd (w, u, v, n);264

265 free_cvector (u, 1, n);266 free_cvector (v, 1, n);267

268 cl ();269

270 switch (mpsign (w+1, n))271 {272 case -1: w [1] = 255; break;273 case 0: cp ((unsigned char *) 0, 0); free_cvector (w, 1, n+1); return *this;274 case 1: w [1] = 0; break;275 }276

277 if (debug) {for (i = 1; i <= n+1; i++) std::cout << ' ' << (int)w [i]; std::cout << std::endl;}278

279 xdig = sdig = w;//w280 adig = udig = n+1;//n+1281 // mpadd result has overflow in w [1], so w [1] is 0 or 1 and to be ignored282 if (debug) std::cout << 'A' << *this << std::endl;283

284 if (debug) std::cout << 'A' << *this << std::endl;285 shrink ();286 if (debug) std::cout << 'A' << *this << std::endl;287

288 return *this;289 }290

291 /* first try +=292 ulintnr ulintnr::operator+= (const ulintnr b)293 {

Page 66: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

66 ulintnr.cpp, 29.6.2016 11:57:56

294 unsigned char * h;295 int a, u, n;296 n = udig + 1;297 if (b.udig+1 > n) n = b.udig + 1;298 extend (n);299 b.extend (n);300 h = xdig;301 u = udig;302 a = adig;303 adig = udig = n;304 xdig = sdig = cvector (1, n);305 mpadd (xdig, h+a-u, b.sdig+b.adig-b.udig, n);306 free_cvector (h, 1, a);307 shrink();308 b.shrink();309 return *this;310 }311 */312

313 // *this -= b314

315 ulintnr ulintnr::operator-= (const ulintnr b)316 {317 unsigned char * w;318 unsigned char * u;319 unsigned char * v;320 int st, sb;321 int n;322

323 st = sign ();324 sb = b.sign ();325

326 if (debug) std::cout << 'S' << *this << std::endl;327 if (debug) std::cout << 'b' << b << std::endl;328

329 if (sb == 0) { return *this; }330 if (st == 0) { cl (); cp (b.sdig, b.udig); neg (); return *this; }331 if (debug) std::cout << 'S' << st << ' ' << sb << std::endl;332

333 n = udig; if (b.udig > n) n = b.udig; n++;334 int i;335 if (debug) {for (i = 1; i <= udig; i++) std::cout << ' ' << (int)sdig [i]; std::cout << std::endl;}336 if (debug) {for (i = 1; i <= b.udig; i++) std::cout << ' ' << (int)b.sdig [i]; std::cout << std::endl;}337 w = cvector (1, n+1);338 u = cvector (1, n);339 v = cvector (1, n);340 mpval (u, sdig, n, udig);341 mpval (v, b.sdig, n, b.udig);342 if (debug) {for (i = 1; i <= udig; i++) std::cout << ' ' << (int)sdig [i]; std::cout << std::endl;}343 if (debug) {for (i = 1; i <= b.udig; i++) std::cout << ' ' << (int)b.sdig [i]; std::cout << std::endl;}344 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)u [i]; std::cout << std::endl;}345 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)v [i]; std::cout << std::endl;}346

347 int iv;348 mpsub (&iv, w+1, u, v, n);349

350 w [1] = iv;351 if (debug) {for (i = 1; i <= n+1; i++) std::cout << ' ' << (int)w [i]; std::cout << std::endl;}352

353 free_cvector (u, 1, n);354 free_cvector (v, 1, n);355

356 cl ();357

358 if (mpsign (w, n+1) == 0)359 {360 cp ((unsigned char *) 0, 0); free_cvector (w, 1, n+1); return *this;361 }362 /* ### Korrektur, weil nr nur mit porsitiven Argumenten rechnet */363 if (mpsign (w+1, n) < 0)364 {365 w [1] = 255;366 }367 /* ### Korrektur, weil nr nur mit porsitiven Argumenten rechnet */368 xdig = sdig = w;369 adig = udig = n+1;370 if (debug) std::cout << 'S' << *this << std::endl;371 shrink ();

Page 67: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintnr.cpp, 29.6.2016 11:57:56 67

372 if (debug) std::cout << 'S' << *this << std::endl;373

374 return *this;375 }376

377 /* first try -=378 ulintnr ulintnr::operator -= (const ulintnr b)379 {380 unsigned char * h;381 int a, u, n, is;382 n = udig + 1;383 if (b.udig+1 > n) n = b.udig + 1;384 extend (n);385 b.extend (n);386 h = xdig;387 u = udig;388 a = adig;389 adig = udig = n;390 xdig = sdig = cvector (1, n);391 mpsub (&is, xdig, h+a-u, b.sdig+b.adig-b.udig, n);392 free_cvector (h, 1, a);393 shrink();394 b.shrink();395 return *this;396 }397 */398

399 /* first try *=400 ulintnr ulintnr::operator *= (const ulintnr b)401 {402 std::cout << "*=" << std::endl;403 unsigned char * ht;404 unsigned char * hb;405 int a, u, st, sb;406

407 st = sign ();408 sb = b.sign ();409

410 std::cout << *this << std::endl;411 std::cout << b << std::endl;412

413 if (st == 0 || sb == 0) { cl (); cp ((unsigned char *) 0, 0); return *this; }414

415 ht = sdig;416 u = udig;417 a = adig;418

419 adig = udig = u + b.udig;420 sdig = cvector (1, adig);421 hb = cvector (1, b.udig);422 mpmov (hb, b.sdig, b.udig);423 if (st < 0) mpneg (ht, u);424 if (sb < 0) mpneg (hb, b.udig);425

426 mpmul (sdig, ht, hb, u, b.udig);427 free_cvector (xdig, 1, a);428 free_cvector (hb, 1, b.udig);429 xdig = sdig;430

431 std::cout << *this << std::endl;432

433 if (st * sb < 0) neg ();434

435 return *this;436 }437 */438

439 // *this *= b440

441 ulintnr ulintnr::operator*= (const ulintnr b)442 {443 unsigned char * w;444 unsigned char * u;445 unsigned char * v;446 int st, sb;447 int n, m, nm;448

449 st = sign ();450 sb = b.sign ();

Page 68: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

68 ulintnr.cpp, 29.6.2016 11:57:56

451

452 if (debug) std::cout << 'M' << *this << std::endl;453 if (debug) std::cout << b << std::endl;454

455 if (st == 0 || sb == 0) { cl (); cp ((unsigned char *) 0, 0); return *this; }456

457 n = udig+1;458 m = b.udig+1;459 nm = n + m;460

461 w = cvector (1, nm);462 u = cvector (1, n);463 v = cvector (1, m);464 mpval (u, sdig, n, udig);465 mpval (v, b.sdig, m, b.udig);466

467 if (st < 0) mpneg (u, n);468 if (sb < 0) mpneg (v, m);469

470 mpmul (w, u, v, n, m);471

472 cl ();473

474 xdig = sdig = w;475 adig = udig = nm;476 if (debug) std::cout << 'M' << *this << std::endl;477

478 free_cvector (u, 1, n);479 free_cvector (v, 1, m);480

481 if (st * sb < 0) neg ();482 if (debug) std::cout << 'M' << *this << std::endl;483 shrink ();484 if (debug) std::cout << 'M' << *this << std::endl;485

486 return *this;487 }488

489 // *this /= b490

491 ulintnr ulintnr::operator/= (const ulintnr b)492 {493 unsigned char * q;494 unsigned char * r;495 unsigned char * u;496 unsigned char * v;497 int st, sb;498 int n, m, nm1;499

500 st = sign ();501 sb = b.sign ();502

503 if (debug) std::cout << "D" << *this << std::endl;504 if (debug) std::cout << b << std::endl;505

506 if (sb == 0) { std::cout << "Division by zero" << std::endl; exit (1); return *this; }507 if (st == 0) { cl (); cp ((unsigned char *) 0, 0); return *this; }508

509 n = udig;510 m = b.udig;511 nm1 = n - m + 1;512 if (debug) std::cout << n << " " << m << " " << nm1 << " " << st << " " << sb << std::endl;513

514 if (m > n)515 {516 cl (); cp ((unsigned char *) 0, 0); return *this;517 }518

519 q = cvector (1, nm1);520 r = cvector (1, m);521 u = cvector (1, n);522 v = cvector (1, m);523 mpmov (u, sdig, n);524 mpmov (v, b.sdig, m);525 int i;526 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)u [i]; std::cout << std::endl;}527 if (debug) {for (i = 1; i <= m; i++) std::cout << ' ' << (int)v [i]; std::cout << std::endl;}528

Page 69: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintnr.cpp, 29.6.2016 11:57:56 69

529 if (st < 0) mpneg (u, n);530 if (sb < 0) mpneg (v, m);531 if (debug) {for (i = 1; i <= n; i++) std::cout << ' ' << (int)u [i]; std::cout << std::endl;}532 if (debug) {for (i = 1; i <= m; i++) std::cout << ' ' << (int)v [i]; std::cout << std::endl;}533

534 mpdiv (q, r, u, v, n, m);535 if (debug) {for (i = 1; i <= nm1; i++) std::cout << ' ' << (int)q [i]; std::cout << std::endl;}536 if (debug) {for (i = 1; i <= m; i++) std::cout << ' ' << (int)r [i]; std::cout << std::endl;}537

538 cl ();539

540 xdig = sdig = q;541 adig = udig = nm1;542

543 free_cvector (r, 1, m);544 free_cvector (u, 1, n);545 free_cvector (v, 1, m);546 if (debug) std::cout << "D end " << *this << std::endl;547

548 if (st * sb < 0) { neg (); if (debug) std::cout << "N" << std::endl; }549 if (debug) std::cout << "D end " << *this << std::endl;550 shrink ();551 if (debug) std::cout << "D end " << *this << std::endl;552

553 return *this;554 }555

556 // *this %= b557

558 ulintnr ulintnr::operator%= (const ulintnr b)559 {560 unsigned char * q;561 unsigned char * r;562 unsigned char * u;563 unsigned char * v;564 int st, sb;565 int n, m, nm1;566

567 st = sign ();568 sb = b.sign ();569

570 if (debug) std::cout << "%" << *this << std::endl;571 if (debug) std::cout << b << std::endl;572

573 if (sb == 0) { std::cout << "remainder (division by zero)" << std::endl; exit (1); }574 if (st == 0) { cl (); cp ((unsigned char *) 0, 0); return *this; }575

576 n = udig;577 m = b.udig;578 nm1 = n - m + 1;579

580 if (m > n) // *this = b * 0 + r = r581 {582 return *this;583 }584

585 q = cvector (1, nm1);586 r = cvector (1, m);587 u = cvector (1, n);588 v = cvector (1, m);589 mpmov (u, sdig, n);590 mpmov (v, b.sdig, m);591

592 if (st < 0) mpneg (u, n);593 if (sb < 0) mpneg (v, m);594

595 mpdiv (q, r, u, v, n, m);596

597 cl ();598

599 free_cvector (q, 1, nm1);600 free_cvector (u, 1, n);601 free_cvector (v, 1, m);602 if (debug) std::cout << "%" << *this << std::endl;603

604 if (mpsign (r, m) == 0)605 {606 cp ((unsigned char *) 0, 0); free_cvector (r, 1, m); return *this;

Page 70: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

70 ulintnr.cpp, 29.6.2016 11:57:56

607 }608

609 xdig = sdig = r;610 adig = udig = m;611 if (debug) std::cout << "%" << *this << std::endl;612

613 if (st < 0) neg ();614 if (debug) std::cout << "%" << *this << std::endl;615 shrink ();616 if (debug) std::cout << "%" << *this << std::endl;617

618 return *this;619 }620

621 // s << b622

623 std::ostream & operator << (std::ostream & s, const ulintnr & b)624 { std::ostream::sentry se (s);625 if (se)626 {627 if (ulintnr::completeout)628 {629 s << "[" << b.adig << "." << b.udig;630 s << "." << (void*)b.xdig << "." << (void*)b.sdig;631 for (int i = 1; i <= b.adig; i++) s << "." << (int)b.xdig [i];632 s << "] ";633 }634 unsigned char * h;635 unsigned char * q;636 unsigned char * t;637 int r;638 std::string st;639 std::string st1;640 h = cvector (1, b.udig);641 q = cvector (1, b.udig);642 mpmov (h, b.sdig, b.udig);643 switch (mpsign (h, b.udig))644 {645 case -1:646 st1 += "-"; mpneg (h, b.udig); break;647 case 0: s << "0"; return s;648 }649 while (!mpiszero (h, b.udig))650 {651 mpsdv (q, h, b.udig, 10, &r);652 t = h;653 h = q;654 q = t;655 st += (char) (r + (int) '0');656 }657 std::string::reverse_iterator it;658 for (it = st.rbegin(); it < st.rend(); it++) st1 = st1 + *it;659 s << st1;660

661 if (ulintnr::completeout)662 {663 s << "=";664 mpmov (h, b.sdig, b.udig);665 st = "";666 while (!mpiszero (h, b.udig))667 {668 mpsdv (q, h, b.udig, 10, &r);669 t = h;670 h = q;671 q = t;672 st = st + (char) (r + (int) '0');673 }674 st1 = "";675 for (it = st.rbegin(); it < st.rend(); it++) st1 = st1 + *it;676 s << st1;677 }678

679 free_cvector (q, 1, b.udig);680 free_cvector (h, 1, b.udig);681 }682 return s;683 }684

Page 71: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintnr.cpp, 29.6.2016 11:57:56 71

685 // s >> b686

687 std::istream & operator >> (std::istream & s, ulintnr & b)688 { std::istream::sentry se (s);689 if (se)690 {691 std::string st;692 s >> st;693 b = ulintnr (st);694 if (ulintnr::debug) std::cout << "operator >> b=" << b << std::endl;695 }696 return s;697 }698

699 // construct ulintnr from std::string700

701 ulintnr::ulintnr (const std::string s)702 {703 if (debug) std::cout << "con string" << std::endl;704 ulintnr h;705 ulintnr ten ((long)10);706 long null ('0');707 int v = 0;708 int i; // std::string::iterator it;709 i = 0; // it = s.begin();710 if (i < s.length()) // it < s.end())711 {712 char ch = s [i]; //*it;713 if (ch == '+' || ch == '-')714 {715 if (ch == '-') v = -1;716 i++;717 }718 }719 for (; i < s.length() && s [i] >= '0' && s [i] <= '9'; i++)720 //t < s.end() && *it >= '0' && *it <= '9'; it++)721 {722 if (debug) std::cout << "ST" << s [i] << "/" << ((long)(s[i])-null)<<' ' << h << std::endl;723 h *= ten;724 if (debug) std::cout << "ST" << s [i] << "/" << ((long)(s[i])-null)<<' ' << h << std::endl;725 h += ulintnr ((long)(s [i]) - null); //*it - '0');726 if (debug) std::cout << "ST" << s [i] << "/" << ((long)(s[i])-null)<<' ' << h << std::endl;727 }728 if (v < 0) h.neg();729 cp (h.sdig, h.udig);730

731 if (debug) std::cout << "constring end" << *this << std::endl;732 }733

734 // (long) ulintnr735

736 ulintnr::operator long () const737 {738 if (debug) std::cout << "(long)" << *this << std::endl;739 unsigned char * u;740 int s;741 int n;742 long x;743 int i;744

745 s = sign ();746

747 if (s == 0) { return 0; }748

749 n = udig;750

751 u = cvector (1, n);752 mpmov (u, sdig, n);753

754 if (s < 0) mpneg (u, n);755

756 x = 0;757 for (i = 1; i <= n; i++) x = x * 256 + u [i];758 if (s < 0) x = -x;759

760 return x;761 }762

Page 72: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

72 ulintnr.cpp, 29.6.2016 11:57:56

763 // (long double) ulintnr764

765 ulintnr::operator long double () const766 {767 if (debug) std::cout << "(long double)" << *this << std::endl;768 unsigned char * u;769 int s;770 int n;771 long double x;772 int i;773

774 s = sign ();775

776 if (s == 0) { return 0; }777

778 n = udig;779

780 u = cvector (1, n);781 mpmov (u, sdig, n);782

783 if (s < 0) mpneg (u, n);784

785 x = 0;786 for (i = 1; i <= n; i++) x = x * 256 + u [i];787 if (s < 0) x = -x;788

789 return x;790 }791

792 // (std::string) ulintnr793

794 ulintnr::operator std::string () const795 {796 if (debug) std::cout << "(string )" << *this << std::endl;797 unsigned char * h;798 unsigned char * q;799 unsigned char * t;800 int r;801 std::string st;802

803 h = cvector (1, udig);804 q = cvector (1, udig);805 mpmov (h, sdig, udig);806 if (mpsgn (h, udig) != 0) { st += "-"; mpneg (h, udig); }807 while (!mpiszero (h, udig))808 {809 mpsdv (q, h, udig, 10, &r);810 t = h;811 h = q;812 q = t;813 st += (char) (r + (int) '0');814 }815 std::string::reverse_iterator it;816 std::string st1;817 for (it = st.rbegin(); it < st.rend(); it++) st1 = st1 + *it;818 return st1;819 }820

Datei 105: nrmpx.c, 29.6.2016 11:57:561 // bruch/nrmpx.c2 /* (h, n) = (0.0..0.x.x..x) == (x.x..x) */3 /* 1.2.........n 1....m */4

5 #include "nr.h"6 #include "nrutil.h"7 #include "nrmpx.h"8

9 unsigned char * mpfirst (unsigned char * h, int n)10 {11 while (n > 0)12 {13 h++;14 if (*h != 0) return h - 1;15 n--;16 }17 return h;18 }19

Page 73: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

nrmpx.c, 29.6.2016 11:57:56 73

20 int mpiszero (unsigned char * h, int n)21 {22 unsigned char * t;23 t = mpfirst (h, n);24 if (t < h + n) return 0;25 return 1;26 }27

28 int mpsign (unsigned char * h, int n)29 {30 unsigned char * t;31 if (n <= 0) return 0;32 t = mpfirst (h, n);33 if (t == h)34 if ((t [1] & 128) != 0)35 return -1;36 if (t < h + n) return 1;37 return 0;38 }39

40 unsigned char mpsgn (unsigned char * h, int n)41 {42 unsigned char * t;43 if (n <= 0) return 0;44 t = mpfirst (h, n);45 if (t == h)46 if ((t [1] & 128) != 0)47 return 255;48 return 0;49 }50

51 void mpsvl (unsigned char * u, int n, unsigned char iv)52 {53 while (n > 0) { u++; *u = iv; n--; }54 }55

56 void mpval (unsigned char * u, unsigned char * v, int n, int m)57 {58 unsigned char s;59 if (n <= m) { mpmov (u, v, n); return; }60 s = mpsgn (v, m);61 mpmov (u+(n-m), v, m);62 mpsvl (u, n-m, s);63 }64

65 void mpmck (unsigned char * w, unsigned char * u, unsigned char * v, int nm, int n, int m)66 {67 }68

69 void mpdivnz70 ( unsigned char * q, unsigned char * r,71 unsigned char * u, unsigned char * v, int n, int m72 )73 {74 if (m == 1)75 {76 int R;77 mpsdv (q, u, n, v [1], &R);78 r [1] = R;79 }80 mpdiv (q, r, u, v, n, m);81 }82

83 #define LOBYTE(x) ((unsigned char) ((x) & 0xff))84 #define HIBYTE(x) ((unsigned char) ((x) >> 8 & 0xff))85

86 void mpng(unsigned char v[], unsigned char u[], int n)87 {88 int j;89 unsigned short ireg=256;90

91 for (j=n;j>=1;j--) {92 ireg=255-u[j]+HIBYTE(ireg);93 v[j+1]=LOBYTE(ireg);94 }95 ireg=255+HIBYTE(ireg);96 v[j+1]=LOBYTE(ireg);97 }

Page 74: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

74 nrmpx.c, 29.6.2016 11:57:56

98

99 #undef LOBYTE100 #undef HIBYTE101

Datei 106: nrmpx.h, 29.6.2016 11:57:561 // bruch/nrmpx.h2

3 #ifndef _NRMPX_H4 #define _NRMPX_H5 unsigned char * mpfirst (unsigned char * h, int n);6 int mpiszero (unsigned char * h, int n);7 int mpsign (unsigned char * h, int n);8 unsigned char mpsgn (unsigned char * h, int n);9 void mpsvl (unsigned char * u, int n, unsigned char iv);10 void mpval (unsigned char * u, unsigned char * v, int n, int m);11 void mpdivnz (unsigned char * q, unsigned char * r, unsigned char * u, unsigned char * v, int n, int m);12 void mpng(unsigned char v[], unsigned char u[], int n);13 #endif14

Datei 107: nrtst.c, 29.6.2016 11:57:581 // bruch/nrtst.c2 #include <stdio.h>3 #include <string.h>4

5 typedef unsigned char usch;6

7 #include "nr.h"8

9 #include "nrmpx.h"10

11 void pr (usch * p, int n)12 {13 printf ("\n");14 while (n > 0)15 {16 p++;17 printf (" %d", (int) * p);18 n--;19 }20 }21

22 int eq (usch * s1, usch * s2, int n)23 {24 while (n > 0)25 {26 if ((*s1) != (*s2)) return 0;27 s1++;28 s2++;29 n--;30 }31 return 1;32 }33

34 int main (void)35 {36 usch tst1 [3] = { (usch) 100, (usch) 255, (usch) 255, };37 usch tst [4] [10] =38 {39 {(usch) 3, (usch) 255, (usch) 255, (usch) 255, },40 {(usch) 4, (usch) 0, (usch) 0, (usch) 0, (usch) 0, },41 {(usch) 4, (usch) 0, (usch) 0, (usch) 1, },42 {(usch) 4, (usch) 141, (usch) 59, (usch) 26, (usch) 53, },43 };44

45 usch res [5] [20] =46 {47 "3945311",48 "9999999",49 "000000000",50 "000000059",51 "551683080",52 };53

54 int n = 3;55 int m;56 usch s [1000];57 usch r [1000];

Page 75: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratnr.res, 26.4.2017 15:02:22 75

58

59 mpng (s, tst1-1, 3); if (!eq(s+1, res[0], strlen (res [0]))) pr (tst1-1, 3);60 pr (tst1-1, 3);61 pr (s, 4);62 mpneg (tst1-1, 3); if (!eq(s+1, res[0], strlen (res [0]))) pr (tst1-1, 3);63 mpneg (tst[0], 3); if (!eq(s+1, res[1], strlen (res [1]))) pr (tst [0], 3);64 mpneg (tst[1], 4); if (!eq(s+1, res[2], strlen (res [2]))) pr (tst [1], 4);65 mpneg (tst[2], 4); if (!eq(s+1, res[3], strlen (res [3]))) pr (tst [2], 4);66 mpneg (tst[3], 4); if (!eq(s+1, res[4], strlen (res [4]))) pr (tst [3], 4);67

68

69 mpneg (tst1-1, 3); if (!eq(s+1, res[0], strlen (res [0]))) pr (tst1-1, 3);70 mpneg (tst[0], 3); if (!eq(s+1, res[1], strlen (res [1]))) pr (tst [0], 3);71 mpneg (tst[1], 4); if (!eq(s+1, res[2], strlen (res [2]))) pr (tst [1], 4);72 mpneg (tst[2], 4); if (!eq(s+1, res[3], strlen (res [3]))) pr (tst [2], 4);73 mpneg (tst[3], 4); if (!eq(s+1, res[4], strlen (res [4]))) pr (tst [3], 4);74

75

76 // must be the last because they destroy tst77 mp2dfr (tst1-1, s, 3, &m); s [m+1] = 0; if (!eq(s+1, res[0], strlen (res [0]))) printf ("\n1 ~ 0.%s, ", s+1);78 mp2dfr (tst[0], s, 3, &m); s [m+1] = 0; if (!eq(s+1, res[1], strlen (res [1]))) printf ("\n1 ~ 0.%s, ", s+1);79 mp2dfr (tst[1], s, 4, &m); s [m+1] = 0; if (!eq(s+1, res[2], strlen (res [2]))) printf ("\n1 ~ 0.%s, ", s+1);80 mp2dfr (tst[2], s, 4, &m); s [m+1] = 0; if (!eq(s+1, res[3], strlen (res [3]))) printf ("\n1 ~ 0.%s, ", s+1);81 mp2dfr (tst[3], s, 4, &m); s [m+1] = 0; if (!eq(s+1, res[4], strlen (res [4]))) printf ("\n1 ~ 0.%s, ", s+1);82

83 return 0;84

85 }86

Datei 108: ratnr.res, 26.4.2017 15:02:221 a = [0.0.0.0] 02 b = [1.1.0x252c0b0.0x252c0b0.5] 5=5:[1.1.0x252c170.0x252c170.7] 7=73 Gib Bruch: a (gelesen) = [1.1.0x252c010.0x252c010.2] 2=2:[1.1.0x252c170.0x252c170.3] 3=3 = [1.1.0x252c420.0x252c420.2] 2=2:[1.1.0x252c1d0.0x252c1d0.3] 3=34 b (vorbesetzt) = [1.1.0x252c010.0x252c010.5] 5=5:[1.1.0x252c170.0x252c170.7] 7=7 = [1.1.0x252c420.0x252c420.5] 5=5:[1.1.0x252c1d0.0x252c1d0.7] 7=75 a + b = [1.1.0x252c3a0.0x252c3a0.2] 2=2:[1.1.0x252c2c0.0x252c2c0.3] 3=3 + [1.1.0x252c280.0x252c280.5] 5=5:[1.1.0x252c2a0.0x252c2a0.7] 7=7 = [1.1.0x252c380.0x252c380.29] 29=29:[1.1.0x252c2e0.0x252c2e0.21] 21=216 a - b = [1.1.0x252c030.0x252c030.2] 2=2:[1.1.0x252c3a0.0x252c3a0.3] 3=3 - [1.1.0x252c280.0x252c280.5] 5=5:[1.1.0x252c2a0.0x252c2a0.7] 7=7 = [2.1.0x252c340.0x252c341.255.255] -1=255:[1.1.0x252c2c0.0x252c2c0.21] 21=217 a * b = [1.1.0x252c360.0x252c360.2] 2=2:[1.1.0x252c320.0x252c320.3] 3=3 * [1.1.0x252c280.0x252c280.5] 5=5:[1.1.0x252c2a0.0x252c2a0.7] 7=7 = [1.1.0x252c340.0x252c340.10] 10=10:[1.1.0x252c030.0x252c030.21] 21=218 a / b = [1.1.0x252c2c0.0x252c2c0.2] 2=2:[1.1.0x252c300.0x252c300.3] 3=3 / [1.1.0x252c280.0x252c280.5] 5=5:[1.1.0x252c2a0.0x252c2a0.7] 7=7 = [1.1.0x252c340.0x252c340.14] 14=14:[1.1.0x252c360.0x252c360.15] 15=159 d = c = a + b = [4.4.0x252c170.0x252c170.0.239.175.59] 15707963=15707963:[4.4.0x252c420.0x252c420.0.207.99.113] 13591409=13591409 + [1.1.0x252c2e0.0x252c2e0.5] 5=5:[1.1.0x252c300.0x252c300.7] 7=7 = [4.4.0x252c2c0.0x252c2c0.10.154.187.210] 177912786=177912786:[4.4.0x252c280.0x252c280.5.171.184.23] 95139863=95139863 = [4.4.0x252c340.0x252c340.10.154.187.210] 177912786=177912786:[4.4.0x252c2a0.0x252c2a0.5.171.184.23] 95139863=9513986310 x = c = 1.8700130564619411 c = [4.4.0x252c2c0.0x252c2c0.16.70.115.233] 273052649=273052649:[4.4.0x252c280.0x252c280.5.171.184.23] 95139863=9513986312 x = c = 2.8700130564619413 c = [4.4.0x252c170.0x252c170.60.42.203.233] 1009437673=1009437673:[4.4.0x252c150.0x252c150.17.3.40.69] 285419589=28541958914 x = c = 3.536679723128615 b = [1.1.0x252c320.0x252c320.2] 2=216 (long) b = 217 Bernoulli-Zahlen18 0: 1 = [1.1.0x252c5c0.0x252c5c0.1] 1=119 1: -0.5 = [1.1.0x252c5c0.0x252c5c0.255] -1=255:[1.1.0x252c5e0.0x252c5e0.2] 2=220 2: 0.166666666666667 = [1.1.0x252c5c0.0x252c5c0.1] 1=1:[1.1.0x252c5e0.0x252c5e0.6] 6=621 3: 0 = [0.0.0.0] 022 4: -0.0333333333333333 = [1.1.0x252c5c0.0x252c5c0.255] -1=255:[1.1.0x252c3e0.0x252c3e0.30] 30=3023 5: 0 = [0.0.0.0] 024 6: 0.0238095238095238 = [1.1.0x252c5c0.0x252c5c0.1] 1=1:[1.1.0x252cf80.0x252cf80.42] 42=4225 7: 0 = [0.0.0.0] 026 8: -0.0333333333333333 = [1.1.0x252c5c0.0x252c5c0.255] -1=255:[1.1.0x252d020.0x252d020.30] 30=3027 9: 0 = [0.0.0.0] 028 10: 0.0757575757575758 = [1.1.0x252c5c0.0x252c5c0.5] 5=5:[1.1.0x252d0c0.0x252d0c0.66] 66=6629 11: 0 = [0.0.0.0] 030 12: -0.253113553113553 = [2.2.0x252c5c0.0x252c5c0.253.77] -691=64845:[2.2.0x252d160.0x252d160.10.170] 2730=273031 13: 0 = [0.0.0.0] 032 14: 1.16666666666667 = [1.1.0x252c5c0.0x252c5c0.7] 7=7:[1.1.0x252d200.0x252d200.6] 6=633 15: 0 = [0.0.0.0] 034 16: -7.0921568627451 = [2.2.0x252c5c0.0x252c5c0.241.223] -3617=61919:[2.2.0x252d320.0x252d320.1.254] 510=51035 17: 0 = [0.0.0.0] 036 18: 54.9711779448622 = [3.3.0x252c5c0.0x252c5c0.0.171.91] 43867=43867:[2.2.0x252d3c0.0x252d3c0.3.30] 798=79837

38 Verbrauchte Gesamtzeit: 0.03852139 Verbrauchte Zeit pro B0-B19: 0.03852140 anz = 1, bmax = 1941

42 results checked43 Bernoulli-Zahlen44 0: 1 = [1.1.0x252d460.0x252d460.1] 1=145 1: -0.5 = [1.1.0x252d460.0x252d460.255] -1=255:[1.1.0x252cdd0.0x252cdd0.2] 2=246 2: 0.166666666666667 = [1.1.0x252d460.0x252d460.1] 1=1:[1.1.0x252cdd0.0x252cdd0.6] 6=647 3: 0 = [0.0.0.0] 0

Page 76: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

76 ratnr.res, 26.4.2017 15:02:22

48 4: -0.0333333333333333 = [1.1.0x252d460.0x252d460.255] -1=255:[1.1.0x252cdf0.0x252cdf0.30] 30=3049 5: 0 = [0.0.0.0] 050 6: 0.0238095238095238 = [1.1.0x252d460.0x252d460.1] 1=1:[1.1.0x252cd90.0x252cd90.42] 42=4251 7: 0 = [0.0.0.0] 052 8: -0.0333333333333333 = [1.1.0x252d460.0x252d460.255] -1=255:[1.1.0x252cbf0.0x252cbf0.30] 30=3053 9: 0 = [0.0.0.0] 054 10: 0.0757575757575758 = [1.1.0x252d460.0x252d460.5] 5=5:[1.1.0x252d760.0x252d760.66] 66=6655 11: 0 = [0.0.0.0] 056 12: -0.253113553113553 = [2.2.0x252d460.0x252d460.253.77] -691=64845:[2.2.0x252d800.0x252d800.10.170] 2730=273057 13: 0 = [0.0.0.0] 058 14: 1.16666666666667 = [1.1.0x252d460.0x252d460.7] 7=7:[1.1.0x252d8a0.0x252d8a0.6] 6=659 15: 0 = [0.0.0.0] 060 16: -7.0921568627451 = [2.2.0x252d460.0x252d460.241.223] -3617=61919:[2.2.0x252d9c0.0x252d9c0.1.254] 510=51061 17: 0 = [0.0.0.0] 062 18: 54.9711779448622 = [3.3.0x252d460.0x252d460.0.171.91] 43867=43867:[2.2.0x252dac0.0x252dac0.3.30] 798=79863 19: 0 = [0.0.0.0] 064 20: -529.124242424242 = [3.3.0x252d460.0x252d460.253.85.237] -174611=16602605:[2.2.0x252db60.0x252db60.1.74] 330=33065

66 Verbrauchte Gesamtzeit: 0.04225167 Verbrauchte Zeit pro B0-B21: 0.04225168 anz = 1, bmax = 2169

70 results checked71 Bernoulli-Zahlen72 0: 1 = [1.1.0x252da40.0x252da40.1] 1=173 1: -0.5 = [1.1.0x252da40.0x252da40.255] -1=255:[1.1.0x252c540.0x252c540.2] 2=274 2: 0.166666666666667 = [1.1.0x252da40.0x252da40.1] 1=1:[1.1.0x252c540.0x252c540.6] 6=675 3: 0 = [0.0.0.0] 076 4: -0.0333333333333333 = [1.1.0x252da40.0x252da40.255] -1=255:[1.1.0x252c600.0x252c600.30] 30=3077 5: 0 = [0.0.0.0] 078 6: 0.0238095238095238 = [1.1.0x252da40.0x252da40.1] 1=1:[1.1.0x252d540.0x252d540.42] 42=4279 7: 0 = [0.0.0.0] 080 8: -0.0333333333333333 = [1.1.0x252da40.0x252da40.255] -1=255:[1.1.0x252d700.0x252d700.30] 30=3081 9: 0 = [0.0.0.0] 082 10: 0.0757575757575758 = [1.1.0x252da40.0x252da40.5] 5=5:[1.1.0x252d560.0x252d560.66] 66=6683 11: 0 = [0.0.0.0] 084 12: -0.253113553113553 = [2.2.0x252da40.0x252da40.253.77] -691=64845:[2.2.0x252e0a0.0x252e0a0.10.170] 2730=273085 13: 0 = [0.0.0.0] 086 14: 1.16666666666667 = [1.1.0x252da40.0x252da40.7] 7=7:[1.1.0x252e140.0x252e140.6] 6=687 15: 0 = [0.0.0.0] 088 16: -7.0921568627451 = [2.2.0x252da40.0x252da40.241.223] -3617=61919:[2.2.0x252e260.0x252e260.1.254] 510=51089 17: 0 = [0.0.0.0] 090 18: 54.9711779448622 = [3.3.0x252da40.0x252da40.0.171.91] 43867=43867:[2.2.0x252e300.0x252e300.3.30] 798=79891 19: 0 = [0.0.0.0] 092 20: -529.124242424242 = [3.3.0x252da40.0x252da40.253.85.237] -174611=16602605:[2.2.0x252e3a0.0x252e3a0.1.74] 330=33093 21: 0 = [0.0.0.0] 094 22: 127766.152173913 = [3.3.0x252da40.0x252da40.89.173.251] 5877243=5877243:[1.1.0x252e440.0x252e440.46] 46=4695

96 Verbrauchte Gesamtzeit: 0.04555897 Verbrauchte Zeit pro B0-B23: 0.04555898 anz = 1, bmax = 2399

100 results checked101 Bernoulli-Zahlen102 0: 1 = [1.1.0x252c700.0x252c700.1] 1=1103 1: -0.5 = [1.1.0x252c700.0x252c700.255] -1=255:[1.1.0x252e1a0.0x252e1a0.2] 2=2104 2: 0.166666666666667 = [1.1.0x252c700.0x252c700.1] 1=1:[1.1.0x252e1a0.0x252e1a0.6] 6=6105 3: 0 = [0.0.0.0] 0106 4: -0.0333333333333333 = [1.1.0x252c700.0x252c700.255] -1=255:[1.1.0x252ca80.0x252ca80.30] 30=30107 5: 0 = [0.0.0.0] 0108 6: 0.0238095238095238 = [1.1.0x252c700.0x252c700.1] 1=1:[1.1.0x252ca80.0x252ca80.42] 42=42109 7: 0 = [0.0.0.0] 0110 8: -0.0333333333333333 = [1.1.0x252c700.0x252c700.255] -1=255:[1.1.0x252c9e0.0x252c9e0.30] 30=30111 9: 0 = [0.0.0.0] 0112 10: 0.0757575757575758 = [1.1.0x252c700.0x252c700.5] 5=5:[1.1.0x252c830.0x252c830.66] 66=66113 11: 0 = [0.0.0.0] 0114 12: -0.253113553113553 = [2.2.0x252c700.0x252c700.253.77] -691=64845:[2.2.0x252e780.0x252e780.10.170] 2730=2730115 13: 0 = [0.0.0.0] 0116 14: 1.16666666666667 = [1.1.0x252c700.0x252c700.7] 7=7:[1.1.0x252e820.0x252e820.6] 6=6117 15: 0 = [0.0.0.0] 0118 16: -7.0921568627451 = [2.2.0x252c700.0x252c700.241.223] -3617=61919:[2.2.0x252e940.0x252e940.1.254] 510=510119 17: 0 = [0.0.0.0] 0120 18: 54.9711779448622 = [3.3.0x252c700.0x252c700.0.171.91] 43867=43867:[2.2.0x252ea40.0x252ea40.3.30] 798=798121 19: 0 = [0.0.0.0] 0122 20: -529.124242424242 = [3.3.0x252c700.0x252c700.253.85.237] -174611=16602605:[2.2.0x252eae0.0x252eae0.1.74] 330=330123 21: 0 = [0.0.0.0] 0124 22: 127766.152173913 = [3.3.0x252c700.0x252c700.89.173.251] 5877243=5877243:[1.1.0x252eb80.0x252eb80.46] 46=46125 23: -1444704.71111111 = [4.4.0x252c700.0x252c700.252.32.0.0] -65011712=4229955584:[1.1.0x252eb80.0x252eb80.45] 45=45

Page 77: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratnr.res, 26.4.2017 15:02:22 77

126 24: 6065065.61355311 = [5.5.0x252c700.0x252c700.0.197.97.223.193] 3311525825=3311525825:[2.2.0x252eb80.0x252eb80.2.34] 546=546127

128 Verbrauchte Gesamtzeit: 0.050337129 Verbrauchte Zeit pro B0-B25: 0.050337130 anz = 1, bmax = 25131

132 results checked133 Bernoulli-Zahlen134 0: 1 = [1.1.0x252e9c0.0x252e9c0.1] 1=1135 1: -0.5 = [1.1.0x252e9c0.0x252e9c0.255] -1=255:[1.1.0x252da60.0x252da60.2] 2=2136 2: 0.166666666666667 = [1.1.0x252e9c0.0x252e9c0.1] 1=1:[1.1.0x252da60.0x252da60.6] 6=6137 3: 0 = [0.0.0.0] 0138 4: -0.0333333333333333 = [1.1.0x252e9c0.0x252e9c0.255] -1=255:[1.1.0x252dbe0.0x252dbe0.30] 30=30139 5: 0 = [0.0.0.0] 0140 6: 0.0238095238095238 = [1.1.0x252e9c0.0x252e9c0.1] 1=1:[1.1.0x252c520.0x252c520.42] 42=42141 7: 0 = [0.0.0.0] 0142 8: -0.0333333333333333 = [1.1.0x252e9c0.0x252e9c0.255] -1=255:[1.1.0x252c500.0x252c500.30] 30=30143 9: 0 = [0.0.0.0] 0144 10: 0.0757575757575758 = [1.1.0x252e9c0.0x252e9c0.5] 5=5:[1.1.0x252e4c0.0x252e4c0.66] 66=66145 11: 0 = [0.0.0.0] 0146 12: -0.253113553113553 = [2.2.0x252e9c0.0x252e9c0.253.77] -691=64845:[2.2.0x252e040.0x252e040.10.170] 2730=2730147 13: 0 = [0.0.0.0] 0148 14: 1.16666666666667 = [1.1.0x252e9c0.0x252e9c0.7] 7=7:[1.1.0x252f200.0x252f200.6] 6=6149 15: 0 = [0.0.0.0] 0150 16: -7.0921568627451 = [2.2.0x252e9c0.0x252e9c0.241.223] -3617=61919:[2.2.0x252f320.0x252f320.1.254] 510=510151 17: 0 = [0.0.0.0] 0152 18: 54.9711779448622 = [3.3.0x252e9c0.0x252e9c0.0.171.91] 43867=43867:[2.2.0x252f3c0.0x252f3c0.3.30] 798=798153 19: 0 = [0.0.0.0] 0154 20: -529.124242424242 = [3.3.0x252e9c0.0x252e9c0.253.85.237] -174611=16602605:[2.2.0x252f460.0x252f460.1.74] 330=330155 21: 0 = [0.0.0.0] 0156 22: 127766.152173913 = [3.3.0x252e9c0.0x252e9c0.89.173.251] 5877243=5877243:[1.1.0x252f500.0x252f500.46] 46=46157 23: -1444704.71111111 = [4.4.0x252e9c0.0x252e9c0.252.32.0.0] -65011712=4229955584:[1.1.0x252f500.0x252f500.45] 45=45158 24: 6065065.61355311 = [5.5.0x252e9c0.0x252e9c0.0.197.97.223.193] 3311525825=3311525825:[2.2.0x252f500.0x252f500.2.34] 546=546159 25: -2330168.88888889 = [4.4.0x252e9c0.0x252e9c0.254.192.0.0] -20971520=4273995776:[1.1.0x252f500.0x252f500.9] 9=9160 26: -59158873.9444444 = [4.4.0x252e9c0.0x252e9c0.192.135.135.173] -1064859731=3230107565:[1.1.0x252f500.0x252f500.18] 18=18161

162 Verbrauchte Gesamtzeit: 0.055472163 Verbrauchte Zeit pro B0-B27: 0.055472164 anz = 1, bmax = 27165

166 results checked167 Bernoulli-Zahlen168 0: 1 = [1.1.0x252e8c0.0x252e8c0.1] 1=1169 1: -0.5 = [1.1.0x252e8c0.0x252e8c0.255] -1=255:[1.1.0x252d480.0x252d480.2] 2=2170 2: 0.166666666666667 = [1.1.0x252e8c0.0x252e8c0.1] 1=1:[1.1.0x252d480.0x252d480.6] 6=6171 3: 0 = [0.0.0.0] 0172 4: -0.0333333333333333 = [1.1.0x252e8c0.0x252e8c0.255] -1=255:[1.1.0x252dd00.0x252dd00.30] 30=30173 5: 0 = [0.0.0.0] 0174 6: 0.0238095238095238 = [1.1.0x252e8c0.0x252e8c0.1] 1=1:[1.1.0x252ca40.0x252ca40.42] 42=42175 7: 0 = [0.0.0.0] 0176 8: -0.0333333333333333 = [1.1.0x252e8c0.0x252e8c0.255] -1=255:[1.1.0x252ddf0.0x252ddf0.30] 30=30177 9: 0 = [0.0.0.0] 0178 10: 0.0757575757575758 = [1.1.0x252e8c0.0x252e8c0.5] 5=5:[1.1.0x252dda0.0x252dda0.66] 66=66179 11: 0 = [0.0.0.0] 0180 12: -0.253113553113553 = [2.2.0x252e8c0.0x252e8c0.253.77] -691=64845:[2.2.0x252eca0.0x252eca0.10.170] 2730=2730181 13: 0 = [0.0.0.0] 0182 14: 1.16666666666667 = [1.1.0x252e8c0.0x252e8c0.7] 7=7:[1.1.0x252f120.0x252f120.6] 6=6183 15: 0 = [0.0.0.0] 0184 16: -7.0921568627451 = [2.2.0x252e8c0.0x252e8c0.241.223] -3617=61919:[2.2.0x252fc20.0x252fc20.1.254] 510=510185 17: 0 = [0.0.0.0] 0186 18: 54.9711779448622 = [3.3.0x252e8c0.0x252e8c0.0.171.91] 43867=43867:[2.2.0x252fcc0.0x252fcc0.3.30] 798=798187 19: 0 = [0.0.0.0] 0188 20: -529.124242424242 = [3.3.0x252e8c0.0x252e8c0.253.85.237] -174611=16602605:[2.2.0x252fd60.0x252fd60.1.74] 330=330189 21: 0 = [0.0.0.0] 0190 22: 127766.152173913 = [3.3.0x252e8c0.0x252e8c0.89.173.251] 5877243=5877243:[1.1.0x252fe00.0x252fe00.46] 46=46191 23: -1444704.71111111 = [4.4.0x252e8c0.0x252e8c0.252.32.0.0] -65011712=4229955584:[1.1.0x252fe00.0x252fe00.45] 45=45192 24: 6065065.61355311 = [5.5.0x252e8c0.0x252e8c0.0.197.97.223.193] 3311525825=3311525825:[2.2.0x252fe00.0x252fe00.2.34] 546=546193 25: -2330168.88888889 = [4.4.0x252e8c0.0x252e8c0.254.192.0.0] -20971520=4273995776:[1.1.0x252fe00.0x252fe00.9] 9=9194 26: -59158873.9444444 = [4.4.0x252e8c0.0x252e8c0.192.135.135.173] -1064859731=3230107565:[1.1.0x252fe00.0x252fe00.18] 18=18195 27: -49432868.5714286 = [4.4.0x252e8c0.0x252e8c0.235.96.0.0] -346030080=3948937216:[1.1.0x252fe00.0x252fe00.7] 7=7196 28: 2136962632.93218 = [6.6.0x252e8c0.0x252e8c0.1.176.222.107.251.219] 1859157490651=1859157490651:[2.2.0x252fe00.0x252fe00.3.102] 870=870197

198 Verbrauchte Gesamtzeit: 0.066525199 Verbrauchte Zeit pro B0-B29: 0.066525200 anz = 1, bmax = 29201

202 results checked203 Bernoulli-Zahlen

Page 78: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

78 ratnr.res, 26.4.2017 15:02:22

204 0: 1 = [1.1.0x252c7e0.0x252c7e0.1] 1=1205 1: -0.5 = [1.1.0x252c7e0.0x252c7e0.255] -1=255:[1.1.0x252c380.0x252c380.2] 2=2206 2: 0.166666666666667 = [1.1.0x252c7e0.0x252c7e0.1] 1=1:[1.1.0x252c380.0x252c380.6] 6=6207 3: 0 = [0.0.0.0] 0208 4: -0.0333333333333333 = [1.1.0x252c7e0.0x252c7e0.255] -1=255:[1.1.0x252f670.0x252f670.30] 30=30209 5: 0 = [0.0.0.0] 0210 6: 0.0238095238095238 = [1.1.0x252c7e0.0x252c7e0.1] 1=1:[1.1.0x252d6c0.0x252d6c0.42] 42=42211 7: 0 = [0.0.0.0] 0212 8: -0.0333333333333333 = [1.1.0x252c7e0.0x252c7e0.255] -1=255:[1.1.0x252c210.0x252c210.30] 30=30213 9: 0 = [0.0.0.0] 0214 10: 0.0757575757575758 = [1.1.0x252c7e0.0x252c7e0.5] 5=5:[1.1.0x252eea0.0x252eea0.66] 66=66215 11: 0 = [0.0.0.0] 0216 12: -0.253113553113553 = [2.2.0x252c7e0.0x252c7e0.253.77] -691=64845:[2.2.0x252f6f0.0x252f6f0.10.170] 2730=2730217 13: 0 = [0.0.0.0] 0218 14: 1.16666666666667 = [1.1.0x252c7e0.0x252c7e0.7] 7=7:[1.1.0x2530500.0x2530500.6] 6=6219 15: 0 = [0.0.0.0] 0220 16: -7.0921568627451 = [2.2.0x252c7e0.0x252c7e0.241.223] -3617=61919:[2.2.0x2530620.0x2530620.1.254] 510=510221 17: 0 = [0.0.0.0] 0222 18: 54.9711779448622 = [3.3.0x252c7e0.0x252c7e0.0.171.91] 43867=43867:[2.2.0x25306c0.0x25306c0.3.30] 798=798223 19: 0 = [0.0.0.0] 0224 20: -529.124242424242 = [3.3.0x252c7e0.0x252c7e0.253.85.237] -174611=16602605:[2.2.0x2530760.0x2530760.1.74] 330=330225 21: 0 = [0.0.0.0] 0226 22: 127766.152173913 = [3.3.0x252c7e0.0x252c7e0.89.173.251] 5877243=5877243:[1.1.0x2530800.0x2530800.46] 46=46227 23: -1444704.71111111 = [4.4.0x252c7e0.0x252c7e0.252.32.0.0] -65011712=4229955584:[1.1.0x2530800.0x2530800.45] 45=45228 24: 6065065.61355311 = [5.5.0x252c7e0.0x252c7e0.0.197.97.223.193] 3311525825=3311525825:[2.2.0x2530800.0x2530800.2.34] 546=546229 25: -2330168.88888889 = [4.4.0x252c7e0.0x252c7e0.254.192.0.0] -20971520=4273995776:[1.1.0x2530800.0x2530800.9] 9=9230 26: -59158873.9444444 = [4.4.0x252c7e0.0x252c7e0.192.135.135.173] -1064859731=3230107565:[1.1.0x2530800.0x2530800.18] 18=18231 27: -49432868.5714286 = [4.4.0x252c7e0.0x252c7e0.235.96.0.0] -346030080=3948937216:[1.1.0x2530800.0x2530800.7] 7=7232 28: 2136962632.93218 = [6.6.0x252c7e0.0x252c7e0.1.176.222.107.251.219] 1859157490651=1859157490651:[2.2.0x2530800.0x2530800.3.102] 870=870233 29: -5716836352 = [5.5.0x252c7e0.0x252c7e0.254.171.64.0.0] -5716836352=1093794791424234 30: -23117208246.0994 = [7.7.0x252c7e0.0x252c7e0.254.210.225.88.168.160.101] -331084656500635=71726509381427301:[2.2.0x2530800.0x2530800.55.242] 14322=14322235

236 Verbrauchte Gesamtzeit: 0.080685237 Verbrauchte Zeit pro B0-B31: 0.080685238 anz = 1, bmax = 31239

240 results checked241 Bernoulli-Zahlen242 0: 1 = [1.1.0x252fbc0.0x252fbc0.1] 1=1243 1: -0.5 = [1.1.0x252fbc0.0x252fbc0.255] -1=255:[1.1.0x252ec40.0x252ec40.2] 2=2244 2: 0.166666666666667 = [1.1.0x252fbc0.0x252fbc0.1] 1=1:[1.1.0x252ec40.0x252ec40.6] 6=6245 3: 0 = [0.0.0.0] 0246 4: -0.0333333333333333 = [1.1.0x252fbc0.0x252fbc0.255] -1=255:[1.1.0x252f8b0.0x252f8b0.30] 30=30247 5: 0 = [0.0.0.0] 0248 6: 0.0238095238095238 = [1.1.0x252fbc0.0x252fbc0.1] 1=1:[1.1.0x252f830.0x252f830.42] 42=42249 7: 0 = [0.0.0.0] 0250 8: -0.0333333333333333 = [1.1.0x252fbc0.0x252fbc0.255] -1=255:[1.1.0x252ffa0.0x252ffa0.30] 30=30251 9: 0 = [0.0.0.0] 0252 10: 0.0757575757575758 = [1.1.0x252fbc0.0x252fbc0.5] 5=5:[1.1.0x252ff80.0x252ff80.66] 66=66253 11: 0 = [0.0.0.0] 0254 12: -0.253113553113553 = [2.2.0x252fbc0.0x252fbc0.253.77] -691=64845:[2.2.0x2530040.0x2530040.10.170] 2730=2730255 13: 0 = [0.0.0.0] 0256 14: 1.16666666666667 = [1.1.0x252fbc0.0x252fbc0.7] 7=7:[1.1.0x25304c0.0x25304c0.6] 6=6257 15: 0 = [0.0.0.0] 0258 16: -7.0921568627451 = [2.2.0x252fbc0.0x252fbc0.241.223] -3617=61919:[2.2.0x2531040.0x2531040.1.254] 510=510259 17: 0 = [0.0.0.0] 0260 18: 54.9711779448622 = [3.3.0x252fbc0.0x252fbc0.0.171.91] 43867=43867:[2.2.0x25310e0.0x25310e0.3.30] 798=798261 19: 0 = [0.0.0.0] 0262 20: -529.124242424242 = [3.3.0x252fbc0.0x252fbc0.253.85.237] -174611=16602605:[2.2.0x2531180.0x2531180.1.74] 330=330263 21: 0 = [0.0.0.0] 0264 22: 127766.152173913 = [3.3.0x252fbc0.0x252fbc0.89.173.251] 5877243=5877243:[1.1.0x2531220.0x2531220.46] 46=46265 23: -1444704.71111111 = [4.4.0x252fbc0.0x252fbc0.252.32.0.0] -65011712=4229955584:[1.1.0x2531220.0x2531220.45] 45=45266 24: 6065065.61355311 = [5.5.0x252fbc0.0x252fbc0.0.197.97.223.193] 3311525825=3311525825:[2.2.0x2531220.0x2531220.2.34] 546=546267 25: -2330168.88888889 = [4.4.0x252fbc0.0x252fbc0.254.192.0.0] -20971520=4273995776:[1.1.0x2531220.0x2531220.9] 9=9268 26: -59158873.9444444 = [4.4.0x252fbc0.0x252fbc0.192.135.135.173] -1064859731=3230107565:[1.1.0x2531220.0x2531220.18] 18=18269 27: -49432868.5714286 = [4.4.0x252fbc0.0x252fbc0.235.96.0.0] -346030080=3948937216:[1.1.0x2531220.0x2531220.7] 7=7270 28: 2136962632.93218 = [6.6.0x252fbc0.0x252fbc0.1.176.222.107.251.219] 1859157490651=1859157490651:[2.2.0x2531220.0x2531220.3.102] 870=870271 29: -5716836352 = [5.5.0x252fbc0.0x252fbc0.254.171.64.0.0] -5716836352=1093794791424272 30: -23117208246.0994 = [7.7.0x252fbc0.0x252fbc0.254.210.225.88.168.160.101] -331084656500635=71726509381427301:[2.2.0x2531220.0x2531220.55.242] 14322=14322273 31: 92695866026.6667 = [5.5.0x252fbc0.0x252fbc0.64.191.80.0.0] 278087598080=278087598080:[1.1.0x2531220.0x2531220.3] 3=3274 32: 579051330875.332 = [7.7.0x252fbc0.0x252fbc0.3.216.211.18.105.135.103] 1082825988736871=1082825988736871:[2.2.0x2531220.0x2531220.7.78] 1870=1870275

276 Verbrauchte Gesamtzeit: 0.098459277 Verbrauchte Zeit pro B0-B33: 0.098459278 anz = 1, bmax = 33279

280 results checked281 Bernoulli-Zahlen

Page 79: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratnr.res, 26.4.2017 15:02:22 79

282 0: 1 = [1.1.0x252df30.0x252df30.1] 1=1283 1: -0.5 = [1.1.0x252df30.0x252df30.255] -1=255:[1.1.0x252e9a0.0x252e9a0.2] 2=2284 2: 0.166666666666667 = [1.1.0x252df30.0x252df30.1] 1=1:[1.1.0x252e9a0.0x252e9a0.6] 6=6285 3: 0 = [0.0.0.0] 0286 4: -0.0333333333333333 = [1.1.0x252df30.0x252df30.255] -1=255:[1.1.0x2530220.0x2530220.30] 30=30287 5: 0 = [0.0.0.0] 0288 6: 0.0238095238095238 = [1.1.0x252df30.0x252df30.1] 1=1:[1.1.0x252f260.0x252f260.42] 42=42289 7: 0 = [0.0.0.0] 0290 8: -0.0333333333333333 = [1.1.0x252df30.0x252df30.255] -1=255:[1.1.0x252d280.0x252d280.30] 30=30291 9: 0 = [0.0.0.0] 0292 10: 0.0757575757575758 = [1.1.0x252df30.0x252df30.5] 5=5:[1.1.0x25309c0.0x25309c0.66] 66=66293 11: 0 = [0.0.0.0] 0294 12: -0.253113553113553 = [2.2.0x252df30.0x252df30.253.77] -691=64845:[2.2.0x2530ad0.0x2530ad0.10.170] 2730=2730295 13: 0 = [0.0.0.0] 0296 14: 1.16666666666667 = [1.1.0x252df30.0x252df30.7] 7=7:[1.1.0x2531a00.0x2531a00.6] 6=6297 15: 0 = [0.0.0.0] 0298 16: -7.0921568627451 = [2.2.0x252df30.0x252df30.241.223] -3617=61919:[2.2.0x2531b20.0x2531b20.1.254] 510=510299 17: 0 = [0.0.0.0] 0300 18: 54.9711779448622 = [3.3.0x252df30.0x252df30.0.171.91] 43867=43867:[2.2.0x2531bc0.0x2531bc0.3.30] 798=798301 19: 0 = [0.0.0.0] 0302 20: -529.124242424242 = [3.3.0x252df30.0x252df30.253.85.237] -174611=16602605:[2.2.0x2531c60.0x2531c60.1.74] 330=330303 21: 0 = [0.0.0.0] 0304 22: 127766.152173913 = [3.3.0x252df30.0x252df30.89.173.251] 5877243=5877243:[1.1.0x2531d00.0x2531d00.46] 46=46305 23: -1444704.71111111 = [4.4.0x252df30.0x252df30.252.32.0.0] -65011712=4229955584:[1.1.0x2531d00.0x2531d00.45] 45=45306 24: 6065065.61355311 = [5.5.0x252df30.0x252df30.0.197.97.223.193] 3311525825=3311525825:[2.2.0x2531d00.0x2531d00.2.34] 546=546307 25: -2330168.88888889 = [4.4.0x252df30.0x252df30.254.192.0.0] -20971520=4273995776:[1.1.0x2531d00.0x2531d00.9] 9=9308 26: -59158873.9444444 = [4.4.0x252df30.0x252df30.192.135.135.173] -1064859731=3230107565:[1.1.0x2531d00.0x2531d00.18] 18=18309 27: -49432868.5714286 = [4.4.0x252df30.0x252df30.235.96.0.0] -346030080=3948937216:[1.1.0x2531d00.0x2531d00.7] 7=7310 28: 2136962632.93218 = [6.6.0x252df30.0x252df30.1.176.222.107.251.219] 1859157490651=1859157490651:[2.2.0x2531d00.0x2531d00.3.102] 870=870311 29: -5716836352 = [5.5.0x252df30.0x252df30.254.171.64.0.0] -5716836352=1093794791424312 30: -23117208246.0994 = [7.7.0x252df30.0x252df30.254.210.225.88.168.160.101] -331084656500635=71726509381427301:[2.2.0x2531d00.0x2531d00.55.242] 14322=14322313 31: 92695866026.6667 = [5.5.0x252df30.0x252df30.64.191.80.0.0] 278087598080=278087598080:[1.1.0x2531d00.0x2531d00.3] 3=3314 32: 579051330875.332 = [7.7.0x252df30.0x252df30.3.216.211.18.105.135.103] 1082825988736871=1082825988736871:[2.2.0x2531d00.0x2531d00.7.78] 1870=1870315 33: -2349312757564.95 = [6.6.0x252df30.0x252df30.211.33.43.0.0.0] -49335567908864=232139408801792:[1.1.0x2531d00.0x2531d00.21] 21=21316 34: -16444354762695.8 = [7.7.0x252df30.0x252df30.255.46.157.129.15.179.19] -230220966677741=71827373071250195:[1.1.0x2531d00.0x2531d00.14] 14=14317

318 Verbrauchte Gesamtzeit: 0.11678319 Verbrauchte Zeit pro B0-B35: 0.11678320 anz = 1, bmax = 35321

322 results checked323 Bernoulli-Zahlen324 0: 1 = [1.1.0x252def0.0x252def0.1] 1=1325 1: -0.5 = [1.1.0x252def0.0x252def0.255] -1=255:[1.1.0x252c6a0.0x252c6a0.2] 2=2326 2: 0.166666666666667 = [1.1.0x252def0.0x252def0.1] 1=1:[1.1.0x252c6a0.0x252c6a0.6] 6=6327 3: 0 = [0.0.0.0] 0328 4: -0.0333333333333333 = [1.1.0x252def0.0x252def0.255] -1=255:[1.1.0x25314f0.0x25314f0.30] 30=30329 5: 0 = [0.0.0.0] 0330 6: 0.0238095238095238 = [1.1.0x252def0.0x252def0.1] 1=1:[1.1.0x252f050.0x252f050.42] 42=42331 7: 0 = [0.0.0.0] 0332 8: -0.0333333333333333 = [1.1.0x252def0.0x252def0.255] -1=255:[1.1.0x2531420.0x2531420.30] 30=30333 9: 0 = [0.0.0.0] 0334 10: 0.0757575757575758 = [1.1.0x252def0.0x252def0.5] 5=5:[1.1.0x2531460.0x2531460.66] 66=66335 11: 0 = [0.0.0.0] 0336 12: -0.253113553113553 = [2.2.0x252def0.0x252def0.253.77] -691=64845:[2.2.0x2531570.0x2531570.10.170] 2730=2730337 13: 0 = [0.0.0.0] 0338 14: 1.16666666666667 = [1.1.0x252def0.0x252def0.7] 7=7:[1.1.0x2532560.0x2532560.6] 6=6339 15: 0 = [0.0.0.0] 0340 16: -7.0921568627451 = [2.2.0x252def0.0x252def0.241.223] -3617=61919:[2.2.0x2532680.0x2532680.1.254] 510=510341 17: 0 = [0.0.0.0] 0342 18: 54.9711779448622 = [3.3.0x252def0.0x252def0.0.171.91] 43867=43867:[2.2.0x2532720.0x2532720.3.30] 798=798343 19: 0 = [0.0.0.0] 0344 20: -529.124242424242 = [3.3.0x252def0.0x252def0.253.85.237] -174611=16602605:[2.2.0x25327c0.0x25327c0.1.74] 330=330345 21: 0 = [0.0.0.0] 0346 22: 127766.152173913 = [3.3.0x252def0.0x252def0.89.173.251] 5877243=5877243:[1.1.0x2532860.0x2532860.46] 46=46347 23: -1444704.71111111 = [4.4.0x252def0.0x252def0.252.32.0.0] -65011712=4229955584:[1.1.0x2532860.0x2532860.45] 45=45348 24: 6065065.61355311 = [5.5.0x252def0.0x252def0.0.197.97.223.193] 3311525825=3311525825:[2.2.0x2532860.0x2532860.2.34] 546=546349 25: -2330168.88888889 = [4.4.0x252def0.0x252def0.254.192.0.0] -20971520=4273995776:[1.1.0x2532860.0x2532860.9] 9=9350 26: -59158873.9444444 = [4.4.0x252def0.0x252def0.192.135.135.173] -1064859731=3230107565:[1.1.0x2532860.0x2532860.18] 18=18351 27: -49432868.5714286 = [4.4.0x252def0.0x252def0.235.96.0.0] -346030080=3948937216:[1.1.0x2532860.0x2532860.7] 7=7352 28: 2136962632.93218 = [6.6.0x252def0.0x252def0.1.176.222.107.251.219] 1859157490651=1859157490651:[2.2.0x2532860.0x2532860.3.102] 870=870353 29: -5716836352 = [5.5.0x252def0.0x252def0.254.171.64.0.0] -5716836352=1093794791424354 30: -23117208246.0994 = [7.7.0x252def0.0x252def0.254.210.225.88.168.160.101] -331084656500635=71726509381427301:[2.2.0x2532860.0x2532860.55.242] 14322=14322355 31: 92695866026.6667 = [5.5.0x252def0.0x252def0.64.191.80.0.0] 278087598080=278087598080:[1.1.0x2532860.0x2532860.3] 3=3356 32: 579051330875.332 = [7.7.0x252def0.0x252def0.3.216.211.18.105.135.103] 1082825988736871=1082825988736871:[2.2.0x2532860.0x2532860.7.78] 1870=1870357 33: -2349312757564.95 = [6.6.0x252def0.0x252def0.211.33.43.0.0.0] -49335567908864=232139408801792:[1.1.0x2532860.0x2532860.21] 21=21358 34: -16444354762695.8 = [7.7.0x252def0.0x252def0.255.46.157.129.15.179.19] -230220966677741=71827373071250195:[1.1.0x2532860.0x2532860.14] 14=14

Page 80: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

80 ratnr.res, 26.4.2017 15:02:22

359 35: 70013135239395.6 = [7.7.0x252def0.0x252def0.2.61.22.212.128.0.0] 630118217154560=630118217154560:[1.1.0x2532860.0x2532860.9] 9=9360 36: 524741348263712 = [9.9.0x252def0.0x252def0.54.152.5.5.239.72.78.54.3] 1007078348174232794627=1007078348174232794627:[3.3.0x2532860.0x2532860.29.72.214] 1919190=1919190361

362 Verbrauchte Gesamtzeit: 0.137316363 Verbrauchte Zeit pro B0-B37: 0.137316364 anz = 1, bmax = 37365

366 results checked367 Bernoulli-Zahlen368 0: 1 = [1.1.0x252eff0.0x252eff0.1] 1=1369 1: -0.5 = [1.1.0x252eff0.0x252eff0.255] -1=255:[1.1.0x252c7c0.0x252c7c0.2] 2=2370 2: 0.166666666666667 = [1.1.0x252eff0.0x252eff0.1] 1=1:[1.1.0x252c7c0.0x252c7c0.6] 6=6371 3: 0 = [0.0.0.0] 0372 4: -0.0333333333333333 = [1.1.0x252eff0.0x252eff0.255] -1=255:[1.1.0x252cee0.0x252cee0.30] 30=30373 5: 0 = [0.0.0.0] 0374 6: 0.0238095238095238 = [1.1.0x252eff0.0x252eff0.1] 1=1:[1.1.0x2532070.0x2532070.42] 42=42375 7: 0 = [0.0.0.0] 0376 8: -0.0333333333333333 = [1.1.0x252eff0.0x252eff0.255] -1=255:[1.1.0x2531e40.0x2531e40.30] 30=30377 9: 0 = [0.0.0.0] 0378 10: 0.0757575757575758 = [1.1.0x252eff0.0x252eff0.5] 5=5:[1.1.0x25323d0.0x25323d0.66] 66=66379 11: 0 = [0.0.0.0] 0380 12: -0.253113553113553 = [2.2.0x252eff0.0x252eff0.253.77] -691=64845:[2.2.0x2532470.0x2532470.10.170] 2730=2730381 13: 0 = [0.0.0.0] 0382 14: 1.16666666666667 = [1.1.0x252eff0.0x252eff0.7] 7=7:[1.1.0x2533100.0x2533100.6] 6=6383 15: 0 = [0.0.0.0] 0384 16: -7.0921568627451 = [2.2.0x252eff0.0x252eff0.241.223] -3617=61919:[2.2.0x2533220.0x2533220.1.254] 510=510385 17: 0 = [0.0.0.0] 0386 18: 54.9711779448622 = [3.3.0x252eff0.0x252eff0.0.171.91] 43867=43867:[2.2.0x25332c0.0x25332c0.3.30] 798=798387 19: 0 = [0.0.0.0] 0388 20: -529.124242424242 = [3.3.0x252eff0.0x252eff0.253.85.237] -174611=16602605:[2.2.0x2533360.0x2533360.1.74] 330=330389 21: 0 = [0.0.0.0] 0390 22: 127766.152173913 = [3.3.0x252eff0.0x252eff0.89.173.251] 5877243=5877243:[1.1.0x2533400.0x2533400.46] 46=46391 23: -1444704.71111111 = [4.4.0x252eff0.0x252eff0.252.32.0.0] -65011712=4229955584:[1.1.0x2533400.0x2533400.45] 45=45392 24: 6065065.61355311 = [5.5.0x252eff0.0x252eff0.0.197.97.223.193] 3311525825=3311525825:[2.2.0x2533400.0x2533400.2.34] 546=546393 25: -2330168.88888889 = [4.4.0x252eff0.0x252eff0.254.192.0.0] -20971520=4273995776:[1.1.0x2533400.0x2533400.9] 9=9394 26: -59158873.9444444 = [4.4.0x252eff0.0x252eff0.192.135.135.173] -1064859731=3230107565:[1.1.0x2533400.0x2533400.18] 18=18395 27: -49432868.5714286 = [4.4.0x252eff0.0x252eff0.235.96.0.0] -346030080=3948937216:[1.1.0x2533400.0x2533400.7] 7=7396 28: 2136962632.93218 = [6.6.0x252eff0.0x252eff0.1.176.222.107.251.219] 1859157490651=1859157490651:[2.2.0x2533400.0x2533400.3.102] 870=870397 29: -5716836352 = [5.5.0x252eff0.0x252eff0.254.171.64.0.0] -5716836352=1093794791424398 30: -23117208246.0994 = [7.7.0x252eff0.0x252eff0.254.210.225.88.168.160.101] -331084656500635=71726509381427301:[2.2.0x2533400.0x2533400.55.242] 14322=14322399 31: 92695866026.6667 = [5.5.0x252eff0.0x252eff0.64.191.80.0.0] 278087598080=278087598080:[1.1.0x2533400.0x2533400.3] 3=3400 32: 579051330875.332 = [7.7.0x252eff0.0x252eff0.3.216.211.18.105.135.103] 1082825988736871=1082825988736871:[2.2.0x2533400.0x2533400.7.78] 1870=1870401 33: -2349312757564.95 = [6.6.0x252eff0.0x252eff0.211.33.43.0.0.0] -49335567908864=232139408801792:[1.1.0x2533400.0x2533400.21] 21=21402 34: -16444354762695.8 = [7.7.0x252eff0.0x252eff0.255.46.157.129.15.179.19] -230220966677741=71827373071250195:[1.1.0x2533400.0x2533400.14] 14=14403 35: 70013135239395.6 = [7.7.0x252eff0.0x252eff0.2.61.22.212.128.0.0] 630118217154560=630118217154560:[1.1.0x2533400.0x2533400.9] 9=9404 36: 524741348263712 = [9.9.0x252eff0.0x252eff0.54.152.5.5.239.72.78.54.3] 1007078348174232794627=1007078348174232794627:[3.3.0x2533400.0x2533400.29.72.214] 1919190=1919190405 37: -2.35594556200277e+15 = [7.7.0x252eff0.0x252eff0.230.227.215.9.0.0.0] -7067836686008320=64989757351919616:[1.1.0x2533400.0x2533400.3] 3=3406 38: -1.8687464782193e+16 = [8.8.0x252eff0.0x252eff0.254.113.167.25.71.109.183.151] -112124788693157993=18334619285016393623:[1.1.0x2533400.0x2533400.6] 6=6407

408 Verbrauchte Gesamtzeit: 0.161573409 Verbrauchte Zeit pro B0-B39: 0.161573410 anz = 1, bmax = 39411

412 results checked413

414 Verbrauchte Gesamtzeit: 0.188319415 Verbrauchte Zeit pro B0-B41: 0.188319416 anz = 1, bmax = 41417

418 results checked419

420 Verbrauchte Gesamtzeit: 0.218051421 Verbrauchte Zeit pro B0-B43: 0.218051422 anz = 1, bmax = 43423

424 results checked425

426 Verbrauchte Gesamtzeit: 0.251171427 Verbrauchte Zeit pro B0-B45: 0.251171428 anz = 1, bmax = 45429

430 results checked431

432 Verbrauchte Gesamtzeit: 0.292708433 Verbrauchte Zeit pro B0-B47: 0.292708434 anz = 1, bmax = 47435

436 results checked437

Page 81: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratnr.res, 26.4.2017 15:02:22 81

438 Verbrauchte Gesamtzeit: 0.333538439 Verbrauchte Zeit pro B0-B49: 0.333538440 anz = 1, bmax = 49441

442 results checked443

444 Verbrauchte Gesamtzeit: 0.378179445 Verbrauchte Zeit pro B0-B51: 0.378179446 anz = 1, bmax = 51447

448 results checked449

450 Verbrauchte Gesamtzeit: 0.424195451 Verbrauchte Zeit pro B0-B53: 0.424195452 anz = 1, bmax = 53453

454 results checked455

456 Verbrauchte Gesamtzeit: 0.474596457 Verbrauchte Zeit pro B0-B55: 0.474596458 anz = 1, bmax = 55459

460 results checked461

462 Verbrauchte Gesamtzeit: 0.517994463 Verbrauchte Zeit pro B0-B57: 0.517994464 anz = 1, bmax = 57465

466 results checked467

468 Verbrauchte Gesamtzeit: 0.581369469 Verbrauchte Zeit pro B0-B59: 0.581369470 anz = 1, bmax = 59471

472 results checked473

474 Verbrauchte Gesamtzeit: 0.639989475 Verbrauchte Zeit pro B0-B61: 0.639989476 anz = 1, bmax = 61477

478 results checked479

480 Verbrauchte Gesamtzeit: 0.707142481 Verbrauchte Zeit pro B0-B63: 0.707142482 anz = 1, bmax = 63483

484 results checked485

486 Verbrauchte Gesamtzeit: 0.780133487 Verbrauchte Zeit pro B0-B65: 0.780133488 anz = 1, bmax = 65489

490 results checked491

492 Verbrauchte Gesamtzeit: 0.855568493 Verbrauchte Zeit pro B0-B67: 0.855568494 anz = 1, bmax = 67495

496 results checked497

498 Verbrauchte Gesamtzeit: 0.936737499 Verbrauchte Zeit pro B0-B69: 0.936737500 anz = 1, bmax = 69501

502 results checked503

504 Verbrauchte Gesamtzeit: 1.009618505 Verbrauchte Zeit pro B0-B71: 1.009618506 anz = 1, bmax = 71507

508 results checked509

510 Verbrauchte Gesamtzeit: 1.10036511 Verbrauchte Zeit pro B0-B73: 1.10036512 anz = 1, bmax = 73513

514 results checked515

516 Verbrauchte Gesamtzeit: 1.206276517 Verbrauchte Zeit pro B0-B75: 1.206276518 anz = 1, bmax = 75

Page 82: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

82 ratnr.res, 26.4.2017 15:02:22

519

520 results checked521

522 Verbrauchte Gesamtzeit: 1.312149523 Verbrauchte Zeit pro B0-B77: 1.312149524 anz = 1, bmax = 77525

526 results checked527

528 Verbrauchte Gesamtzeit: 1.421027529 Verbrauchte Zeit pro B0-B79: 1.421027530 anz = 1, bmax = 79531

532 results checked533

534 Verbrauchte Gesamtzeit: 1.540011535 Verbrauchte Zeit pro B0-B81: 1.540011536 anz = 1, bmax = 81537

538 results checked539

540 Verbrauchte Gesamtzeit: 1.675015541 Verbrauchte Zeit pro B0-B83: 1.675015542 anz = 1, bmax = 83543

544 results checked545

546 Verbrauchte Gesamtzeit: 1.819921547 Verbrauchte Zeit pro B0-B85: 1.819921548 anz = 1, bmax = 85549

550 results checked551

552 Verbrauchte Gesamtzeit: 1.984628553 Verbrauchte Zeit pro B0-B87: 1.984628554 anz = 1, bmax = 87555

556 results checked557

558 Verbrauchte Gesamtzeit: 2.151017559 Verbrauchte Zeit pro B0-B89: 2.151017560 anz = 1, bmax = 89561

562 results checked563

564 Verbrauchte Gesamtzeit: 2.324334565 Verbrauchte Zeit pro B0-B91: 2.324334566 anz = 1, bmax = 91567

568 results checked569

570 Verbrauchte Gesamtzeit: 2.511146571 Verbrauchte Zeit pro B0-B93: 2.511146572 anz = 1, bmax = 93573

574 results checked575

576 Verbrauchte Gesamtzeit: 2.719357577 Verbrauchte Zeit pro B0-B95: 2.719357578 anz = 1, bmax = 95579

580 results checked581

582 Verbrauchte Gesamtzeit: 2.929233583 Verbrauchte Zeit pro B0-B97: 2.929233584 anz = 1, bmax = 97585

586 results checked587

588 Verbrauchte Gesamtzeit: 3.14983589 Verbrauchte Zeit pro B0-B99: 3.14983590 anz = 1, bmax = 99591

592 results checked593

594 Verbrauchte Gesamtzeit: 3.375213595 Verbrauchte Zeit pro B0-B101: 3.375213596 anz = 1, bmax = 101597

598 results checked599

Page 83: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ratnr.res, 26.4.2017 15:02:22 83

600 Verbrauchte Gesamtzeit: 3.628882601 Verbrauchte Zeit pro B0-B103: 3.628882602 anz = 1, bmax = 103603

604 results checked605

606 Verbrauchte Gesamtzeit: 3.91048607 Verbrauchte Zeit pro B0-B105: 3.91048608 anz = 1, bmax = 105609

610 results checked611

612 Verbrauchte Gesamtzeit: 4.228976613 Verbrauchte Zeit pro B0-B107: 4.228976614 anz = 1, bmax = 107615

616 results checked617

618 Verbrauchte Gesamtzeit: 4.608103619 Verbrauchte Zeit pro B0-B109: 4.608103620 anz = 1, bmax = 109621

622 results checked623

624 Verbrauchte Gesamtzeit: 5.042827625 Verbrauchte Zeit pro B0-B111: 5.042827626 anz = 1, bmax = 111627

628 results checked629

630 Verbrauchte Gesamtzeit: 5.515458631 Verbrauchte Zeit pro B0-B113: 5.515458632 anz = 1, bmax = 113633

634 results checked635

636 Verbrauchte Gesamtzeit: 6.07919800000001637 Verbrauchte Zeit pro B0-B115: 6.07919800000001638 anz = 1, bmax = 115639

640 results checked641

642 Verbrauchte Gesamtzeit: 6.71084643 Verbrauchte Zeit pro B0-B117: 6.71084644 anz = 1, bmax = 117645

646 results checked647

648 Verbrauchte Gesamtzeit: 7.557125649 Verbrauchte Zeit pro B0-B119: 7.557125650 anz = 1, bmax = 119651

652 results checked653

654 Verbrauchte Gesamtzeit: 8.66332800000001655 Verbrauchte Zeit pro B0-B121: 8.66332800000001656 anz = 1, bmax = 121657

658 results checked659

660 Verbrauchte Gesamtzeit: 10.737424661 Verbrauchte Zeit pro B0-B123: 10.737424662 anz = 1, bmax = 123663

664 results checked665

666 Verbrauchte Gesamtzeit: 13.808375667 Verbrauchte Zeit pro B0-B125: 13.808375668 anz = 1, bmax = 125669

670 results checked671

672 Verbrauchte Gesamtzeit: 17.869098673 Verbrauchte Zeit pro B0-B127: 17.869098674 anz = 1, bmax = 127675

676 results checked677

678 Verbrauchte Gesamtzeit: 22.981166679 Verbrauchte Zeit pro B0-B129: 22.981166680 anz = 1, bmax = 129

Page 84: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

84 ratnr.res, 26.4.2017 15:02:22

681

682 results checked683

684 Verbrauchte Gesamtzeit: 30.074866685 Verbrauchte Zeit pro B0-B131: 30.074866686 anz = 1, bmax = 131687

688 results checked689

690 Verbrauchte Gesamtzeit: 38.719174691 Verbrauchte Zeit pro B0-B133: 38.719174692 anz = 1, bmax = 133693

694 results checked695

696 Verbrauchte Gesamtzeit: 47.950158697 Verbrauchte Zeit pro B0-B135: 47.950158698 anz = 1, bmax = 135699

700 results checked701

702 Verbrauchte Gesamtzeit: 58.982487703 Verbrauchte Zeit pro B0-B137: 58.982487704 anz = 1, bmax = 137705

706 results checked707

708 Verbrauchte Gesamtzeit: 78.218336709 Verbrauchte Zeit pro B0-B139: 78.218336710 anz = 1, bmax = 139711

712 results checked713

714 Verbrauchte Gesamtzeit: 112.926319715 Verbrauchte Zeit pro B0-B141: 112.926319716 anz = 1, bmax = 141717

718 results checked719

720 Verbrauchte Gesamtzeit: 176.397993721 Verbrauchte Zeit pro B0-B143: 176.397993722 anz = 1, bmax = 143723

724 results checked725

726 Verbrauchte Gesamtzeit: 275.294206727 Verbrauchte Zeit pro B0-B145: 275.294206728 anz = 1, bmax = 145729

730 results checked731

732 Verbrauchte Gesamtzeit: 513.102291733 Verbrauchte Zeit pro B0-B147: 513.102291734 anz = 1, bmax = 147735

736 results checked737

738 Verbrauchte Gesamtzeit: 904.35042739 Verbrauchte Zeit pro B0-B149: 904.35042740 anz = 1, bmax = 149741

742 results checked743

Datei 109: uebnr.bat, 29.6.2016 11:57:521 gcc -c -I \vectra\nr\other -I . nrmpx.c2 gcc -I . -I \vectra\nr\other nrtst.c nrmpx.o -L c:\vectra\nr\ansi -lnr3 rem a4 gpp -I \vectra\nr\other -I . ulintnrt.c ulintnr.cpp nrmpx.o -L \vectra\nr\ansi -lnr -lm5 rem a6 gpp -g -o ratmnr -I c:\vectra\nr\other -D RAT_NR ratmain.cpp rzeit.c ulintnr.cpp nrmpx.o c:\vectra\nr\ansi\libnr.a7 gpp -g -o rm -I c:\vectra\nr\other -D RAT_NR rm.cpp rzeit.c ulintnr.cpp nrmpx.o c:\vectra\nr\ansi\libnr.a8

Datei 110: ulintnrt.cpp, 29.6.2016 11:57:561 // bruch/ulintnrt.cpp2

3 #include <iostream>4 #include <cstdlib>5

6 #include "ulintnr.hh"

Page 85: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

ulintnrt.cpp, 29.6.2016 11:57:56 85

7

8 using namespace std;9

10 void t1 ()11 {12 cout << "Test 1" << endl;13 ulintnr i;14 cout << "i=" << i << endl;15 ulintnr j (12);16 cout << "j1=" << j << endl;17 j = ulintnr (257);18 cout << "j2=" << j << endl;19 j = ulintnr (-257);20 cout << "j3=" << j << endl;21 j.neg();22 cout << "j4=" << j << endl;23 j.neg();24 cout << "j5=" << j << endl;25 ulintnr k (13);26 cout << "k=" << k << endl;27 j -= k;28 cout << "j6=" << j << endl;29 cout << "k=" << k << endl;30 }31

32 void t2 ()33 {34 cout << "Test 2" << endl;35 int i;36 ulintnr k, l;37 for (i = 1; i < 100000; i++)38 {39 if (i % 1000 == 0) std::cout << ".";40 k = ulintnr (i);41 l = ulintnr (-i);42 k.neg();43 if (k != l) std::cout << i << " " << std::endl << k << std::endl << l << std::endl;44 }45 }46

47 void t3 ()48 {49 cout << "Test 3" << endl;50 ulintnr t ("789");51 cout << t << endl;52 }53

54

55 void t4 ()56 {57 cout << "Test 4" << endl;58 ulintnr t1 (1415);59 ulintnr t2 (9265);60 cout << t1 << endl;61 cout << t2 << endl;62 t1 *= t2;63 cout << "Soll: 13109975; Ist: " << t1 << endl;64 }65

66 void t5 ()67 {68 cout << "Test 5" << endl;69 ulintnr t1 (141535897);70 ulintnr t2 (9265);71 cout << t1 << endl;72 cout << t2 << endl;73 t1 /= t2;74 cout << "Soll: 15276; Ist: " << t1 << endl;75 }76

77 void t5a ()78 {79 cout << "Test 5a" << endl;80 ulintnr t1 (141535897);81 ulintnr t2 (9265);82 cout << t1 << endl;83 cout << t2 << endl;84 t1 %= t2;85 cout << "Soll: 3757; Ist: " << t1 << endl;

Page 86: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

86 ulintnrt.cpp, 29.6.2016 11:57:56

86 }87

88 void t6 ()89 {90 cout << "Test 6" << endl;91 long i, j;92 const long st = 300000;93 ulintnr uj (-st);94 cout << uj << endl;95 ulintnr uk;96 cout << uk << endl;97 for (j = -st; j < 100000; j++)98 {99 if (j % 1000 == 0) cout << ".";100 uk = ulintnr (j);101 if (uj != uk) { cout << "uj!=uk" << j << endl << uk << endl << uj << endl; return; }102 i = (long) uk;103 if (j != i)104 { cout << "j!=i" << j << endl << i << endl << uk << endl << uj << endl; return; }105 uj++;106 }107 cout << endl;108 uj = ulintnr (st);109 for (j = st; j >= 70000; j--)110 {111 if (j % 1000 == 0) cout << ".";112 uk = ulintnr (j);113 if (uj != uk) { cout << "uj!=uk" << j << endl << uk << endl << uj << endl; return; }114 i = (long) uk;115 if (j != i)116 { cout << "j!=i" << j << endl << i << endl << uk << endl << uj << endl; return; }117 uj--;118 }119 cout << "Test 6 Ende" << endl;120 }121

122 int main ()123 {124 cout << "Programmbeginn" << endl;125 t1();126 t2();127 t3();128 t4();129 t5();130 t5a();131 t6();132 cout << "Programmende" << endl;133 }134

Datei 111: FILES.A2T, 26.4.2017 15:04:341 /O2 bruch\doc.doc3 bruch\FILES.A2T4

5 bruch\rzeit.tim6

7 bruch\ueblinux.8

9 bruch\ratc.c10 bruch\ratc.r11

12 bruch\bruch.cpp13 bruch\bruch.in14 bruch\bruch.res15

16 bruch\intext.hh17 bruch\rat.hh18 bruch\ratmain.cpp19 bruch\rzeit.h20 bruch\rzeit.c21

22 bruch\ulintmt.h23 bruch\apx.h24 bruch\ulintgmp.h25 bruch\gmpx.h26

27 bruch\ulintnr.hh

Page 87: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

string.cpp, 29.6.2016 11:58:04 87

28 bruch\ulintnr.cpp29

30 bruch\nrmpx.c31 bruch\nrmpx.h32 bruch\nrtst.c33 bruch\ratnr.res34 bruch\uebnr.bat35 bruch\ulintnrt.cpp36

37

Datei 112: string.cpp, 29.6.2016 11:58:041 /* ./ooprog/mystring/string.cpp: eigene Stringklasse */2

3 #include <iostream>4 #include <iomanip>5 #include <cstdlib>6 #include <cstring>7

8 using namespace std;9

10 class String11 { private:12 // Statische Member13 static int number;14

15 // Objekt-Member16 int nr; // Stempel17 int n; // n == 0 oder18 char * p; // p [0], p [1], ... , p [n-1], p [n] == 019

20 // interne Member-Funktionen21 void test () const22 { if (n) if (n != strlen (p)) { cout << "test"; exit (1); } }23 void prot (int i) const24 { test();25 char * a;26 switch (i)27 { case 1: a = "Con()"; break;28 case 2: a = "Con(ch)"; break;29 case 3: a = "Dest()"; break;30 case 4: a = "Con(ch*)"; break;31 case 5: a = "Con(l==0)"; break;32 case 6: a = "Con(l!=0)"; break;33 case 7: a = "Con(St&)"; break;34 case 8: a = "op=(St&)"; break;35 case 9: a = "(long)"; break;36 case 10: a = "cat"; break;37 default: a = "???"; break;38 }39 cout << setiosflags(ios::left) << setw (10) << a40 << " [nr=" << nr << ",n=" << n << ",a=" << i << "] ";41 if (n) cout << p;42 cout << "<\n";;43 }44 void del () { test (); if (n) delete [] p; n = 0; } // hier kein number--45 void konv (long, int); // Dezimalkonversion46 void stempel () { nr = number++; }47

48 public:49 // Konstruktoren50 String ()51 { stempel (); n = 0; prot (1); }52 String (const char ch)53 { stempel ();54 n = 1; p = new char [2];55 p [0] = ch; p [1] = 0;56 prot (2);57 }58 String (const char *);59 String (long);60 String (const String &);61

62 // Destruktor63 ~String () { prot (3); del (); }64

65 // Operator-Funktionen66 const String & operator = (const String &);

Page 88: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

88 string.cpp, 29.6.2016 11:58:04

67 char & operator [] (int i)68 { if (i < 0 || i >= n) { cout << "[]"; exit (1); }69 return p [i];70 }71 operator long ();72 String & operator += (const String &);73

74 // Sonstige Member-Funktionen75 int length () { return n; }; // Alternativ strlen (p) (falls s [3] = 0 im Programm vorkommt)76 friend String concat (String s1, String s2);77

78 // Ein-Ausgabe79 friend ostream & operator << (ostream & s, String st);80 };81

82 // Statische Member83 int String :: number = 0;84

85 // Konstruktoren86 String :: String (const char * st)87 { stempel ();88 n = strlen (st);89 if (n > 0)90 { p = new char [n + 1];91 strcpy (p, st);92 }93 prot (4);94 }95

96 void String :: konv (long l, int i) // l Restzahl; i Position in *this97 { int r;98 r = l % 10; // neue letzte Ziffer (lokal)99 l /= 10; // neuer vorderer Rest (Wertargument)100 i++; // neue Position (Wertargument)101 n++; // neue Laenge (member-Variable)102 if (l)103 { konv (l, i); // vorderen Rest bearbeiten104 } else {105 p = new char [n+1]; // Speicherplatz erzeugen106 p [n] = 0;107 }108 p [n-i] = r + '0'; // Ziffer r speichern109 }110

111 String :: String (long l)112 { stempel ();113 if (!l)114 { n = 1;115 p = new char [2];116 p [0] = '0';117 p [1] = 0;118 prot (5);119 return;120 }121 bool neg;122 neg = false; n = 0;123 if (l < 0) { neg = true; n = 1; l = -l; }124 konv (l, 0);125 if (neg) p [0] = '-';126 prot (6);127 }128

129 String :: String (const String & st)130 { stempel ();131 n = st.n;132 if (n > 0)133 { p = new char [n + 1];134 strcpy (p, st.p);135 }136 prot (7);137 }138

139 const String & String :: operator = (const String & st)140 { if (this != &st) // s = s zieht keine Taetigkeit nach sich141 { del ();142 n = st.n;143 if (n > 0)

Page 89: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

string.cpp, 29.6.2016 11:58:04 89

144 { p = new char [n + 1];145 strcpy (p, st.p);146 } }147 prot (8);148 return *this;149 }150

151 String :: operator long ()152 { prot (9);153 long l;154 int i, neg;155 l = 0;156 i = 0;157 neg = 0;158 if (i < n)159 { if (p [i] == '+') i++;160 else if (p [i] == '-') { neg = 1; i++; }161 }162 while (i < n && '0' <= p [i] && p [i] <= '9')163 { l = l * 10 + p [i++] - '0';164 }165 if (neg) l = -l;166 return l;167 }168

169 String & String :: operator += (const String & st)170 {171 }172

173 String concat (String s1, String s2)174 { String s;175 s.n = s1.n + s2.n;176 if (s.n > 0)177 { s.p = new char [s.n + 1];178 if (s1.n > 0) strcpy (s.p, s1.p);179 if (s2.n > 0) strcat (s.p, s2.p);180 }181 s.prot (10);182 return s;183 }184

185 ostream & operator << (ostream & s, String st) // const String & st besser186 { ostream::sentry se(s);187 if (se)188 { int i;189 st.test ();190 for (i = 0; i < st.n; i++) s << st [i];191 }192 return s;193 }194

195 int main ()196 { cout << endl << "Programmbeginn" << endl;197 String a;198 String b ("Hans");199 String c ('H');200 String d1 ((long)-125), d2 ((long)0), d3 (long(1256)), d4 ((long)-123456789);201 cout << "Alles gekonstruktet " << endl;202 long l;203 l = d1; cout << l << endl;204 l = d2; cout << l << endl;205 l = d3; cout << l << endl;206 l = d4; cout << l << endl;207 cout << d1 << endl;208 for (int i = 0; i < d1.length (); i++) { cout << d1 [i]; d1 [i] = i % 10 + 'A'; }209 cout << d1 << endl;210 for (int i = 0; i < d1.length (); i++) { cout << d1 [i]; d1 [i] = i % 10 + 'a'; }211 cout << d1 << endl;212 cout << b << endl;213 cout << c << endl;214 a = concat (b, c);215 cout << a << endl;216 cout << "Vor return" << endl;217 return 0;218 }219

220

221

Page 90: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

90 string.cpp, 29.6.2016 11:58:04

222

Datei 113: string.res, 26.4.2017 10:05:321

2 Programmbeginn3 Con() [nr=0,n=0,a=1] <4 Con(ch*) [nr=1,n=4,a=4] Hans<5 Con(ch) [nr=2,n=1,a=2] H<6 Con(l!=0) [nr=3,n=4,a=6] -125<7 Con(l==0) [nr=4,n=1,a=5] 0<8 Con(l!=0) [nr=5,n=4,a=6] 1256<9 Con(l!=0) [nr=6,n=10,a=6] -123456789<10 Alles gekonstruktet11 (long) [nr=3,n=4,a=9] -125<12 -12513 (long) [nr=4,n=1,a=9] 0<14 015 (long) [nr=5,n=4,a=9] 1256<16 125617 (long) [nr=6,n=10,a=9] -123456789<18 -12345678919 Con(St&) [nr=7,n=4,a=7] -125<20 -12521 Dest() [nr=7,n=4,a=3] -125<22 -125Con(St&) [nr=8,n=4,a=7] ABCD<23 ABCD24 Dest() [nr=8,n=4,a=3] ABCD<25 ABCDCon(St&) [nr=9,n=4,a=7] abcd<26 abcd27 Dest() [nr=9,n=4,a=3] abcd<28 Con(St&) [nr=10,n=4,a=7] Hans<29 Hans30 Dest() [nr=10,n=4,a=3] Hans<31 Con(St&) [nr=11,n=1,a=7] H<32 H33 Dest() [nr=11,n=1,a=3] H<34 Con(St&) [nr=12,n=1,a=7] H<35 Con(St&) [nr=13,n=4,a=7] Hans<36 Con() [nr=14,n=0,a=1] <37 cat [nr=14,n=5,a=10] HansH<38 op=(St&) [nr=0,n=5,a=8] HansH<39 Dest() [nr=14,n=5,a=3] HansH<40 Dest() [nr=13,n=4,a=3] Hans<41 Dest() [nr=12,n=1,a=3] H<42 Con(St&) [nr=15,n=5,a=7] HansH<43 HansH44 Dest() [nr=15,n=5,a=3] HansH<45 Vor return46 Dest() [nr=6,n=10,a=3] -123456789<47 Dest() [nr=5,n=4,a=3] 1256<48 Dest() [nr=4,n=1,a=3] 0<49 Dest() [nr=3,n=4,a=3] abcd<50 Dest() [nr=2,n=1,a=3] H<51 Dest() [nr=1,n=4,a=3] Hans<52 Dest() [nr=0,n=5,a=3] HansH<53

Datei 114: cpp6.a2t, 29.6.2016 11:57:341 ooprog\mystring\string.cpp2 ooprog\mystring\string.res3

Datei 115: �les.a2t, 29.6.2016 11:58:001 ooprog\inherit\files.a2t2 ooprog\inherit\shape1.cc3 ooprog\inherit\shape.cpp4 ooprog\inherit\shape.res5

6 ooprog\inherit\shape0.c7 ooprog\inherit\shape0.res8

9 ooprog\inherit\shape2.cpp10 ooprog\inherit\shape2.res11 ooprog\inherit\shape3.cpp12 ooprog\inherit\shape3.res13 ooprog\inherit\shape.h14 ooprog\inherit\punkt.h15 ooprog\inherit\punkt.cpp

Page 91: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

shape1.cc, 29.6.2016 11:58:00 91

16 ooprog\inherit\dreieck.h17 ooprog\inherit\dreieck.cpp18 ooprog\inherit\kreis.h19 ooprog\inherit\kreis.cpp20

Datei 116: shape1.cc, 29.6.2016 11:58:001 // ./ooprog/inherit/shape1.cc2

3 #include <iostream>4 //#include "mathlib1.h"5

6 using namespace std;7

8 // **************************************************************************9 // Allgemeine Hilfsdefinitionen10

11 const double Pi = 3.141592653589793;12 const double TwoPi = 2 * Pi;13

14 void red_phi (double & phi)15

16 { while (phi >= TwoPi) phi -= TwoPi;17 while (phi < 0) phi += TwoPi;18 }19

20 // **************************************************************************21 // Die Klasse point22

23 class point24 { double x, y; // Koordinaten des Punktes25 public:26 point () { x = y = 0; }27 point (double x) { point::x = x; y = 0; }28 point (double x, double y) { point::x = x; point::y = y; }29 void mov_abs (double nx = 0, double ny = 0) { x = nx; y = ny; }30 void mov_rel (double nx = 0, double ny = 0) { x += nx; y += ny; }31 friend ostream & operator << (ostream & s, point p);32 };33

34 ostream & operator << (ostream & s, point p)35

36 { return s << '(' << p.x << '/' << p.y << ')';37 }38

39 // **************************************************************************40 // Die Klasse shape41

42 class shape43 : public point // Lage des geometrischen Objekts44 { double phi; // Richtung (Winkel zur x-Achse)45 public:46 shape (double x = 0, double y = 0, double p = 0) : point (x, y) { phi = p; }47 void rot_abs (double p) { phi = p; red_phi (phi); }48 void rot_rel (double p) { phi += p; red_phi (phi); }49 virtual double length ();50 virtual double area ();51 friend ostream & operator << (ostream & s, shape sh);52 };53

54 double shape::length ()55

56 { return 0;57 }58

59 double shape::area ()60

61 { return 0;62 }63

64 ostream & operator << (ostream & s, shape sh)65

66 { point p;67 p = sh;68 return s << p << '[' << sh.phi << ']';69 }70

71 // **************************************************************************

Page 92: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

92 shape1.cc, 29.6.2016 11:58:00

72 // Die Klasse poly73

74 const int polydef = 10;75

76 class poly77 : public shape // Lage und Richtung des geometrischen Objekts78 { int size;79 int nmbr;80 ::point * pnts;81 public:82 poly () { size = 0; }83 poly (int n) { size = n; nmbr = 0; pnts = new ::point [n]; }84 poly (poly &);85 poly & operator = (poly & p);86 virtual void add (::point p);87 virtual void del (int pn);88 virtual double length ();89 virtual double area ();90 friend ostream & operator << (ostream & s, poly p);91 };92

93 double poly::length ()94

95 { return 0;96 }97

98 double poly::area ()99

100 { return 0;101 }102

103 ostream & operator << (ostream & s, poly p)104

105 {106 s << (::point) p << '[' << (shape) p << ']';107 return s;108 }109

110 // **************************************************************************111 // Testprozeduren112

113 void tst_point ()114

115 { point p;116 point p1 (3, 2);117 cout << " p = " << p << endl;118 cout << " p1 = " << p1 << endl;119 p.mov_abs (5, 4);120 cout << " p = " << p << endl;121 p.mov_rel (5, 4);122 cout << " p = " << p << endl;123 }124

125 void tst_shape ()126

127 { shape s;128 cout << " s = " << s << endl;129 }130

131 // **************************************************************************132 // und (wer haette es noch geglaubt?) main133

134 int main ()135

136 { tst_point ();137 tst_shape ();138 return 0;139 }140

Datei 117: shape.cpp, 29.6.2016 11:57:581 // ./ooprog/inherit/shape.cpp2

3 #include <cmath>4 #include <iostream>5 #include <cstdlib>6

7 using namespace std;8

Page 93: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

shape.cpp, 29.6.2016 11:57:58 93

9 // **************************************************************************10 // Allgemeine Hilfsdefinitionen11

12 const double Pi = 3.141592653589793238462643;13 const double TwoPi = 2 * Pi;14

15 void red_phi (double & phi)16 { while (phi >= TwoPi) phi -= TwoPi;17 while (phi < 0) phi += TwoPi;18 }19

20 double sqr (double x)21 { return x*x;22 }23

24 // **************************************************************************25 // Die Klasse point26

27 class point28 {29 private:30 double x, y; // Koordinaten des Punktes31 public:32 point (double x=0, double y=0) { point::x = x; point::y = y; }33 void mov_abs (double nx = 0, double ny = 0) { x = nx; y = ny; }34 void mov_rel (double nx = 0, double ny = 0) { x += nx; y += ny; }35 double px () const { return x; }36 double py () const { return y; }37 friend ostream & operator << (ostream & s, point p);38 };39

40 ostream & operator << (ostream & s, point p)41 { ostream::sentry se(s);42 if (se)43 { s << '(' << p.x << '/' << p.y << ')';44 }45 return s;46 }47

48 // **************************************************************************49 // Die Klasse shape50

51 class shape52 :53 public54 point // Lage des geometrischen Objekts55 {56 private:57 double phi; // Richtung (Winkel zur x-Achse)58 public:59 shape (double x = 0, double y = 0, double p = 0) : point (x, y) { phi = p; red_phi (phi); }60 void rot_abs (double p) { phi = p; red_phi (phi); }61 void rot_rel (double p) { phi += p; red_phi (phi); }62 virtual double length () const ;63 virtual double area () const ;64 friend ostream & operator << (ostream & s, shape sh);65 };66

67 double shape::length () const68 { return 0;69 }70

71 double shape::area () const72 { return 0;73 }74

75 ostream & operator << (ostream & s, shape sh)76 { ostream::sentry se(s);77 if (se)78 { point * p;79 p = & sh;80 s << *p << '[' << sh.phi << ']';81 }82 return s;83 }84

85 // **************************************************************************86 // Die Klasse polygon

Page 94: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

94 shape.cpp, 29.6.2016 11:57:58

87

88 const int polydef = 10;89

90 point * const nil = (point *) 0;91

92 class polygon93 :94 public95 shape // Lage und Richtung des geometrischen Objekts96 { int size; // allocated97 int nmbr; // used98 protected:99 point * pnts;100 public:101 polygon () { size = nmbr = 0; pnts = nil; }102 polygon (int n) { size = n; nmbr = 0; pnts = new point [n]; }103 polygon (polygon &);104 polygon & operator = (const polygon & p);105 ~polygon () { if (size > 0) delete [] pnts; }106 virtual void add (point p);107 virtual void del (int pn);108 virtual double length () const ;109 virtual double area () const ;110 int pn () const { return nmbr; }111 friend ostream & operator << (ostream & s, polygon p);112 };113

114 polygon::polygon (polygon & p)115 { size = p.size;116 nmbr = p.nmbr;117 if (size > 0) pnts = new point [size];118 for (int i = 0; i < size; i++) pnts [i] = p.pnts [i];119 }120

121 polygon & polygon::operator = (const polygon & p)122 { if (&p != this)123 { if (size > 0) delete [] pnts;124 size = p.size;125 nmbr = p.nmbr;126 if (size > 0) pnts = new point [size];127 for (int i = 0; i < size; i++) pnts [i] = p.pnts [i];128 }129 return *this;130 }131

132 void polygon::add (point p)133 { if (nmbr == size)134 { point * p;135 p = new point [size + polydef];136 for (int i = 0; i < nmbr; i++) p [i] = pnts [i];137 delete [] pnts;138 pnts = p;139 size += polydef;140 }141 pnts [nmbr++] = p;142 }143

144 void polygon::del (int pn)145 { if (pn < 0 || pn >= nmbr) return;146 for (int i = pn; i < nmbr - 1; i++) pnts [i] = pnts [i+1];147 nmbr--;148 }149

150 double polygon::length () const151 { double s;152 s = 0;153 point * p1, * p2;154 for (int i = 1; i < nmbr; i++)155 { p1 = & (pnts [i-1]);156 p2 = & (pnts [i]);157 s += sqrt (sqr (p1->px() - p2->px()) + sqr (p1->py() - p2->py()));158 }159 p1 = & (pnts [nmbr-1]);160 p2 = & (pnts [0]);161 s += sqrt (sqr (p1->px() - p2->px()) + sqr (p1->py() - p2->py()));162 return s;163 }164

Page 95: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

shape.cpp, 29.6.2016 11:57:58 95

165 double polygon::area () const166 { return 0; // zu kompliziert fuer das Vererbungsbeispiel167 }168

169 ostream & operator << (ostream & s, polygon p)170 { ostream::sentry se(s);171 if (se)172 { shape * sh;173 sh = & p;174 s << * sh << '/' << p.size << ',' << p.nmbr << '/';175 for (int i = 0; i < p.nmbr; i++)176 { point * q;177 q = & ((p.pnts) [i]);178 s << *q << '/';179 } }180 return s;181 }182

183 // **************************************************************************184 // Die Klasse triangle185

186 class triangle187 :188 public189 polygon // Lage, Richtung und Punkte des Dreiecks190 {191 public:192 triangle () : polygon (3) { };193 ~triangle () { };194 virtual void add (point p);195 virtual void del (int pn);196 virtual double length () const ;197 virtual double area () const ;198 friend ostream & operator << (ostream & s, triangle p);199 };200

201 void triangle::add (point p)202 { if (pn () < 3) polygon::add (p);203 }204

205 void triangle::del (int pn)206 { polygon::del (pn);207 }208

209 double triangle::length () const210 { if (polygon::pn () != 3) { cout << "Fehler in triangle::length ()" << endl; exit (1); }211 return polygon::length ();212 }213

214 double triangle::area () const215 { if (polygon::pn () != 3) { cout << "Fehler in triangle::area ()" << endl; exit (1); }216 // Flaeche Dreieck ABC = 1/2 * Flaeche Parallelogramm (b-a, c-a)217 // Flaeche Parallelogramm (b-a, c-a) = (b-a) * (c-a)218 // und Norm (Vektorprodukt a x b) = Flaeche des von a und b aufgespannten Parallogramms219 double x1, y1, x2, y2;220 x1 = pnts [1] . px () - pnts [0] . px ();221 y1 = pnts [1] . py () - pnts [0] . py ();222 x2 = pnts [2] . px () - pnts [0] . px ();223 y2 = pnts [2] . py () - pnts [0] . py ();224 return fabs ((x1 * y2 - x2 * y1) / 2);225 }226

227 ostream & operator << (ostream & s, triangle t)228 { ostream::sentry se(s);229 if (se)230 { polygon * p;231 p = & t;232 s << "Dreieck: " << * p;233 }234 return s;235 }236

237 // **************************************************************************238 // Testprozeduren239

240 void tst_point ()241 { point p;242 point p1 (3, 2);

Page 96: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

96 shape.cpp, 29.6.2016 11:57:58

243 cout << " p = " << p << endl;244 cout << " p1 = " << p1 << endl;245 p.mov_abs (5, 4);246 cout << " p = " << p << endl;247 p.mov_rel (5, 4);248 cout << " p = " << p << endl;249 }250

251 void tst_shape ()252 { shape s;253 cout << " s = " << s << endl;254 s.rot_abs (Pi/6);255 cout << " s = " << s << endl;256 s.rot_rel (Pi/6);257 cout << " s = " << s << endl;258 s.rot_rel (Pi/6);259 cout << " s = " << s << endl;260 cout << "Laenge: " << s.length () << " / Flaeche: " << s.area () << endl;261 }262

263 void tst_poly ()264 { polygon p;265 int i;266 cout << " p = " << p << endl;267 point q (3, 4);268 for (i = 0; i < 25; i++)269 { p.add (q);270 cout << " p = " << p << endl;271 }272 for (i = 0; i < 20; i++)273 { p.del (0);274 cout << " p = " << p << endl;275 }276 cout << "Laenge: " << p.length () << " / Flaeche: " << p.area () << endl;277 }278

279 void tst_triangle ()280 { triangle p;281 int i;282 cout << " p = " << p << endl;283 point q (3, 4);284 for (i = 0; i < 7; i++)285 { p.add (q);286 cout << "p vergroessern: p = " << p << endl;287 }288 for (i = 0; i < 10; i++)289 { p.del (0);290 cout << "p verkleinern: p = " << p << endl;291 }292 p.add (q); p.add (point (4, 1)); p.add (point (5, 3));293 cout << "Testdreieck: " << p;294 cout << "Laenge: " << p.length () << " / Flaeche: " << p.area () << endl;295 for (i = 0; i < 10; i++)296 { p.del (0);297 }298 p.add (point (4, 0)); p.add (point (0, 5)); p.add (point (0, 0));299 cout << "Testdreieck: " << p;300 cout << "Laenge: " << p.length () << " / Flaeche: " << p.area () << endl;301 }302

303 // **************************************************************************304 // und (wer haette es noch geglaubt?) main305

306 int main ()307 { cout << "Test der Klasse point" << endl;308 tst_point ();309 cout << "Test der Klasse shape" << endl;310 tst_shape ();311 cout << "Test der Klasse polygon" << endl;312 tst_poly ();313 cout << "Test der Klasse triangle" << endl;314 tst_triangle ();315 cout << "Programmende" << endl;316 return 0;317 }318

Datei 118: shape.res, 26.4.2017 10:05:30

Page 97: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

shape.res, 26.4.2017 10:05:30 97

1 Test der Klasse point2 p = (0/0)3 p1 = (3/2)4 p = (5/4)5 p = (10/8)6 Test der Klasse shape7 s = (0/0)[0]8 s = (0/0)[0.523599]9 s = (0/0)[1.0472]10 s = (0/0)[1.5708]11 Laenge: 0 / Flaeche: 012 Test der Klasse polygon13 p = (0/0)[0]/0,0/14 p = (0/0)[0]/10,1/(3/4)/15 p = (0/0)[0]/10,2/(3/4)/(3/4)/16 p = (0/0)[0]/10,3/(3/4)/(3/4)/(3/4)/17 p = (0/0)[0]/10,4/(3/4)/(3/4)/(3/4)/(3/4)/18 p = (0/0)[0]/10,5/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/19 p = (0/0)[0]/10,6/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/20 p = (0/0)[0]/10,7/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/21 p = (0/0)[0]/10,8/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/22 p = (0/0)[0]/10,9/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/23 p = (0/0)[0]/10,10/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/24 p = (0/0)[0]/20,11/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/25 p = (0/0)[0]/20,12/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/26 p = (0/0)[0]/20,13/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/27 p = (0/0)[0]/20,14/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/28 p = (0/0)[0]/20,15/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/29 p = (0/0)[0]/20,16/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/30 p = (0/0)[0]/20,17/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/31 p = (0/0)[0]/20,18/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/32 p = (0/0)[0]/20,19/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/33 p = (0/0)[0]/20,20/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/34 p = (0/0)[0]/30,21/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/35 p = (0/0)[0]/30,22/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/36 p = (0/0)[0]/30,23/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/37 p = (0/0)[0]/30,24/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/38 p = (0/0)[0]/30,25/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/39 p = (0/0)[0]/30,24/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/40 p = (0/0)[0]/30,23/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/41 p = (0/0)[0]/30,22/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/42 p = (0/0)[0]/30,21/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/43 p = (0/0)[0]/30,20/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/44 p = (0/0)[0]/30,19/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/45 p = (0/0)[0]/30,18/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/46 p = (0/0)[0]/30,17/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/47 p = (0/0)[0]/30,16/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/48 p = (0/0)[0]/30,15/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/49 p = (0/0)[0]/30,14/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/50 p = (0/0)[0]/30,13/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/51 p = (0/0)[0]/30,12/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/52 p = (0/0)[0]/30,11/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/53 p = (0/0)[0]/30,10/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/54 p = (0/0)[0]/30,9/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/55 p = (0/0)[0]/30,8/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/56 p = (0/0)[0]/30,7/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/57 p = (0/0)[0]/30,6/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/58 p = (0/0)[0]/30,5/(3/4)/(3/4)/(3/4)/(3/4)/(3/4)/59 Laenge: 0 / Flaeche: 060 Test der Klasse triangle61 p = Dreieck: (0/0)[0]/3,0/62 p vergroessern: p = Dreieck: (0/0)[0]/3,1/(3/4)/63 p vergroessern: p = Dreieck: (0/0)[0]/3,2/(3/4)/(3/4)/64 p vergroessern: p = Dreieck: (0/0)[0]/3,3/(3/4)/(3/4)/(3/4)/65 p vergroessern: p = Dreieck: (0/0)[0]/3,3/(3/4)/(3/4)/(3/4)/66 p vergroessern: p = Dreieck: (0/0)[0]/3,3/(3/4)/(3/4)/(3/4)/67 p vergroessern: p = Dreieck: (0/0)[0]/3,3/(3/4)/(3/4)/(3/4)/68 p vergroessern: p = Dreieck: (0/0)[0]/3,3/(3/4)/(3/4)/(3/4)/69 p verkleinern: p = Dreieck: (0/0)[0]/3,2/(3/4)/(3/4)/70 p verkleinern: p = Dreieck: (0/0)[0]/3,1/(3/4)/71 p verkleinern: p = Dreieck: (0/0)[0]/3,0/72 p verkleinern: p = Dreieck: (0/0)[0]/3,0/73 p verkleinern: p = Dreieck: (0/0)[0]/3,0/74 p verkleinern: p = Dreieck: (0/0)[0]/3,0/75 p verkleinern: p = Dreieck: (0/0)[0]/3,0/76 p verkleinern: p = Dreieck: (0/0)[0]/3,0/77 p verkleinern: p = Dreieck: (0/0)[0]/3,0/

Page 98: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

98 shape.res, 26.4.2017 10:05:30

78 p verkleinern: p = Dreieck: (0/0)[0]/3,0/79 Testdreieck: Dreieck: (0/0)[0]/3,3/(3/4)/(4/1)/(5/3)/Laenge: 7.63441 / Flaeche: 2.580 Testdreieck: Dreieck: (0/0)[0]/3,3/(4/0)/(0/5)/(0/0)/Laenge: 15.4031 / Flaeche: 1081 Programmende82

Datei 119: shape0.c, 29.6.2016 11:57:581 /* ./ooprog/inherit/shape2.c */2 /* Vererbung und Polymorphismus: Vergleich von C und C++ */3

4 #include <stdio.h>5 #include <math.h>6

7 #define Pi 3.1415926535897938

9 struct SPunkt10 { double x, y; /* Koordinaten */11 };12

13 typedef struct SPunkt Punkt;14

15 struct SKreis16 { Punkt m; /* Mittelpunkt */17 double r; /* Radius */18 };19

20 typedef struct SKreis Kreis;21

22 struct SDreieck23 { Punkt A, B, C;24 };25

26 typedef struct SDreieck Dreieck;27

28 enum EShapeTyp { pkt, krs, dck };29

30 typedef enum EShapeTyp ShapeTyp;31

32 union UShapeVal33 { Punkt p;34 Kreis k;35 Dreieck d;36 };37

38 typedef union UShapeVal ShapeVal;39

40 struct SShape41 { ShapeTyp t;42 ShapeVal v;43 };44

45 typedef struct SShape Shape;46

47 void prShape (FILE * f, Shape s)48 { switch (s.t)49 { case pkt: fprintf (f, "Punkt (%e, %e)", s.v.p.x, s.v.p.y); break;50 case krs: fprintf (f, "Kreis [(%e, %e), %e]", s.v.k.m.x, s.v.k.m.y, s.v.k.r); break;51 case dck:52 fprintf (f, "Dreieck [(%e, %e), (%e, %e), (%e, %e)]",53 s.v.d.A.x, s.v.d.A.y,54 s.v.d.B.x, s.v.d.B.y,55 s.v.d.C.x, s.v.d.C.y56 );57 break;58 } }59

60 double area (Shape s)61 { double x1, y1, x2, y2;62 switch (s.t)63 { case pkt: return 0;64 case krs: return s.v.k.r * s.v.k.r * Pi;65 case dck:66 x1 = s.v.d.B.x - s.v.d.A.x;67 y1 = s.v.d.B.y - s.v.d.A.y;68 x2 = s.v.d.C.x - s.v.d.A.x;69 y2 = s.v.d.C.y - s.v.d.A.y;70 return fabs ((x1 * y2 - x2 * y1) / 2);71 } }72

Page 99: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

shape2.cpp, 29.6.2016 11:58:00 99

73 int main (void)74 { Shape p, k, d;75 p.t = pkt; p.v.p.x = 2; p.v.p.y = 3; /* Ein Punkt */76 k.t = krs; k.v.k.m.x = 4; k.v.k.m.y = 5; k.v.k.r = 2; /* Ein Kreis */77 d.t = dck; d.v.d.A.x = 1; d.v.d.A.y = 0;78 d.v.d.B.x = 5; d.v.d.B.y = 2;79 d.v.d.C.x = 6; d.v.d.C.y = 1; /* Ein Dreieck */80

81 prShape (stdout, p); printf ("Flaeche: %e\n", area (p));82 prShape (stdout, k); printf ("Flaeche: %e\n", area (k));83 prShape (stdout, d); printf ("Flaeche: %e\n", area (d));84

85 return 0;86 }87

Datei 120: shape0.res, 26.4.2017 10:05:281 Punkt (2.000000e+00, 3.000000e+00)Flaeche: 0.000000e+002 Kreis [(4.000000e+00, 5.000000e+00), 2.000000e+00]Flaeche: 1.256637e+013 Dreieck [(1.000000e+00, 0.000000e+00), (5.000000e+00, 2.000000e+00), (6.000000e+00, 1.000000e+00)]Flaeche: 3.000000e+004

Datei 121: shape2.cpp, 29.6.2016 11:58:001 // ./ooprog/inherit/shape2.cpp2 // Vererbung und Polymorphismus: Vergleich von C und C++3

4 #include <iostream>5 #include <cmath>6

7 using namespace std;8

9 const double Pi = 3.141592653589793;10

11 class Shape12 {13 public:14 virtual double area () = 0;15 virtual void print () = 0;16 };17

18 class Punkt : public Shape19 { double x, y; // Koordinaten20 public:21 Punkt (double a, double b) { x = a; y = b; }22 virtual double area () { return 0; }23 virtual void print ();24 double px () { return x; }25 double py () { return y; }26 };27

28 void Punkt :: print ()29 { cout << "Punkt: (" << x << ", " << y << ")";30 }31

32 class Kreis : public Shape33 { Punkt m;34 double r;35 public:36 Kreis (double a, double b, double c) : m (a, b) { r = c; }37 virtual double area () { return r * r * Pi; }38 virtual void print ();39 };40

41 void Kreis :: print ()42 { cout << "Kreis: ["; m.print (); cout << ", " << r << "]";43 }44

45 class Dreieck : public Shape46 { Punkt A, B, C;47 public:48 Dreieck (double ax, double ay, double bx, double by, double cx, double cy) : A (ax, ay), B (bx, by), C (cx, cy) {};49 virtual double area ();50 virtual void print ();51 };52

53 double Dreieck :: area ()54 { double x1, y1, x2, y2;55 x1 = B . px () - A . px ();56 y1 = B . py () - A . py ();

Page 100: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

100 shape2.cpp, 29.6.2016 11:58:00

57 x2 = C . px () - A . px ();58 y2 = C . py () - A . py ();59 return fabs ((x1 * y2 - x2 * y1) / 2);60 }61

62 void Dreieck :: print ()63 { cout << "Dreieck: ["; A.print (); cout << ", "; B.print (); cout << ", "; C.print (); cout << "]";64 }65

66 int main ()67 { Punkt p (2, 3);68 Kreis k (4, 5, 2);69 Dreieck d (1, 0, 5, 2, 6, 1);70 Shape * h;71

72 cout << "Direkter Aufruf" << endl;73 p.print (); cout << " " << p.area () << endl;74 k.print (); cout << " " << k.area () << endl;75 d.print (); cout << " " << d.area () << endl;76

77 cout << "Polymorpher Aufruf" << endl;78 h = &p; h->print (); cout << " " << h->area () << endl;79 h = &k; h->print (); cout << " " << h->area () << endl;80 h = &d; h->print (); cout << " " << h->area () << endl;81

82 return 0;83 }84

Datei 122: shape2.res, 26.4.2017 10:05:301 Direkter Aufruf2 Punkt: (2, 3) 03 Kreis: [Punkt: (4, 5), 2] 12.56644 Dreieck: [Punkt: (1, 0), Punkt: (5, 2), Punkt: (6, 1)] 35 Polymorpher Aufruf6 Punkt: (2, 3) 07 Kreis: [Punkt: (4, 5), 2] 12.56648 Dreieck: [Punkt: (1, 0), Punkt: (5, 2), Punkt: (6, 1)] 39

Datei 123: shape3.cpp, 29.6.2016 11:58:001 // ./ooprog/inherit/shape3.cpp2 // Vererbung und Polymorphismus: Vergleich von C und C++3

4 #include <iostream>5 #include "shape.h"6 #include "punkt.h"7 #include "kreis.h"8 #include "dreieck.h"9

10 using namespace std;11

12 int main ()13 { Punkt p (2, 3);14 Kreis k (4, 5, 2);15 Dreieck d (1, 0, 5, 2, 6, 1);16 Shape * h;17

18 p.print (); cout << " " << p.area () << endl;19 k.print (); cout << " " << k.area () << endl;20 d.print (); cout << " " << d.area () << endl;21

22 h = &p; h->print (); cout << " " << h->area () << endl;23 h = &k; h->print (); cout << " " << h->area () << endl;24 h = &d; h->print (); cout << " " << h->area () << endl;25

26 return 0;27 }28

Datei 124: shape3.res, 26.4.2017 10:05:301 Punkt: (2, 3) 02 Kreis: [Punkt: (4, 5), 2] 12.56643 Dreieck: [Punkt: (1, 0), Punkt: (5, 2), Punkt: (6, 1)] 34 Punkt: (2, 3) 05 Kreis: [Punkt: (4, 5), 2] 12.56646 Dreieck: [Punkt: (1, 0), Punkt: (5, 2), Punkt: (6, 1)] 37

Page 101: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

dreieck.cpp, 29.6.2016 11:58:00 101

Datei 125: shape.h, 29.6.2016 11:58:001 #if !defined __SHAPE_H2 #define __SHAPE_H3

4 class Shape5 {6 public:7 virtual double area () = 0;8 virtual void print () = 0;9 };10

11 #endif12

Datei 126: punkt.h, 29.6.2016 11:58:001 #if ! defined __punkt_h2 #define __punkt_h3

4 #include "shape.h"5

6 class Punkt : public Shape7 { double x, y; // Koordinaten8 public:9 Punkt (double a, double b) { x = a; y = b; }10 virtual double area () { return 0; }11 virtual void print ();12 double px () { return x; }13 double py () { return y; }14 };15

16 #endif17

Datei 127: punkt.cpp, 29.6.2016 11:57:581 // ./ooprog/inherit/PUNKT.CPP2

3 #include <iostream>4 #include "punkt.h"5

6 using namespace std;7

8 void Punkt :: print ()9 { cout << "Punkt: (" << x << ", " << y << ")";10 }11

12

Datei 128: dreieck.h, 29.6.2016 11:58:001 #if !defined __dreieck_h2 #define __dreieck_h3

4 #include "shape.h"5 #include "punkt.h"6

7 class Dreieck : public Shape8 { Punkt A, B, C;9 public:10 Dreieck (double ax, double ay, double bx, double by, double cx, double cy) : A (ax, ay), B (bx, by), C (cx, cy) {};11 virtual double area ();12 virtual void print ();13 };14 #endif15

Datei 129: dreieck.cpp, 29.6.2016 11:58:001 // ./ooprog/inherit/DREIECK.CPP2

3 #include <iostream>4 #include <cmath>5 #include "dreieck.h"6

7 using namespace std;8

9 double Dreieck :: area ()10 { double x1, y1, x2, y2;11 x1 = B . px () - A . px ();12 y1 = B . py () - A . py ();13 x2 = C . px () - A . px ();14 y2 = C . py () - A . py ();15 return fabs ((x1 * y2 - x2 * y1) / 2);

Page 102: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

102 dreieck.cpp, 29.6.2016 11:58:00

16 }17

18 void Dreieck :: print ()19 { cout << "Dreieck: [";20 A.print (); cout << ", ";21 B.print (); cout << ", ";22 C.print (); cout << "]";23 }24

Datei 130: kreis.h, 29.6.2016 11:58:001 #if ! defined __kreis_h2 #define __kreis_h3

4 #include "shape.h"5 #include "punkt.h"6

7 const double Pi = 3.141592653589793;8

9 class Kreis : public Shape10 { Punkt m;11 double r;12 public:13 Kreis (double a, double b, double c) : m (a, b) { r = c; }14 virtual double area () { return r * r * Pi; }15 virtual void print ();16 };17 #endif18

Datei 131: kreis.cpp, 29.6.2016 11:58:001 // ./ooprog/inherit/KREIS.CPP2

3 #include <iostream>4 #include "kreis.h"5

6 using namespace std;7

8 void Kreis :: print ()9

10 { cout << "Kreis: ["; m.print (); cout << ", " << r << "]";11 }12

Datei 132: �les.a2t, 29.6.2016 11:58:021 ooprog\newton\files.a2t2 ooprog\newton\main.cpp3 ooprog\newton\main.res4 ooprog\newton\func.h5 ooprog\newton\difffunc.h6 ooprog\newton\invfunc.h7 ooprog\newton\newton.h8 ooprog\newton\invert.h9 ooprog\newton\math1.h10 ooprog\newton\newton.cpp11 ooprog\newton\invert.cpp12 ooprog\newton\math1.c13 ooprog\newton\UEB.BAT14

Datei 133: main.cpp, 29.6.2016 11:58:021 // Datei: ./ooprog/newton/main.cpp Demonstration des Newtonverfahrens und der Inversen Funktion2

3 #include <iostream>4 #include <cmath>5

6 #include "difffunc.h"7 #include "invfunc.h"8 #include "newton.h"9 #include "invert.h"10 #include "math1.h"11

12 using namespace std;13

14 class Cos : public DiffableFunction15 { public:16 virtual double zero () { return 1.5; }17 virtual double f (double x) { return cos (x); }18 virtual double df (double x) { return - sin (x); }

Page 103: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

func.h, 29.6.2016 11:58:02 103

19 };20

21 class Sin : public InvertibleFunction22 { public:23 virtual double zero () { return this->x * pi / 2; }24 virtual double f (double x) { return sin (x); }25 virtual double df (double x) { return cos (x); }26 };27

28 int main ()29 { cout << "Programmbeginn" << endl;30 DiffableFunction * p;31 Cos c;32 double a, b;33

34 a=c.f (0.1);35 b=c.df (0.1);36 cout << "Kontrolle von Cos: " << a << " " << b << " " << (a*a+b*b) << endl;37

38 p = & c;39 Newton n (p);40 double p2;41 p2 = n.zero (1e-6);42 cout << "Newtonverfahren: " << p2 << " " << reldist (p2, pi/2) << endl;43

44 Sin s; // Sin ist Klasse mit Funktion, Approximation und Ableitung von sin45 Invert as (&s, 1e-10); // Invert ist Klasse zur Berechnung der Umkehrfunktion46 for (int i = 0; i <= 20; i++)47 { double x, y, yct;48 x = (i - 10.0) / 10;49 y = as.invert (x);50 yct = asin (x);51 cout << i << " " << x << ": " << s.zero () << " " << y << " " << yct << " | " << reldist (y, yct) << endl;52 }53 cout << "Programmende" << endl;54 }55

Datei 134: main.res, 26.4.2017 10:05:321 Programmbeginn2 Kontrolle von Cos: 0.995004 -0.0998334 13 Newtonverfahren: 1.5708 04 0 -1: -1.5708 -1.5708 -1.5708 | 05 1 -0.9: -1.41372 -1.11977 -1.11977 | 06 2 -0.8: -1.25664 -0.927295 -0.927295 | 2.22045e-167 3 -0.7: -1.09956 -0.775397 -0.775397 | 2.22045e-168 4 -0.6: -0.942478 -0.643501 -0.643501 | 2.22045e-169 5 -0.5: -0.785398 -0.523599 -0.523599 | 010 6 -0.4: -0.628319 -0.411517 -0.411517 | 011 7 -0.3: -0.471239 -0.304693 -0.304693 | 012 8 -0.2: -0.314159 -0.201358 -0.201358 | 2.22045e-1613 9 -0.1: -0.15708 -0.100167 -0.100167 | 014 10 0: 0 0 0 | 015 11 0.1: 0.15708 0.100167 0.100167 | 016 12 0.2: 0.314159 0.201358 0.201358 | 1.11022e-1617 13 0.3: 0.471239 0.304693 0.304693 | 018 14 0.4: 0.628319 0.411517 0.411517 | 019 15 0.5: 0.785398 0.523599 0.523599 | 020 16 0.6: 0.942478 0.643501 0.643501 | 2.22045e-1621 17 0.7: 1.09956 0.775397 0.775397 | 1.11022e-1622 18 0.8: 1.25664 0.927295 0.927295 | 1.11022e-1623 19 0.9: 1.41372 1.11977 1.11977 | 024 20 1: 1.5708 1.5708 1.5708 | 025 Programmende26

Datei 135: func.h, 29.6.2016 11:58:021 #ifndef _FUNC_H2 #define _FUNC_H3

4 // Datei: \vectra\C_KURS\cpp\newton\func.h allgemeine Funktion5

6 class Function7 { public:8 virtual double zero () = 0; // estimate for zero of f (x)9 virtual double f (double) = 0; // f (x)10 };11

Page 104: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

104 func.h, 29.6.2016 11:58:02

12 #endif13

Datei 136: di�func.h, 29.6.2016 11:58:021 #ifndef _DIFFFUNC_H2 #define _DIFFFUNC_H3

4 // Datei: \vectra\C_KURS\cpp\newton\difffunc.h differenzierbare Funktion5

6 #include "func.h"7

8 class DiffableFunction : public Function9 { public:10 virtual double df (double) = 0;11 };12

13 #endif14

Datei 137: invfunc.h, 29.6.2016 11:58:041 #ifndef _INVFUNC_H2 #define _INVFUNC_H3

4 // Datei: \vectra\C_KURS\cpp\newton\invfunc.h invertierbare Funktion mit Approximation der Inversen5

6 #include "difffunc.h"7

8 class InvertibleFunction : public DiffableFunction9 { protected:10 double x;11 public:12 void setX (double x) { this->x = x; }13 double getX () { return this->x; }14 };15

16 #endif17

Datei 138: newton.h, 29.6.2016 11:58:021 #ifndef _NEWTON_H2 #define _NEWTON_H3

4 // Datei: \vectra\C_KURS\cpp\newton\newton.h Nullstellen allgemeiner Funktionen5

6 #include "difffunc.h"7

8 class Newton9 { private:10 DiffableFunction * p;11 public:12 Newton (DiffableFunction * f) { this->p = f; }13 double zero (double eps);14 };15

16 #endif17

Datei 139: invert.h, 29.6.2016 11:58:021 #ifndef _INVERT_H2 #define _INVERT_H3

4 // Datei: \vectra\C_KURS\cpp\newton\invert.h Inversion allgemeiner Funktionen5

6 #include "invfunc.h"7 #include "newton.h"8

9 class IFunc : public DiffableFunction10 { private:11 InvertibleFunction * p;12 public:13 IFunc (InvertibleFunction * f) : p (f) {}14 virtual double zero () { return p->zero(); }15 virtual double f (double x) { return p->f (x) - p->getX(); }16 virtual double df (double x) { return p->df (x); }17 };18

19 class Invert20 { private:21 InvertibleFunction * p;22 DiffableFunction * q;

Page 105: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

math1.c, 29.6.2016 11:58:02 105

23 double eps;24 Newton * n;25 public:26 Invert (InvertibleFunction * f, double e) : eps (e), p (f)27 { q = new IFunc (f);28 n = new Newton (q);29 }30 double invert (double x);31 };32

33 #endif34

Datei 140: math1.h, 29.6.2016 11:58:021 #ifndef _MATH1_H2 #define _MATH1_H3

4 // Datei: \vectra\C_KURS\cpp\newton\math1.h elementare Funktionen5

6 #define pi 3.1415926535897937

8 #ifdef __cplusplus9 extern "C" {10 #endif11

12 double dist (double x, double y);13 double reldist (double x, double y);14

15 #ifdef __cplusplus16 }17 #endif18

19 #endif20

Datei 141: newton.cpp, 29.6.2016 11:58:021 // Datei: ./ooprog/newton/newton.cpp numerisch primitives Newtonverfahren2

3 #include "newton.h"4 #include "math1.h"5

6 double Newton::zero (double eps)7 { double x0, x1, err;8 int i;9

10 x0 = this->p->zero();11 i = 0;12

13 do14 { i++;15 x1 = x0 - (this->p->f (x0)) / (this->p->df (x0));16 err = reldist (x1, x0);17 x0 = x1;18 } while (err > eps && i < 100);19

20 return x1;21 }22

Datei 142: invert.cpp, 29.6.2016 11:58:021 // Datei: ./ooprog/newton/invert.cpp Inverse Funktion2

3 #include "invert.h"4

5 double Invert::invert (double x)6 { this->p->setX (x);7 return this->n->zero(this->eps);8 }9

Datei 143: math1.c, 29.6.2016 11:58:021 // Datei: ./ooprog/newton/math1.cpp elementare Funktionen2

3 #include <math.h>4

5 #include "math1.h"6

7 // Datei: \vectra\C_KURS\cpp\newton\difffunc.h differenzierbare Funktion8

9 double dist (double x, double y) { return fabs (x-y); }

Page 106: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

106 math1.c, 29.6.2016 11:58:02

10 double reldist (double x, double y)11 { if (x == 0) return fabs (y);12 if (y == 0) return fabs (x);13 if (x < y) return fabs (1 - x/y);14 return fabs (1 - y/x);15 }16

Datei 144: UEB.BAT, 29.6.2016 11:58:021 del *.bak2 del *.o3

4 call r5 gcc -x c -c math1.c6 g++ -x c++ -c main.cpp7 g++ -x c++ -c newton.cpp8 g++ -x c++ -c invert.cpp9

10 g++ -enable-auto-import -o main main.o newton.o invert.o math1.o11

12 main > main.res13

Datei 145: cpp7.a2t, 29.6.2016 11:57:341 /r ooprog\inherit\files.a2t2

3 /r ooprog\newton\files.a2t4

Datei 146: except1.cpp, 29.6.2016 11:57:341 #include <iostream>2 #include <string>3

4 using namespace std;5

6 class overflow7 {8 public:9 overflow (float, float) {}10 };11

12 float mydiv (float a, float b) throw (string, overflow)13 { if (!b) throw string ("Division durch 0");14 if (a > 10 && b < 0.1) throw overflow (a, b);15 return a / b;16 }17

18 int main ()19 { float x, a, b;20 cout << endl << "Gib a, b"; cin >> a >> b;21 try22 { x = mydiv (a, b);23 }24 catch (string p)25 { cout << endl << p;26 x = 999;27 }28 catch (overflow o)29 { cout << endl << "Ueberlauf ";30 throw;31 }32 cout << endl << "Korrekt" << a << "/" << b << "=" << x;33 }34

Datei 147: except1.i1, 29.6.2016 11:57:341 1 32

Datei 148: except1.i2, 29.6.2016 11:57:341 1 02

Datei 149: except1.i3, 29.6.2016 11:57:341 100 0.012

Datei 150: except1.r1, 26.4.2017 10:05:341

2 Gib a, b

Page 107: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

except2.r1, 26.4.2017 10:05:34 107

3 Korrekt1/3=0.333333

Datei 151: except1.re2, 26.4.2017 10:05:341

2 Gib a, b3 Division durch 04 Korrekt1/0=999

Datei 152: except1.r3, 26.4.2017 10:05:341

2 Gib a, b3 Ueberlauf

Datei 153: except2.cpp, 29.6.2016 11:57:341 #include <iostream>2 #include <string>3

4 using namespace std;5

6 class DateiEnde {};7

8 int Zahl () throw(DateiEnde, const string)9 { int i;10 cin >> i;11 if (cin.eof ()) throw DateiEnde ();12 if (cin.fail()) throw string("Syntaxfehler");13 if (cin.bad ()) throw;14 return i;15 }16

17 void Zahlen_lesen () throw ()18 { int i;19 while (1)20 { cout << endl << "Gib Zahl: ";21 try22 { i = Zahl ();23 }24 catch (DateiEnde)25 { cout << endl << "Datei-Ende";26 cin.clear ();27 break;28 }29 catch (const string z)30 { cout << endl << z;31 cin.clear ();32 cin.get ();33 i = 9999;34 }35 cout << endl << "Gelesene Zahl = " << i;36 } }37

38 int main ()39 { Zahlen_lesen ();40 }41

Datei 154: except2.i1, 29.6.2016 11:57:341 02 43 54 65 76 2342347

Datei 155: except2.i2, 29.6.2016 11:57:341 342 453 hans4

Datei 156: except2.r1, 26.4.2017 10:05:341

2 Gib Zahl:3 Gelesene Zahl = 04 Gib Zahl:5 Gelesene Zahl = 46 Gib Zahl:7 Gelesene Zahl = 58 Gib Zahl:

Page 108: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

108 except2.r1, 26.4.2017 10:05:34

9 Gelesene Zahl = 610 Gib Zahl:11 Gelesene Zahl = 712 Gib Zahl:13 Gelesene Zahl = 23423414 Gib Zahl:15 Datei-Ende

Datei 157: except2.r2, 26.4.2017 10:05:341

2 Gib Zahl:3 Gelesene Zahl = 344 Gib Zahl:5 Gelesene Zahl = 456 Gib Zahl:7 Syntaxfehler8 Gelesene Zahl = 99999 Gib Zahl:10 Syntaxfehler11 Gelesene Zahl = 999912 Gib Zahl:13 Syntaxfehler14 Gelesene Zahl = 999915 Gib Zahl:16 Syntaxfehler17 Gelesene Zahl = 999918 Gib Zahl:19 Datei-Ende

Datei 158: make�le., 29.6.2016 11:57:341 include ../mkincl2 include dep3

4 %.re2 : %.exe5 -./$< < $*.i2 > $@ 2>&16

7 %.r3 : %.exe8 -./$< < $*.i3 > $@9

10 all: except1.r1 except1.re2 except1.r3 except2.r1 except2.r211

Datei 159: �les.a2t, 29.6.2016 11:57:341 except\except1.cpp2 except\except1.i13 except\except1.i24 except\except1.i35 except\except1.r16 except\except1.re27 except\except1.r38 except\except2.cpp9 except\except2.i110 except\except2.i211 except\except2.r112 except\except2.r213 except\makefile.14

Datei 160: func.cpp, 29.6.2016 11:57:481 // genproc/template/func.cpp2

3 #include <cstdlib>4 #include <iostream>5

6 using namespace std;7

8 void mess (int i, int n)9 { switch (i)10 {11 case -4: cout << "\n[]: Kein Speicher"; break;12 case -3: cout << "\n[" << n << "]"; break;13 case -2: cout << "\n=: Kein Speicher"; break;14 case -1: cout << "\ncopy con: Kein Speicher"; break;15 case 1: cout << "\ncon n = 0"; break;16 case 2: cout << "\ndes n = " << n; break;17 case 3: cout << "\nint, n = " << n; break;18 case 4: cout << "\nmax, n = " << n; break;19 case 5: cout << "\ncopy con n = " << n; break;20 case 6: cout << "\n= " << n; break;

Page 109: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

func.cpp, 29.6.2016 11:57:48 109

21 case 7: cout << "\n[" << n << "]"; break;22 }23 if (i < 0) exit (1);24 }25

26 class Vektor27 { double * t;28 int n;29 public:30 Vektor () { n = 0; }31 Vektor (Vektor &);32 ~Vektor () { if (n) delete [] t; }33 Vektor & operator = (Vektor &);34 double & operator [] (int);35 operator int () { return n; }36 int max () { return n; }37 void print ();38 };39

40 Vektor :: Vektor (Vektor & o)41 { n = o.n;42 if (n)43 { t = new double [n];44 if (!t) mess (-1, 0);45 for (int i = 0; i < n; i++) t [i] = o.t [i];46 } }47

48 Vektor & Vektor :: operator = (Vektor & o)49 { if (this != &o)50 { if (n) delete [] t;51 n = o.n;52 if (n)53 { t = new double [n];54 if (!t) mess (-2, 0);55 for (int i = 0; i < n; i++) t [i] = o.t [i];56 } }57 return *this;58 }59

60 double & Vektor :: operator [] (int i)61 { if (i < 0) mess (-3, i);62 if (i >= n)63 { double * h;64 int j;65 h = new double [i+1];66 if (!h) mess (-4, 0);67 for (j = 0; j < n; j++) h [j] = t [j];68 for (j = n; j <= i; j++) h [j] = 0;69 n = i+1;70 t = h;71 }72 return t [i];73 }74

75 void Vektor :: print ()76 { int i;77 cout << endl << n << ": ";78 for (i = 0; i < n; i++) cout << " " << t [i];79 }80

81 void sort (Vektor &);82

83 int main ()84 { cout << "\nProgrammbeginn func";85 Vektor vi;86 Vektor vd;87

88 vd [3] = 4.5;89 vd.print ();90 vi = vd;91 vi.print ();92 vi [2] = 2;93 vi.print ();94 vi [10] = 2;95 vi.print ();96 sort (vi);97 vi.print ();98 sort (vd);

Page 110: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

110 func.cpp, 29.6.2016 11:57:48

99 vd.print ();100

101 return 0;102 }103

104 void sort (Vektor & v)105

106 { int i, j;107 for (i = 0; i < v.max () - 1; i++)108 { for (j = i+1; j < v.max (); j++)109 { if (v [i] > v [j])110 { double h;111 h = v [i];112 v [i] = v [j];113 v [j] = h;114 } } } }115

Datei 161: func.res, 26.4.2017 10:05:321

2 Programmbeginn func3 4: 0 0 0 4.54 4: 0 0 0 4.55 4: 0 0 2 4.56 11: 0 0 2 4.5 0 0 0 0 0 0 27 11: 0 0 0 0 0 0 0 0 2 2 4.58 4: 0 0 0 4.5

Datei 162: functem.cpp, 29.6.2016 11:57:481 // genproc/template/functem.cpp2

3 #include <cstring>4 #include <cstdlib>5 #include <iostream>6 #include <string>7

8 using namespace std;9

10 void mess (int i, int n)11 { switch (i)12 {13 case -4: cout << "\n[]: Kein Speicher"; break;14 case -3: cout << "\n[" << n << "]"; break;15 case -2: cout << "\n=: Kein Speicher"; break;16 case -1: cout << "\ncopy con: Kein Speicher"; break;17 case 1: cout << "\ncon n = 0"; break;18 case 2: cout << "\ndes n = " << n; break;19 case 3: cout << "\nint, n = " << n; break;20 case 4: cout << "\nmax, n = " << n; break;21 case 5: cout << "\ncopy con n = " << n; break;22 case 6: cout << "\n= " << n; break;23 case 7: cout << "\n[" << n << "]"; break;24 }25 if (i < 0) exit (1);26 }27

28 template<class T>29 class Vektor30 { T * t;31 int n;32 public:33 Vektor () { n = 0; }34 Vektor (Vektor &);35 ~Vektor () { if (n) delete [] t; }36 Vektor & operator = (Vektor &);37 T & operator [] (int);38 operator int () { return n; }39 int max () { return n; }40 void print ();41 };42

43 template<class T>44 Vektor<T> :: Vektor (Vektor<T> & o)45 { n = o.n;46 if (n)47 { t = new T [n];48 if (!t) mess (-1, 0);49 for (int i = 0; i < n; i++) t [i] = o.t [i];50 } }

Page 111: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

functem.cpp, 29.6.2016 11:57:48 111

51

52 template<class T>53 Vektor<T> & Vektor<T> :: operator = (Vektor<T> & o)54 { if (this != &o)55 { if (n) delete [] t;56 n = o.n;57 if (n)58 { t = new T [n];59 if (!t) mess (-2, 0);60 for (int i = 0; i < n; i++) t [i] = o.t [i];61 } }62 return *this;63 }64

65 template<class T>66 T & Vektor<T> :: operator [] (int i)67 { if (i < 0) mess (-3, i);68 if (i >= n)69 { T * h;70 int j;71 h = new T [i+1];72 if (!h) mess (-4, 0);73 for (j = 0; j < n; j++) h [j] = t [j];74 for (j = n; j <= i; j++) h [j] = 0;75 n = i+1;76 t = h;77 }78 return t [i];79 }80

81 template<>82 string & Vektor<string> :: operator [] (int i)83 { if (i < 0) mess (-3, i);84 if (i >= n)85 { string * h;86 int j;87 h = new string [i+1];88 if (!h) mess (-4, 0);89 for (j = 0; j < n; j++) h [j] = t [j];90 for (j = n; j <= i; j++) h [j] = "";91 n = i+1;92 t = h;93 }94 return t [i];95 }96

97 template<class T>98 void Vektor<T> :: print ()99 { int i;100 cout << endl << n << ": ";101 for (i = 0; i < n; i++) cout << " [" << t [i] << "]";102 }103

104 template<class T>105 void sort (Vektor<T> &);106

107 void sort (Vektor<string> & v)108 { int i, j;109 for (i = 0; i < v.max () - 1; i++)110 { for (j = i+1; j < v.max (); j++)111 { if (v [i] > v [j])112 { string h;113 h = v [i];114 v [i] = v [j];115 v [j] = h;116 } } } }117

118 int main ()119 { cout << "\nProgrammbeginn functem";120 Vektor<int> vi;121 Vektor<double> vd;122 Vektor<string> vs;123

124 vd [3] = 4.5;125 vd.print ();126 vi [5] = 1;127 vi [0] = 10;128 vi.print ();

Page 112: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

112 functem.cpp, 29.6.2016 11:57:48

129 vi [2] = 2;130 vi.print ();131 vi [10] = 2;132 vi.print ();133 sort (vi);134 vi.print ();135 sort (vd);136 vd.print ();137 vs [8] = "Hans";138 vs [0] = "Anna";139 vs.print ();140 sort (vs);141 vs.print ();142

143 cout << "\nProgrammende";144 return 0;145 }146

147 template<class T>148 void sort (Vektor<T> & v)149 { int i, j;150 for (i = 0; i < v.max () - 1; i++)151 { for (j = i+1; j < v.max (); j++)152 { if (v [i] > v [j])153 { T h;154 h = v [i];155 v [i] = v [j];156 v [j] = h;157 } } } }158

Datei 163: functem.res, 26.4.2017 10:05:321

2 Programmbeginn functem3 4: [0] [0] [0] [4.5]4 6: [10] [0] [0] [0] [0] [1]5 6: [10] [0] [2] [0] [0] [1]6 11: [10] [0] [2] [0] [0] [1] [0] [0] [0] [0] [2]7 11: [0] [0] [0] [0] [0] [0] [0] [1] [2] [2] [10]8 4: [0] [0] [0] [4.5]9 9: [Anna] [] [] [] [] [] [] [] [Hans]10 9: [] [] [] [] [] [] [] [Anna] [Hans]11 Programmende

Datei 164: sort.cpp, 29.6.2016 11:57:481 // genproc/template/sort.cpp2

3 #include <cstdlib>4 #include <cstring>5 #include <iostream>6

7 using namespace std;8

9 template<class T>10 inline void Swap (T & x, T & y) // wegen std::swap der Grossbuchstabe11 { T h;12 h = x;13 x = y;14 y = h;15 }16

17 template<class T>18 inline bool after (T x, T y)19 { cout << ","; return x > y;20 }21

22 template<class T>23 void sort (T * l, int n)24 { int i, min;25 if (n <= 1) return;26 min = 0;27 for (i = 1; i < n; i++)28 if (after (l [min], l [i]))29 min = i;30 if (min)31 Swap (l [0], l [min]);32 sort (l+1, n-1);33 }

Page 113: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

readln.cpp, 29.6.2016 11:57:32 113

34

35 template<> // ohne Spezialisierung bleibt char * [] unsortiert (Sortierung nach Adressen)36 inline bool after (char * x, char * y)37 { cout << "."; return strcmp (x, y) > 0;38 }39

40 int main ()41 { cout << "\nProgrammbeginn sort";42 int i;43

44 int l1 [] = { 3, 1, 4, 1, -5, 9, 2, };45 sort (l1, 7);46 for (i = 0; i < 7; i++) cout << ' ' << l1 [i]; cout << endl;47

48 double l2 [] = { 3.1, 4.1, 5.9, 2.6, -5.3, 5.8, 9.7, };49 sort (l2, 7);50 for (i = 0; i < 7; i++) cout << ' ' << l2 [i]; cout << endl;51

52 char * l3 [] = { "huhn", "haus", "hans", "hohl", "halb", "herz", "hort", };53 sort (l3, 7);54 for (i = 0; i < 7; i++) cout << ' ' << l3 [i]; cout << endl;55

56 string l4 [] = { "hund", "hart", "huld", "hohl", "hast", "herr", "herd", };57 sort (l4, 7);58 for (i = 0; i < 7; i++) cout << ' ' << l4 [i]; cout << endl;59

60 return 0;61 }62

Datei 165: sort.res, 26.4.2017 10:05:341

2 Programmbeginn sort,,,,,,,,,,,,,,,,,,,,, -5 1 1 2 3 4 93 ,,,,,,,,,,,,,,,,,,,,, -5.3 2.6 3.1 4.1 5.8 5.9 9.74 ..................... halb hans haus herz hohl hort huhn5 ,,,,,,,,,,,,,,,,,,,,, hart hast herd herr hohl huld hund6

Datei 166: Make�le., 29.6.2016 11:57:481 include ../../mkincl2 include dep3

4 all: func.res functem.res sort.res5

Datei 167: cpp8.a2t, 29.6.2016 11:57:341 .\genprog\template\func.cpp2 .\genprog\template\func.res3 .\genprog\template\functem.cpp4 .\genprog\template\functem.res5 .\genprog\template\sort.cpp6 .\genprog\template\sort.res7 .\genprog\template\Makefile.8

Datei 168: cppios.a2t, 29.6.2016 11:57:341

Datei 169: readln.cpp, 29.6.2016 11:57:321 // READLN.CPP: zeilenweises Lesen aus einer Datei2

3 #include <iostream>4 #include <fstream>5

6 using namespace std;7

8 int main (int argc, char * argv [])9 { ifstream t;10 const int max = 500;11 char buf [max];12 int i;13

14 cout << "Programmbeginn" << endl;15

16 t.open (argv [1]);17 i = 0;18 while (t.good())19 { t.getline (buf, max - 1);20 buf [max-1] = 0;

Page 114: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

114 readln.cpp, 29.6.2016 11:57:32

21 cout << i++ << ": " << buf << "|" << endl;22 }23 cout << "Programmende" << endl;24 return 0;25 }26

Datei 170: readln.res, 26.4.2017 10:12:441 Programmbeginn2 0: // READLN.CPP: zeilenweises Lesen aus einer Datei|3 1: |4 2: #include <iostream>|5 3: #include <fstream>|6 4: |7 5: using namespace std;|8 6: |9 7: int main (int argc, char * argv [])|10 8: { ifstream t;|11 9: const int max = 500;|12 10: char buf [max];|13 11: int i;|14 12: |15 13: cout << "Programmbeginn" << endl;|16 14: |17 15: t.open (argv [1]);|18 16: i = 0;|19 17: while (t.good())|20 18: { t.getline (buf, max - 1);|21 19: buf [max-1] = 0;|22 20: cout << i++ << ": " << buf << "|" << endl;|23 21: }|24 22: cout << "Programmende" << endl;|25 23: return 0;|26 24: }|27 25: |28 Programmende29

Datei 171: readtext.cpp, 29.6.2016 11:57:321 // READTEXT.CPP: Lesen aus einer Text-Datei2

3 #include <iostream>4 #include <fstream>5

6 using namespace std;7

8 int main ()9 { ifstream t;10 int i;11 int n;12 double x;13 char s [100];14

15 cout << "Programmbeginn" << endl;16

17 t.open ("readtext.dat"); // Eingabedaten in readtext.dat18 i = 0;19 while (t.good())20 { switch (i++)21 { case 0: case 1:22 t >> n;23 cout << "Ganze Zahlen: " << n << endl;24 break;25 case 9:26 t >> oct >> n;27 cout << "Ganze oktale Zahlen: " << n << " = " << oct << n << " oktal " << dec << endl;28 break;29 case 2: case 5:30 t >> x;31 cout << "Reelle Zahlen: " << x << endl;32 break;33 default:34 t >> s;35 cout << "Strings: " << s << endl;36 break;37 } }38 cout << "Programmende" << endl;39 return 0;40 }

Page 115: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

textram.cpp, 29.6.2016 11:57:32 115

41

Datei 172: readtext.dat, 29.6.2016 11:57:321 293 49562 3.143 hans otto4 2.715 peter fritz6 anna7 7778 johanna

Datei 173: readtext.res, 26.4.2017 10:06:081 Programmbeginn2 Ganze Zahlen: 2933 Ganze Zahlen: 49564 Reelle Zahlen: 3.145 Strings: hans6 Strings: otto7 Reelle Zahlen: 2.718 Strings: peter9 Strings: fritz10 Strings: anna11 Ganze oktale Zahlen: 511 = 777 oktal12 Strings: johanna13 Programmende14

Datei 174: textram.cpp, 29.6.2016 11:57:321 // TEXTRAM.CPP: Wahlfreier Zugriff auf Textdateien mit Indexdatei2

3 #include <iostream>4 #include <fstream>5

6 using namespace std;7

8 int main (int argc, char * argv [])9 { fstream txt, idx;10 streampos p;11 char ch;12 int i, n;13

14 cout << "Programmbeginn" << endl;15 if (argc < 2) { cout << "Argumente fehlen" << endl; return 1; }16

17 txt.open (argv [1], ios::in);18 if (!txt.good()) { cout << "Fehler: Textdatei existiert nicht"; return 1; }19 idx.open ("idx.idx", ios::out | ios::trunc | ios::binary);20

21 i = 0;22 while (txt.good())23 { p = txt.tellg(); i++;24 idx.write ((char*) (&p), sizeof (p));25 cout << "Test" << i << " (" << p << "): " << endl;26 do {27 txt.get (ch);28 cout << ch;29 } while (txt.good() && ch != '\n');30 }31 n = i;32 idx.close();33 txt.close();34

35 for (;;)36 { cout << "Gib Zeilennummer zwischen 1 und " << n << endl;37 cin >> i; i--;38

39 if (i < 0 || i >= n) break;40

41 cout << i + 1 << " (";42

43 idx.open ("idx.idx", ios::in | ios::binary);44 idx.seekg (i * (sizeof p));45 idx.read ((char*) (&p), sizeof (p));46 idx.close();47

48 txt.clear(); // open setzt errorflags nicht zurueck49 txt.open (argv [1], ios::in);50 txt.seekg (p);51

Page 116: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

116 textram.cpp, 29.6.2016 11:57:32

52 cout << p << "): ";53

54 while (txt.good())55 { txt.get(ch);56 if (!txt.good()) break;57 if (ch == '\n') break;58 cout << ch;59 }60 txt.close();61

62 cout << "|" << endl;63 }64 return 0;65 }66

Datei 175: textram.in, 29.6.2016 11:57:321 58 Erste Zeile2 18 Zweite Zeile3 50 Dritte Zeile4 37 Vierte Zeile5 1 Fuenfte Zeile6 0 Sechste Zeile7 Siebte Zeile

Datei 176: textram.cin, 29.6.2016 11:57:321 32 13 54 75 -16

Datei 177: textram.res, 26.4.2017 10:12:441 Programmbeginn2 Test1 (0):3 58 Erste Zeile4 Test2 (17):5 18 Zweite Zeile6 Test3 (35):7 50 Dritte Zeile8 Test4 (53):9 37 Vierte Zeile10 Test5 (71):11 1 Fuenfte Zeile12 Test6 (90):13 0 Sechste Zeile14 Test7 (109):15 Siebte ZeileeGib Zeilennummer zwischen 1 und 716 3 (35): 50 Dritte Zeile|17 Gib Zeilennummer zwischen 1 und 718 1 (0): 58 Erste Zeile|19 Gib Zeilennummer zwischen 1 und 720 5 (71): 1 Fuenfte Zeile|21 Gib Zeilennummer zwischen 1 und 722 7 (109): Siebte Zeile|23 Gib Zeilennummer zwischen 1 und 724

Datei 178: bin.cpp, 29.6.2016 11:57:321 // BIN.CPP: Binaer-Ein-Ausgabe mit read und write2

3 #include <iostream>4

5 using namespace std;6

7 int main ()8 { int i;9

10 cout << "Programmbeginn" << endl;11

12 cout.write ("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 10); cout << endl;13

14 for (i = 10; i <= 26; i++)15 { cout << i << ": ";16 cout.write ("ABCDEFGHIJKLMNOPQRSTUVWXYZ", i);17 cout << endl;18 }19

20 cout << "Programmende" << endl;

Page 117: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

binio.cpp, 29.6.2016 11:57:32 117

21 return 0;22 }23

Datei 179: bin.res, 26.4.2017 10:06:101 Programmbeginn2 ABCDEFGHIJ3 10: ABCDEFGHIJ4 11: ABCDEFGHIJK5 12: ABCDEFGHIJKL6 13: ABCDEFGHIJKLM7 14: ABCDEFGHIJKLMN8 15: ABCDEFGHIJKLMNO9 16: ABCDEFGHIJKLMNOP10 17: ABCDEFGHIJKLMNOPQ11 18: ABCDEFGHIJKLMNOPQR12 19: ABCDEFGHIJKLMNOPQRS13 20: ABCDEFGHIJKLMNOPQRST14 21: ABCDEFGHIJKLMNOPQRSTU15 22: ABCDEFGHIJKLMNOPQRSTUV16 23: ABCDEFGHIJKLMNOPQRSTUVW17 24: ABCDEFGHIJKLMNOPQRSTUVWX18 25: ABCDEFGHIJKLMNOPQRSTUVWXY19 26: ABCDEFGHIJKLMNOPQRSTUVWXYZ20 Programmende21

Datei 180: binio.cpp, 29.6.2016 11:57:321 // BINIO.CPP: Turbo-C++ Version! Binaer-Ein-Ausgabe mit read und write2

3 #include <cmath>4 #include <iostream>5 #include <fstream>6

7 using namespace std;8

9 int f (int i)10 { double x;11 x = 100 * sin ((double) i); // (double) cast wegen sin (float/double/long double)12 i = static_cast <int> (x);13 return i;14 }15

16 int main ()17 { fstream tst;18 int i, j;19 long k;20

21 const int max = 50;22

23 cout << "Programmbeginn" << sizeof k << ' ' << sizeof (k) << endl;24

25 tst.open ("bin1.dat", ios::out | ios::trunc | ios::binary);26

27 for (i = 0; i < 2 * max; i++)28 {29 k = f (i);30 cout << i << " " << k << endl;31 tst.write ((char *) (&k), sizeof (k));32 if (!tst.good()) { cout << "Fehler 1"; return 1; }33 }34

35 tst.close ();36 if (!tst.good()) { cout << "Fehler 2"; return 1; }37

38 for (j = max - 1; j >= 0; j--)39 {40 i = 2 * j;41 tst.open ("bin1.dat", ios::in | ios::binary);42 if (!tst.good()) { cout << "Fehler 3"; return 1; }43 tst.seekg (i * (sizeof k));44 if (!tst.good()) { cout << "Fehler 4"; return 1; }45 tst.read ((char*) &k, sizeof (k));46 if (!tst.good()) { cout << "Fehler 5"; return 1; }47 tst.close ();48 if (!tst.good()) { cout << "Fehler 6"; return 1; }49 if (f (i) != k)50 {51 cout << i << ": " << k << " ";

Page 118: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

118 binio.cpp, 29.6.2016 11:57:32

52 cout << f (i);53 cout << "<---------------- Fehler";54 cout << endl;55 }56 }57

58 for (j = 0; j < max; j++)59 {60 i = 2 * j + 1;61 tst.open ("bin1.dat", ios::in | ios::binary);62 if (!tst.good()) { cout << "Fehler 7"; return 1; }63 tst.seekg (i * sizeof k);64 if (!tst.good()) { cout << "Fehler 8"; return 1; }65 tst.read ((char*) &k, sizeof k);66 if (!tst.good()) { cout << "Fehler 9"; return 1; }67 tst.close ();68 if (!tst.good()) { cout << "Fehler 10"; return 1; }69 if (f (i) != k)70 {71 cout << i << ": " << k << " ";72 cout << f (i) ;73 cout << "<---------------- Fehler";74 cout << endl;75 }76 }77

78 for (;;)79 {80 cout << "Gib i: ";81 cin >> i;82 if (i < 0 || i >= 2 * max)83 {84 cout << "Programmende" << endl;85 return 0;86 }87 tst.open ("bin1.dat", ios::in | ios::binary);88 if (!tst.good()) { cout << "Fehler 11"; return 1; }89 tst.seekg (i * sizeof k);90 if (!tst.good()) { cout << "Fehler 12"; return 1; }91 tst.read ((char*) &k, sizeof k);92 if (!tst.good()) { cout << "Fehler 13"; return 1; }93 tst.close ();94 if (!tst.good()) { cout << "Fehler 14"; return 1; }95 cout << i << ": " << k << " ";96 cout << f (i);97 if (f (i) != k) cout << "<================ Fehler";98 cout << endl;99 }100

101 // return 0;102 }103

Datei 181: binio.in, 29.6.2016 11:57:321 902 793 24 05 -16

Datei 182: binio.res, 26.4.2017 10:12:441 Programmbeginn8 82 0 03 1 844 2 905 3 146 4 -757 5 -958 6 -279 7 6510 8 9811 9 4112 10 -5413 11 -9914 12 -5315 13 4216 14 9917 15 65

Page 119: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

binio.res, 26.4.2017 10:12:44 119

18 16 -2819 17 -9620 18 -7521 19 1422 20 9123 21 8324 22 025 23 -8426 24 -9027 25 -1328 26 7629 27 9530 28 2731 29 -6632 30 -9833 31 -4034 32 5535 33 9936 34 5237 35 -4238 36 -9939 37 -6440 38 2941 39 9642 40 7443 41 -1544 42 -9145 43 -8346 44 147 45 8548 46 9049 47 1250 48 -7651 49 -9552 50 -2653 51 6754 52 9855 53 3956 54 -5557 55 -9958 56 -5259 57 4360 58 9961 59 6362 60 -3063 61 -9664 62 -7365 63 1666 64 9267 65 8268 66 -269 67 -8570 68 -8971 69 -1172 70 7773 71 9574 72 2575 73 -6776 74 -9877 75 -3878 76 5679 77 9980 78 5181 79 -4482 80 -9983 81 -6284 82 3185 83 9686 84 7387 85 -1788 86 -9289 87 -8290 88 391 89 8692 90 8993 91 1094 92 -7795 93 -9496 94 -2497 95 6898 96 98

Page 120: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

120 binio.res, 26.4.2017 10:12:44

99 97 37100 98 -57101 99 -99102 Gib i: 90: 89 89103 Gib i: 79: -44 -44104 Gib i: 2: 90 90105 Gib i: 0: 0 0106 Gib i: Programmende107

Datei 183: make�le., 29.6.2016 11:57:321 include ../mkincl2 include dep3

4 readln.res: readln.exe readln.cpp5 ./readln.exe readln.cpp > $@6 textram.res: textram.exe textram.in textram.cin7 ./textram.exe textram.in < textram.cin > $@8 binio.res: binio.exe binio.in9 ./binio.exe < binio.in > $@10

11 all: readln.res readtext.res textram.res bin.res binio.res update.r1 update.r212

13

Datei 184: cpp9.a2t, 26.4.2017 15:08:421 file\readln.cpp2 file\readln.res3

4 file\readtext.cpp5 file\readtext.dat6 file\readtext.res7

8 file\textram.cpp9 file\textram.in10 file\textram.cin11 file\textram.res12

13 file\bin.cpp14 file\bin.res15

16 file\binio.cpp17 file\binio.in18 file\binio.res19

20 file\makefile.21

Page 121: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

Inhaltsverzeichnis

1 a2t\dir.txt, 29.6.2016 11:57:34 12 mkincl., 26.4.2017 12:10:22 13 stl\string\itor0.c, 29.6.2016 11:57:50 14 stl\string\itor0.res, 26.4.2017 12:01:14 25 stl\string\itor1.cpp, 29.6.2016 11:57:50 26 stl\string\itor1.res, 26.4.2017 12:01:14 37 stl\string\itor3.cpp, 29.6.2016 11:57:50 38 stl\string\itor3.res, 26.4.2017 12:01:14 39 stl\string\itor4.cpp, 29.6.2016 11:57:50 310 stl\string\itor4.res, 26.4.2017 12:01:16 311 stl\string\itor5.cpp, 29.6.2016 11:57:50 312 stl\string\itor5.res, 26.4.2017 12:01:18 413 procprog\nichts\nichts.cpp, 29.6.2016 11:57:36 414 procprog\hallo\hallo.cpp, 29.6.2016 11:57:36 415 procprog\hallo\hallo.res, 26.4.2017 10:05:16 516 a2t\cpp1.a2t, 29.6.2016 11:57:34 517 procprog\inout\input.cpp, 29.6.2016 11:57:38 518 procprog\inout\input.in, 29.6.2016 11:57:38 519 procprog\inout\input.rs, 26.4.2017 10:05:18 520 procprog\inout\output.cpp, 29.6.2016 11:57:38 521 procprog\inout\output.res, 26.4.2017 10:05:18 622 procprog\inout\konvert1.cpp, 29.6.2016 11:57:38 623 procprog\inout\konvert1.in, 29.6.2016 11:57:38 724 procprog\inout\konvert1.rs, 26.4.2017 10:05:18 725 procprog\inout\stringio.cpp, 29.6.2016 11:57:38 726 procprog\inout\stringio.in, 29.6.2016 11:57:38 827 procprog\inout\stringio.rs, 26.4.2017 10:05:18 828 a2t\cpp2.a2t, 29.6.2016 11:57:34 829 procprog\referenc\�les1.a2t, 29.6.2016 11:57:38 830 procprog\referenc\make�le., 29.6.2016 11:57:38 931 procprog\referenc\�anders.txt, 29.6.2016 11:57:38 932 procprog\referenc\wortcnt.cpp, 29.6.2016 11:57:36 933 procprog\referenc\wortcnt.res, 26.4.2017 10:05:20 1034 procprog\referenc\wortcnti.cpp, 29.6.2016 11:57:38 1135 procprog\referenc\wortcnti.res, 26.4.2017 10:05:20 1236 procprog\referenc\wortcnts.cpp, 29.6.2016 11:57:38 1237 procprog\referenc\wortcnts.res, 26.4.2017 10:05:22 1338 procprog\referenc\wortcntx.cpp, 29.6.2016 11:57:38 1439 procprog\referenc\wortcntx.res, 26.4.2017 10:05:22 1440 procprog\referenc\icstrng.hpp, 29.6.2016 11:57:38 1541 procprog\referenc\icstrng.cpp, 29.6.2016 11:57:38 1642 procprog\referenc\icstrng.rs, 26.4.2017 10:05:22 1643 procprog\referenc\destrng.cpp, 29.6.2016 11:57:38 1644 procprog\referenc\destrng.hpp, 29.6.2016 11:57:38 1745 procprog\referenc\destrng.rs, 26.4.2017 10:05:24 1846 procprog\referenc\sort1.cpp, 29.6.2016 11:57:38 1847 procprog\referenc\sort1.res, 26.4.2017 10:05:24 1848 procprog\referenc\unique.cpp, 29.6.2016 11:57:38 1849 procprog\referenc\unique.rs, 26.4.2017 10:05:26 1950 procprog\referenc\vor.cpp, 29.6.2016 11:57:38 1951 procprog\referenc\vor.h, 29.6.2016 11:57:38 2052 procprog\referenc\vor.rs, 26.4.2017 10:05:24 2053 a2t\cpp3.a2t, 29.6.2016 11:57:34 2054 stl\vector\vector.cpp, 29.6.2016 11:57:50 2055 stl\vector\vector.res, 26.4.2017 10:05:36 2156 a2t\cpp3a.a2t, 29.6.2016 11:57:34 2157 ooprog\geom\SCHNITT.C, 29.6.2016 11:58:02 2258 ooprog\geom\SCHNITT.RES, 26.4.2017 10:05:26 2359 ooprog\geom\MATH1.H, 29.6.2016 11:58:02 2360 ooprog\geom\MATH1.C, 29.6.2016 11:58:02 23

121

Page 122: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

122 INHALTSVERZEICHNIS

61 ooprog\geom\VEKTOR.H, 29.6.2016 11:58:02 2362 ooprog\geom\VEKTOR.C, 29.6.2016 11:58:02 2363 ooprog\geom\GERADE.H, 29.6.2016 11:58:02 2464 ooprog\geom\GERADE.C, 29.6.2016 11:58:02 2465 ooprog\geom\PUNKT.C, 29.6.2016 11:58:02 2566 ooprog\geom\PUNKT.RES, 26.4.2017 10:05:26 2567 ooprog\geom\SCHNITTA.C, 29.6.2016 11:58:02 2568 ooprog\geom\SCHNITTA.RES, 26.4.2017 10:05:26 2669 ooprog\geom\MATH1A.H, 29.6.2016 11:58:02 2770 ooprog\geom\MATH1A.C, 29.6.2016 11:58:02 2771 ooprog\geom\SCHNITT1.CPP, 29.6.2016 11:58:02 2772 ooprog\geom\SCHNITT1.RES, 26.4.2017 10:05:28 2873 ooprog\geom\SCHNITT2.CPP, 29.6.2016 11:58:02 2974 ooprog\geom\SCHNITT2.RES, 26.4.2017 10:05:28 3175 ooprog\geom\SCHNITT4.CPP, 29.6.2016 11:58:02 3176 ooprog\geom\SCHNITT4.RES, 26.4.2017 10:05:28 3277 ooprog\geom\GERADEA.CPP, 29.6.2016 11:58:02 3278 ooprog\geom\GERADEA.H, 29.6.2016 11:58:02 3379 ooprog\geom\VEKTORA.CPP, 29.6.2016 11:58:02 3380 ooprog\geom\VEKTORA.H, 29.6.2016 11:58:02 3481 ooprog\geom\uebc.BAT, 29.6.2016 11:58:02 3482 ooprog\geom\uebcpp.BAT, 29.6.2016 11:58:02 3483 ooprog\geom\Makef., 29.6.2016 11:58:02 3584 a2t\cpp4.a2t, 29.6.2016 11:57:34 3585 bruch\doc.doc, 13.7.2016 15:39:44 3586 bruch\FILES.A2T, 26.4.2017 15:04:34 3687 bruch\rzeit.tim, 29.6.2016 11:57:56 3688 bruch\ueblinux., 26.4.2017 13:48:14 4089 bruch\ratc.c, 26.4.2017 12:06:54 4190 bruch\ratc.r, 26.4.2017 14:21:02 4291 bruch\bruch.cpp, 29.6.2016 11:57:58 4492 bruch\bruch.in, 29.6.2016 11:57:56 4793 bruch\bruch.res, 26.4.2017 14:21:32 4794 bruch\intext.hh, 27.2.2017 14:13:56 4895 bruch\rat.hh, 27.2.2017 14:13:56 4996 bruch\ratmain.cpp, 29.6.2016 11:57:56 5297 bruch\rzeit.h, 29.6.2016 11:57:56 5498 bruch\rzeit.c, 29.6.2016 11:57:56 5599 bruch\ulintmt.h, 29.6.2016 11:57:56 55100 bruch\apx.h, 29.6.2016 11:57:56 56101 bruch\ulintgmp.h, 29.6.2016 11:57:56 58102 bruch\gmpx.h, 29.6.2016 11:57:58 59103 bruch\ulintnr.hh, 29.6.2016 11:57:56 60104 bruch\ulintnr.cpp, 29.6.2016 11:57:56 62105 bruch\nrmpx.c, 29.6.2016 11:57:56 72106 bruch\nrmpx.h, 29.6.2016 11:57:56 74107 bruch\nrtst.c, 29.6.2016 11:57:58 74108 bruch\ratnr.res, 26.4.2017 15:02:22 75109 bruch\uebnr.bat, 29.6.2016 11:57:52 84110 bruch\ulintnrt.cpp, 29.6.2016 11:57:56 84111 bruch\FILES.A2T, 26.4.2017 15:04:34 86112 ooprog\mystring\string.cpp, 29.6.2016 11:58:04 87113 ooprog\mystring\string.res, 26.4.2017 10:05:32 90114 a2t\cpp6.a2t, 29.6.2016 11:57:34 90115 ooprog\inherit\�les.a2t, 29.6.2016 11:58:00 90116 ooprog\inherit\shape1.cc, 29.6.2016 11:58:00 91117 ooprog\inherit\shape.cpp, 29.6.2016 11:57:58 92118 ooprog\inherit\shape.res, 26.4.2017 10:05:30 96119 ooprog\inherit\shape0.c, 29.6.2016 11:57:58 98120 ooprog\inherit\shape0.res, 26.4.2017 10:05:28 99121 ooprog\inherit\shape2.cpp, 29.6.2016 11:58:00 99122 ooprog\inherit\shape2.res, 26.4.2017 10:05:30 100123 ooprog\inherit\shape3.cpp, 29.6.2016 11:58:00 100124 ooprog\inherit\shape3.res, 26.4.2017 10:05:30 100125 ooprog\inherit\shape.h, 29.6.2016 11:58:00 100126 ooprog\inherit\punkt.h, 29.6.2016 11:58:00 101127 ooprog\inherit\punkt.cpp, 29.6.2016 11:57:58 101128 ooprog\inherit\dreieck.h, 29.6.2016 11:58:00 101129 ooprog\inherit\dreieck.cpp, 29.6.2016 11:58:00 101130 ooprog\inherit\kreis.h, 29.6.2016 11:58:00 102131 ooprog\inherit\kreis.cpp, 29.6.2016 11:58:00 102

Page 123: Datei 1: dir.txt, 29.6.2016 11:57:34 Datei 2: mkincl., 26.4.2017 …brf09510/EDV/kurs... · 2017-04-26 · itor5.cpp, 29.6.2016 11:57:50 3 40 41 delete [] m; 42} 43 Datei 6: itor1.res,

INHALTSVERZEICHNIS 123

132 ooprog\newton\�les.a2t, 29.6.2016 11:58:02 102133 ooprog\newton\main.cpp, 29.6.2016 11:58:02 102134 ooprog\newton\main.res, 26.4.2017 10:05:32 103135 ooprog\newton\func.h, 29.6.2016 11:58:02 103136 ooprog\newton\di�func.h, 29.6.2016 11:58:02 104137 ooprog\newton\invfunc.h, 29.6.2016 11:58:04 104138 ooprog\newton\newton.h, 29.6.2016 11:58:02 104139 ooprog\newton\invert.h, 29.6.2016 11:58:02 104140 ooprog\newton\math1.h, 29.6.2016 11:58:02 105141 ooprog\newton\newton.cpp, 29.6.2016 11:58:02 105142 ooprog\newton\invert.cpp, 29.6.2016 11:58:02 105143 ooprog\newton\math1.c, 29.6.2016 11:58:02 105144 ooprog\newton\UEB.BAT, 29.6.2016 11:58:02 106145 a2t\cpp7.a2t, 29.6.2016 11:57:34 106146 except\except1.cpp, 29.6.2016 11:57:34 106147 except\except1.i1, 29.6.2016 11:57:34 106148 except\except1.i2, 29.6.2016 11:57:34 106149 except\except1.i3, 29.6.2016 11:57:34 106150 except\except1.r1, 26.4.2017 10:05:34 106151 except\except1.re2, 26.4.2017 10:05:34 107152 except\except1.r3, 26.4.2017 10:05:34 107153 except\except2.cpp, 29.6.2016 11:57:34 107154 except\except2.i1, 29.6.2016 11:57:34 107155 except\except2.i2, 29.6.2016 11:57:34 107156 except\except2.r1, 26.4.2017 10:05:34 107157 except\except2.r2, 26.4.2017 10:05:34 108158 except\make�le., 29.6.2016 11:57:34 108159 except\�les.a2t, 29.6.2016 11:57:34 108160 .\genprog\template\func.cpp, 29.6.2016 11:57:48 108161 .\genprog\template\func.res, 26.4.2017 10:05:32 110162 .\genprog\template\functem.cpp, 29.6.2016 11:57:48 110163 .\genprog\template\functem.res, 26.4.2017 10:05:32 112164 .\genprog\template\sort.cpp, 29.6.2016 11:57:48 112165 .\genprog\template\sort.res, 26.4.2017 10:05:34 113166 .\genprog\template\Make�le., 29.6.2016 11:57:48 113167 a2t\cpp8.a2t, 29.6.2016 11:57:34 113168 a2t\cppios.a2t, 29.6.2016 11:57:34 113169 �le\readln.cpp, 29.6.2016 11:57:32 113170 �le\readln.res, 26.4.2017 10:12:44 114171 �le\readtext.cpp, 29.6.2016 11:57:32 114172 �le\readtext.dat, 29.6.2016 11:57:32 115173 �le\readtext.res, 26.4.2017 10:06:08 115174 �le\textram.cpp, 29.6.2016 11:57:32 115175 �le\textram.in, 29.6.2016 11:57:32 116176 �le\textram.cin, 29.6.2016 11:57:32 116177 �le\textram.res, 26.4.2017 10:12:44 116178 �le\bin.cpp, 29.6.2016 11:57:32 116179 �le\bin.res, 26.4.2017 10:06:10 117180 �le\binio.cpp, 29.6.2016 11:57:32 117181 �le\binio.in, 29.6.2016 11:57:32 118182 �le\binio.res, 26.4.2017 10:12:44 118183 �le\make�le., 29.6.2016 11:57:32 120184 a2t\cpp9.a2t, 26.4.2017 15:08:42 120