diff options
Diffstat (limited to 'Bachelor/Prog1')
305 files changed, 20854 insertions, 0 deletions
diff --git a/Bachelor/Prog1/Ascii_Table.htm b/Bachelor/Prog1/Ascii_Table.htm new file mode 100644 index 0000000..512ae95 --- /dev/null +++ b/Bachelor/Prog1/Ascii_Table.htm @@ -0,0 +1,197 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!-- saved from url=(0070)http://cwx.prenhall.com/bookbind/pubbooks/deitelcpp/medialib/appb.html -->
+<HTML><HEAD><TITLE>Reference Material-ASCII Character Set</TITLE>
+<META http-equiv=Content-Type content="text/html; charset=windows-1252">
+<META content="MSHTML 5.50.4134.600" name=GENERATOR><LINK
+href="appb-Dateien/APPEN_B.css" rel=STYLESHEET></HEAD>
+<BODY text=#410d9c bgColor=#ffffff>
+<CENTER><FONT size=+3><B>ASCII Character Set</B></FONT>
+<P><BR>
+<TABLE cellSpacing=5 cellPadding=5 border=1>
+ <TBODY>
+ <TR>
+ <TD align=middle></TD>
+ <TD align=middle><B>0</B> </TD>
+ <TD align=middle><B>1</B> </TD>
+ <TD align=middle><B>2</B> </TD>
+ <TD align=middle><B>3</B> </TD>
+ <TD align=middle><B>4</B> </TD>
+ <TD align=middle><B>5</B> </TD>
+ <TD align=middle><B>6</B> </TD>
+ <TD align=middle><B>7</B> </TD>
+ <TD align=middle><B>8</B> </TD>
+ <TD align=middle><B>9</B> </TD></TR>
+ <TR>
+ <TD align=middle><B>0</B></TD>
+ <TD align=middle>nul</TD>
+ <TD align=middle>soh</TD>
+ <TD align=middle>stx</TD>
+ <TD align=middle>etx</TD>
+ <TD align=middle>eot</TD>
+ <TD align=middle>enq</TD>
+ <TD align=middle>ack</TD>
+ <TD align=middle>bel</TD>
+ <TD align=middle>bs</TD>
+ <TD align=middle>ht</TD></TR>
+ <TR>
+ <TD align=middle><B>1</B></TD>
+ <TD align=middle>nl</TD>
+ <TD align=middle>vt</TD>
+ <TD align=middle>ff</TD>
+ <TD align=middle>cr</TD>
+ <TD align=middle>so</TD>
+ <TD align=middle>si</TD>
+ <TD align=middle>dle</TD>
+ <TD align=middle>dc1</TD>
+ <TD align=middle>dc2</TD>
+ <TD align=middle>dc3</TD></TR>
+ <TR>
+ <TD align=middle><B>2</B></TD>
+ <TD align=middle>dc4</TD>
+ <TD align=middle>nak</TD>
+ <TD align=middle>syn</TD>
+ <TD align=middle>etb</TD>
+ <TD align=middle>can</TD>
+ <TD align=middle>em</TD>
+ <TD align=middle>sub</TD>
+ <TD align=middle>esc</TD>
+ <TD align=middle>fs</TD>
+ <TD align=middle>gs</TD></TR>
+ <TR>
+ <TD align=middle><B>3</B></TD>
+ <TD align=middle>rs</TD>
+ <TD align=middle>us</TD>
+ <TD align=middle>sp</TD>
+ <TD align=middle>!</TD>
+ <TD align=middle>"</TD>
+ <TD align=middle>#</TD>
+ <TD align=middle>$</TD>
+ <TD align=middle>%</TD>
+ <TD align=middle>&</TD>
+ <TD align=middle>`</TD></TR>
+ <TR>
+ <TD align=middle><B>4</B></TD>
+ <TD align=middle>(</TD>
+ <TD align=middle>)</TD>
+ <TD align=middle>*</TD>
+ <TD align=middle>+</TD>
+ <TD align=middle>,</TD>
+ <TD align=middle>-</TD>
+ <TD align=middle>.</TD>
+ <TD align=middle>/</TD>
+ <TD align=middle>0</TD>
+ <TD align=middle>1</TD></TR>
+ <TR>
+ <TD align=middle><B>5</B></TD>
+ <TD align=middle>2</TD>
+ <TD align=middle>3</TD>
+ <TD align=middle>4</TD>
+ <TD align=middle>5</TD>
+ <TD align=middle>6</TD>
+ <TD align=middle>7</TD>
+ <TD align=middle>8</TD>
+ <TD align=middle>9</TD>
+ <TD align=middle>:</TD>
+ <TD align=middle>;</TD></TR>
+ <TR>
+ <TD align=middle><B>6</B></TD>
+ <TD align=middle><</TD>
+ <TD align=middle>=</TD>
+ <TD align=middle>></TD>
+ <TD align=middle>?</TD>
+ <TD align=middle>@</TD>
+ <TD align=middle>A</TD>
+ <TD align=middle>B</TD>
+ <TD align=middle>C</TD>
+ <TD align=middle>D</TD>
+ <TD align=middle>E</TD></TR>
+ <TR>
+ <TD align=middle><B>7</B></TD>
+ <TD align=middle>F</TD>
+ <TD align=middle>G</TD>
+ <TD align=middle>H</TD>
+ <TD align=middle>I</TD>
+ <TD align=middle>J</TD>
+ <TD align=middle>K</TD>
+ <TD align=middle>L</TD>
+ <TD align=middle>M</TD>
+ <TD align=middle>N</TD>
+ <TD align=middle>O</TD></TR>
+ <TR>
+ <TD align=middle><B>8</B></TD>
+ <TD align=middle>P</TD>
+ <TD align=middle>Q</TD>
+ <TD align=middle>R</TD>
+ <TD align=middle>S</TD>
+ <TD align=middle>T</TD>
+ <TD align=middle>U</TD>
+ <TD align=middle>V</TD>
+ <TD align=middle>W</TD>
+ <TD align=middle>X</TD>
+ <TD align=middle>Y</TD></TR>
+ <TR>
+ <TD align=middle><B>9</B></TD>
+ <TD align=middle>Z</TD>
+ <TD align=middle>[</TD>
+ <TD align=middle>\</TD>
+ <TD align=middle>]</TD>
+ <TD align=middle>^</TD>
+ <TD align=middle>_</TD>
+ <TD align=middle>'</TD>
+ <TD align=middle>a</TD>
+ <TD align=middle>b</TD>
+ <TD align=middle>c</TD></TR>
+ <TR>
+ <TD align=middle><B>10</B></TD>
+ <TD align=middle>d</TD>
+ <TD align=middle>e</TD>
+ <TD align=middle>f</TD>
+ <TD align=middle>g</TD>
+ <TD align=middle>h</TD>
+ <TD align=middle>i</TD>
+ <TD align=middle>j</TD>
+ <TD align=middle>k</TD>
+ <TD align=middle>l</TD>
+ <TD align=middle>m</TD></TR>
+ <TR>
+ <TD align=middle><B>11</B></TD>
+ <TD align=middle>n</TD>
+ <TD align=middle>o</TD>
+ <TD align=middle>p</TD>
+ <TD align=middle>q</TD>
+ <TD align=middle>r</TD>
+ <TD align=middle>s</TD>
+ <TD align=middle>t</TD>
+ <TD align=middle>u</TD>
+ <TD align=middle>v</TD>
+ <TD align=middle>w</TD></TR>
+ <TR>
+ <TD align=middle><B>12</B></TD>
+ <TD align=middle>x</TD>
+ <TD align=middle>y</TD>
+ <TD align=middle>z</TD>
+ <TD align=middle>{</TD>
+ <TD align=middle>|</TD>
+ <TD align=middle>}</TD>
+ <TD align=middle>~</TD>
+ <TD align=middle>del</TD></TR></TBODY></TABLE>
+<P></P>
+<CENTER><CAPTION><A name=pgfId=8168></A>The ASCII character
+set.</CAPTION></CENTER>
+<P></CENTER>
+<P><BR><BR></P>
+<P></P>
+<P>The digits at the left of the table are the left digits of the decimal
+equivalent (0-127) of the character code, and the digits at the top of the table
+are the right digits of the character code. For example, the character code for
+`F' is 70, and the character code for `&' is 38.</P>
+<P>Note: Most users of this book are interested in the ASCII character set used
+to represent English characters on many computers. The ASCII character set is a
+subset of the Unicode character set used to represent characters from most of
+the world's languages. For more information on the Unicode character set, visit
+the World Wide Web site:</P>
+<DIV></DIV>
+<P><CODE><B> <A
+href="http://unicode.org/">http://unicode.org/</A></B></CODE> </P>
+<DIV></DIV>
+<DIV></DIV></BODY></HTML>
diff --git a/Bachelor/Prog1/Codierungsstandard.htm b/Bachelor/Prog1/Codierungsstandard.htm new file mode 100644 index 0000000..844c06d --- /dev/null +++ b/Bachelor/Prog1/Codierungsstandard.htm @@ -0,0 +1,319 @@ +<html><head>
+<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+
+<title>Codierungs-Standard</title><style>
+<!--
+ p.MsoNormal
+ {mso-style-parent:"";
+ margin-bottom:.0001pt;
+ font-size:12.0pt;
+ font-family:"Times New Roman";
+ margin-left:0cm; margin-right:0cm; margin-top:0cm}
+ li.MsoNormal
+ {mso-style-parent:"";
+ margin-bottom:.0001pt;
+ font-size:12.0pt;
+ font-family:"Times New Roman";
+ margin-left:0cm; margin-right:0cm; margin-top:0cm}
+-->
+</style></head>
+
+<body>
+
+<p class="MsoNormal" style="">
+<span style="font-size: 14.5pt; font-family: Arial;">Codierungs-Standard</span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 14.5pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;">Der hier angeführte
+Codierungs-Standard ist im wesentlichen aus dem Buch von Schmaranz (s.
+Literaturliste) übernommen. Er ist in einigen wenigen Punkten modifiziert, so
+dass er mit den in der Vorlesung verwendeten Beispielen konform ist. Es sind
+natürlich auch andere Standards denkbar und sinnvoll, für die Praktikumsaufgaben
+<b>und in der Klausur </b>ist jedoch dieser Standard einzuhalten!</span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style=""><b>
+<span style="font-family: Arial;">1 Generelle Regeln</span></b></p>
+<p class="MsoNormal" style="">
+<span style="font-family: Arial;"> </span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;">Die folgenden Prinzipien sind
+essentiell für die Lesbarkeit, Wartbarkeit und Erweiterbarkeit eines Programms:</span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style=""><b>
+<span style="font-size: 10pt; font-family: Arial;">Einfachheit:</span></b><span style="font-size: 10pt; font-family: Arial;">
+Das Prinzip der Einfachheit ist auch als das KISS-Prinzip (<b>K</b>eep <b>I</b>t
+<b>S</b>mall and <b>S</b>imple) bekannt. Kurz gesagt sollen Methoden, Funktionen
+und natürlich auch Operatoren genau eine, für ihren Abstraktionslevel adäquate,
+atomare Aufgabe erfüllen. Niemals sollen mehrere Aufgaben auf einmal erledigt
+werden, genauso wenig, wie Aufgaben erledigt werden sollen, die in ein anderes
+Abstraktionslevel gehören (=Durchgriff nach unten oder oben). Parameterlisten
+sollen so kurz und übersichtlich wie möglich gehalten werden. Methoden,
+Operatoren und Funktionen sollen als Faustregel nicht mehr als 60 Zeilen lang
+sein. Eine durchschnittliche Länge von ca. 30 Zeilen ist zu bevorzugen.
+Seiteneffekte sind absolut zu vermeiden!</span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style=""><b>
+<span style="font-size: 10pt; font-family: Arial;">Intuitivität: </span></b>
+<span style="font-size: 10pt; font-family: Arial;">Das Prinzip der Intuitivität
+bedeutet, dass man den geschriebenen Source-Code "wie ein Buch" lesen und
+verstehen können muss, und zwar ohne Kommentare im Source-Code und ohne
+Erklärungen des Programmierers! Damit ist impliziert, dass Variablen-, Methoden-
+und Funktionsnamen sprechend (=selbsterklärend) und genau ihrer Funktionalität
+entsprechend benannt sein müssen. Einbuchstabenvariablen, wie z.B. i, sind nur
+in Sonderfällen wie Schleifenzähler erlaubt. Unnötige Kommentare werden als
+störend erachtet und sollen dementsprechend weggelassen werden. Ein typisches
+Beispiel für solche unnötigen Kommentare wäre:</span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Courier New;" lang="EN-GB">count++;
+// and here the counter is incremented</span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style=""><b>
+<span style="font-size: 10pt; font-family: Arial;">Einheitlichkeit:</span></b><span style="font-size: 10pt; font-family: Arial;"> Verwandte Teile im Source-Code müssen denselben Prinzipien folgen. Wenn
+z.B. eine Funktion </span>
+<span style="font-size: 10pt; font-family: "Courier New";">copy</span><span style="font-size: 10pt; font-family: Arial;">
+als ersten Parameter den Zielort und als zweiten Parameter den Ursprungsort
+nimmt, dann müssen verwandte Funktionen, wie z.B. </span>
+<span style="font-size: 10pt; font-family: "Courier New";">move</span><span style="font-size: 10pt; font-family: Arial;">,
+sich an dieselben Konventionen halten. Genauso gilt dies auch für Klassen und
+ihre Methoden. Nehmen wir z.B. eine Klasse die einen Knoten für z.B. eine
+einfach verkettete Liste repräsentiert. Wenn in dieser Klasse der nachfolgende
+Knoten über Aufruf von </span>
+<span style="font-size: 10pt; font-family: "Courier New";">next()</span><span style="font-size: 10pt; font-family: Arial;">
+erreichbar ist, dann darf er nicht in einem Knoten für eine doppelt verkettete
+Liste auf einmal über Aufruf von </span>
+<span style="font-size: 10pt; font-family: "Courier New";">successor()</span><span style="font-size: 10pt; font-family: Arial;">
+erreichbar sein.</span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style=""><b>
+<span style="font-family: Arial;">2 Codierungs-Regeln</span></b></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;">Die hier angeführten Regeln
+helfen, den Source-Code so weit wie möglich zu vereinheitlichen und damit die
+Arbeit in einem Team zu erleichtern:</span></p>
+<ul style="margin-top: 0cm; margin-bottom: 0cm;" type="disc">
+ <li class="MsoNormal" style=""><b>
+ <span style="font-size: 10pt; font-family: Arial;">Die Sprache für Source-Code
+ ist Englisch. Dies gilt für alle Teile eines Programms</span></b><span style="font-size: 10pt; font-family: Arial;">,
+ von Variablennamen über Methoden- und Funktionsnamen bis hin zu Kommentaren im
+ Source-Code.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Der Gebrauch von Block-Kommentaren </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">(/* comment
+ */</span><span style="font-size: 10pt; font-family: Arial;">) ist zu vermeiden.
+ Stattdessen müssen Zeilenkommentare (</span><span style="font-size: 10pt; font-family: "Courier New";">// comment</span><span style="font-size: 10pt; font-family: Arial;">) eingesetzt werden. Dies macht Source-Code robuster gegen
+ Änderungen und erleichtert das Debugging</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Wenn es sich nicht vermeiden lässt, z.B.
+ algorithmische Details in Form von Kommentaren in den Source-Code
+ einzubringen, dann ist ein Block mit einer vollständigen Erklärung des
+ Algorithmus vor der Implementation des Algorithmus selbst zu schreiben. Es
+ darf die Kommentierung des Algorithmus nicht im laufenden Source-Code Zeile
+ für Zeile erfolgen, denn sonst wird der Code durch die Kommentare unleserlich.
+ Natürlich sind wenige, kurze Kommentare in Form von Cross-References zur
+ vollständigen Erklärung manchmal sinnvoll und deshalb erlaubt.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Sollten jemals Codezeilen in das Programm Eingang
+ finden, bei denen beim Lesen der Zeile nicht sofort klar ist, was sie tut,
+ dann muss dies in einem kurzen Kommentar dort festgehalten werden. Jedoch
+ sollte man sich immer sehr gut überlegen, ob es nicht eigentlich ein besseres,
+ leichter lesbares Konstrukt gibt, das keinen Kommentar benötigt, um verstanden
+ zu werden.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Globale Variablen sind nach allen Möglichkeiten
+ zu vermeiden!</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">C-Style Casts sind zu vermeiden. Stattdessen
+ müssen die "echten" C++-Casts </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">static_cast</span><span style="font-size: 10pt; font-family: Arial;">, </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">dynamic_cast</span><span style="font-size: 10pt; font-family: Arial;">, etc. Anwendung finden.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Wenn aus irgendwelchen Gründen böse Hacks im
+ Source-Code temporär nicht vermeidbar sind (z.B. Zeitdruck), so sind diese
+ unbedingt in hackstart und hack-end Kommentare zu fassen, damit man sie
+ einfach wieder finden und ausbessern kann. Die hack-... Kommentare haben die
+ folgendeForm:<br>
+ </span><span style="font-size: 10pt; font-family: "Courier New";">//
+ FIXXME (<author, date>) -> <description of the hack><br>
+ [..... the code with the hack .....]<br>
+ // END FIXXME (<author, date>)</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Hier gehört das Keyword </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">FIXXME</span><span style="font-size: 10pt; font-family: Arial;"> immer mit zumindest zwei '</span><span style="font-size: 10pt; font-family: "Courier New";">X</span><span style="font-size: 10pt; font-family: Arial;">' geschrieben, denn damit kann man leicht nach ihm
+ suchen. Je nachdem, wie schlimm der Hack ist, können auch mehrere '</span><span style="font-size: 10pt; font-family: "Courier New";">X</span><span style="font-size: 10pt; font-family: Arial;">'
+ vorkommen. Als Faustregel für die Abstufung gilt, dass der SVH (=Schlimmste
+ Vorstellbare Hack) mit 5 '</span><span style="font-size: 10pt; font-family: "Courier New";">X</span><span style="font-size: 10pt; font-family: Arial;">'
+ geschrieben wird.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Klassendeklarationen müssen von ihren
+ Definitionen getrennt und in einem separaten Header File gespeichert werden.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Alle Klassen müssen einen </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">virtual</span><span style="font-size: 10pt; font-family: Arial;">
+ Destruktor besitzen.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Alle Klassen müssen sowohl den Copy-Constructor
+ als auch den Zuweisungsoperator explizit implementieren. Wenn keine
+ Implementation der beiden gewünscht ist, dann müssen sie als Dummies
+ implementiert und auf </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">private</span><span style="font-size: 10pt; font-family: Arial;"> gesetzt werden.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Alle Headers müssen durch Definition und
+ entsprechende Abfragen von Preprocessor Macros vor Mehrfachinklusion geschützt
+ werden. Das entsprechende </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">#define</span><span style="font-size: 10pt; font-family: Arial;"> muss der folgenden Namenskonvention entsprechen: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">FILENAME_H</span><span style="font-size: 10pt; font-family: Arial;">,
+ wobei </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">FILENAME_H</span><span style="font-size: 10pt; font-family: Arial;">
+ natürlich dem Namen der Headerdatei entspricht.</span></li>
+ <li class="MsoNormal" style=""><b>
+ <span style="font-size: 10pt; font-family: Arial;">Namen von Bezeichnern</span></b><span style="font-size: 10pt; font-family: Arial;">
+ müssen den folgenden Konventionen genügen:<br>
+ Klassen: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">
+ AlleWorteCapitalizedOhneUnderlines</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Structures: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">
+ GleichWieKlassen</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Unions: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">
+ GleichWieKlassen</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Exceptions: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">
+ KlassennameEndetMitException</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Methoden und Funktionen: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">erstesWortKleinRestCapitalized</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Konstanten: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">
+ GROSS_MIT_UNDERLINES</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Member Variablen: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">
+ erstesWortKleinRestCapitalized</span><span style="font-size: 10pt; font-family: Arial;"><br>
+ Lokale Variablen: </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">
+ erstesWortKleinRestCapitalized</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Neben diesen generellen Konventionen gibt es auch
+ eine spezielle Konvention, die sich auf die Semantik von Methoden bezieht:<br>
+ Schreibende Zugriffsmethoden auf Member Variablen müssen </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">setXXX</span><span style="font-size: 10pt; font-family: Arial;">
+ und ihre lesenden Äquivalente </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">getXXX</span><span style="font-size: 10pt; font-family: Arial;">
+ benannt werden (z.B. </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">setMaxUsers</span><span style="font-size: 10pt; font-family: Arial;">,
+ </span><span style="font-size: 10pt; font-family: "Courier New";">
+ getMaxUsers</span><span style="font-size: 10pt; font-family: Arial;">). Eine
+ Ausnahme dabei bilden Zugriffe auf boolsche Variablen: Hier wird die lesende
+ Methode semantisch sinnvoll mit </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">isXXX</span><span style="font-size: 10pt; font-family: Arial;">,
+ </span><span style="font-size: 10pt; font-family: "Courier New";">
+ hasXXX</span><span style="font-size: 10pt; font-family: Arial;">, </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">allowsXXX</span><span style="font-size: 10pt; font-family: Arial;">
+ o.ä. benannt (z.B. </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">setReadOnly</span><span style="font-size: 10pt; font-family: Arial;">,
+ </span><span style="font-size: 10pt; font-family: "Courier New";">
+ isReadOnly</span><span style="font-size: 10pt; font-family: Arial;">).</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Die Struktur des Source-Codes muss den folgenden
+ Prinzipien genügen:</span></li>
+</ul>
+<p class="MsoNormal" style="text-indent: -14.2pt; margin-left: 68.2pt;">
+<span style="font-size: 10pt; font-family: Symbol;">-<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
+</span></span><span style="font-size: 10pt; font-family: Arial;">Jedes File muss
+einen Header besitzen, in dem zumindest der Filename, und eine kurze
+Beschreibung des Inhalts zu finden sind. In der Praxis hat es sich eingebürgert,
+dass außerdem der Name des Autors, das Erstellungsdatum, das letzte
+Änderungsdatum, eine Versionsnummer und ein Copyright-Statement im Header
+stehen.</span></p>
+<p class="MsoNormal" style="text-indent: -14.2pt; margin-left: 68.2pt;">
+<span style="font-size: 10pt; font-family: Symbol;">-<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
+</span></span><span style="font-size: 10pt; font-family: Arial;">Geschwungene
+Klammern für Code-Blöcke müssen in einer eigenen Zeile stehen. Ausnahme hiervon
+sind Codeblöcke, die zu Kontrollstrukturen (Auswahl, Wiederholung) gehören. Bei
+diesen steht die öffnende geschwungene Klammer in derselben Zeile wie das
+Schlüsselwort der Kontrollstruktur (</span><span style="font-size: 10pt; font-family: "Courier New";">if</span><span style="font-size: 10pt; font-family: Arial;">, </span>
+<span style="font-size: 10pt; font-family: "Courier New";">while</span><span style="font-size: 10pt; font-family: Arial;">,
+</span><span style="font-size: 10pt; font-family: "Courier New";">for</span><span style="font-size: 10pt; font-family: Arial;">, …). Die Einrückung der Klammern entspricht genau dem
+umschließenden Block. Der eingeschlossene Block selbst muss genau um 3 Spaces
+eingerückt sein (hier sind in der Praxis Werte zwischen 2 und 4 gängig).
+Einrückungen dürfen ausschließlich mit Spaces gemacht werden, Tabs sind
+verboten, denn sonst kann es mit verschiedenen Editor-Einstellungen und beim
+Drucken Probleme geben.</span></p>
+<p class="MsoNormal" style="text-indent: -14.2pt; margin-left: 68.2pt;">
+<span style="font-size: 10pt; font-family: Symbol;">-<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
+</span></span><span style="font-size: 10pt; font-family: Arial;">Vor jeder
+Operator-, Methoden- oder Funktionsdefinition muss in kurzen Worten beschrieben
+werden, wozu diese Funktion dient. Bei größeren Projekten muss auch beschrieben
+sein, was bei den einzelnen Parametern erwartet wird, welche Randbedingungen
+gelten, welche Return-Values zu erwarten sind und wie diese zu interpretieren
+sind.</span></p>
+<p class="MsoNormal" style="margin-left: 54pt;">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style="margin-left: 54pt;">
+<span style="font-size: 10pt; font-family: Arial;"> </span></p>
+<p class="MsoNormal" style=""><b>
+<span style="font-family: Arial;">3 Design Guidelines</span></b></p>
+<p class="MsoNormal" style=""><b>
+<span style="font-family: Arial;"> </span></b></p>
+<p class="MsoNormal" style="">
+<span style="font-size: 10pt; font-family: Arial;">Dieser Abschnitt enthält einige
+generelle Richtlinien, die helfen sollen, sauberen und robusten Code zu
+schreiben.</span></p>
+<ul style="margin-top: 0cm; margin-bottom: 0cm;" type="disc">
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Membervariablen dürfen niemals </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">public</span><span style="font-size: 10pt; font-family: Arial;">
+ zugreifbar sein.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Interne und externe Zugriffsmethoden dürfen
+ niemals vermischt werden. Wenn Methoden zum Zugriff für die Außenwelt gedacht
+ sind und entsprechend </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">public</span><span style="font-size: 10pt; font-family: Arial;"> zugreifbar sind, so dürfen diese klassenintern nicht verwendet
+ werden. Wenn man beispielsweise ein Paar von Methoden </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">setVariable</span><span style="font-size: 10pt; font-family: Arial;">,
+ </span><span style="font-size: 10pt; font-family: "Courier New";">
+ getVariable</span><span style="font-size: 10pt; font-family: Arial;"> als </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">public</span><span style="font-size: 10pt; font-family: Arial;">
+ zur Verfügung stellt, dann dürfen diese intern nicht für den Zugriff verwendet
+ werden. Stattdessen muss der direkte Zugriff auf die Membervariable erfolgen.
+ Der Grund dafür ist einfach zu erkennen: In </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">public</span><span style="font-size: 10pt; font-family: Arial;"> Methoden werden alle möglichen Schutzmechanismen
+ eingebaut, die eine Fehlverwendung ausschließen sollen. Man will aber eine
+ Klasse nicht vor sich selbst schützen. Sollten tatsächlich auch intern
+ Methoden für gewisse Zugriffe benötigt werden, so sind diese getrennt und
+ entweder </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">protected</span><span style="font-size: 10pt; font-family: Arial;">
+ oder </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">private</span><span style="font-size: 10pt; font-family: Arial;">
+ zu implementieren. Durch diese Maßnahme erreicht man eine saubere Trennung
+ zwischen dem </span>
+ <span style="font-size: 10pt; font-family: "Courier New";">public</span><span style="font-size: 10pt; font-family: Arial;">
+ Interface und der internen Implementation einer Klasse.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Seiteneffekte und unerwartetes (d.h. nicht aus
+ dem Namen ersichtliches) Verhalten von Methoden, Operatoren und Funktionen
+ sind um jeden Preis zu vermeiden!</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Niemals dürfen sogenannte silent Catches
+ implementiert werden, also Catches von Exceptions, die ganz einfach sang- und
+ klanglos ignoriert werden.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Exceptions dürfen niemals zu Standard
+ Flow-Control Zwecken verwendet werden.</span></li>
+ <li class="MsoNormal" style="">
+ <span style="font-size: 10pt; font-family: Arial;">Abstrakte Methoden in Basisklassen sind unbedingt
+ solchen mit sinnlosen dummy Implementationen vorzuziehen.</span></li>
+</ul>
+<p class="MsoNormal"><span style="font-family: Arial;"> </span></p>
+
+</body></html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Folien/chapter01.ppt b/Bachelor/Prog1/Folien/chapter01.ppt Binary files differnew file mode 100644 index 0000000..e40e68c --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter01.ppt diff --git a/Bachelor/Prog1/Folien/chapter02.ppt b/Bachelor/Prog1/Folien/chapter02.ppt Binary files differnew file mode 100644 index 0000000..97e0c0c --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter02.ppt diff --git a/Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt Binary files differnew file mode 100644 index 0000000..376ef1b --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter02_CaseStudy.ppt diff --git a/Bachelor/Prog1/Folien/chapter03.ppt b/Bachelor/Prog1/Folien/chapter03.ppt Binary files differnew file mode 100644 index 0000000..ecc78ac --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter03.ppt diff --git a/Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt Binary files differnew file mode 100644 index 0000000..f286397 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter03_CaseStudy.ppt diff --git a/Bachelor/Prog1/Folien/chapter04.ppt b/Bachelor/Prog1/Folien/chapter04.ppt Binary files differnew file mode 100644 index 0000000..0166fba --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter04.ppt diff --git a/Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt Binary files differnew file mode 100644 index 0000000..3fe5dd6 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter04_CaseStudy.ppt diff --git a/Bachelor/Prog1/Folien/chapter05.ppt b/Bachelor/Prog1/Folien/chapter05.ppt Binary files differnew file mode 100644 index 0000000..a9c8bb9 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter05.ppt diff --git a/Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt Binary files differnew file mode 100644 index 0000000..d750294 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter05_CaseStudy.ppt diff --git a/Bachelor/Prog1/Folien/chapter06.ppt b/Bachelor/Prog1/Folien/chapter06.ppt Binary files differnew file mode 100644 index 0000000..1faff91 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter06.ppt diff --git a/Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt Binary files differnew file mode 100644 index 0000000..5c67b11 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter06_CaseStudy.ppt diff --git a/Bachelor/Prog1/Folien/chapter07.ppt b/Bachelor/Prog1/Folien/chapter07.ppt Binary files differnew file mode 100644 index 0000000..fe27bec --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter07.ppt diff --git a/Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt b/Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt Binary files differnew file mode 100644 index 0000000..99992a6 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter07_CaseStudy.ppt diff --git a/Bachelor/Prog1/Folien/chapter08.ppt b/Bachelor/Prog1/Folien/chapter08.ppt Binary files differnew file mode 100644 index 0000000..e236968 --- /dev/null +++ b/Bachelor/Prog1/Folien/chapter08.ppt diff --git a/Bachelor/Prog1/Hinweise.pdf b/Bachelor/Prog1/Hinweise.pdf Binary files differnew file mode 100644 index 0000000..0fd297c --- /dev/null +++ b/Bachelor/Prog1/Hinweise.pdf diff --git a/Bachelor/Prog1/Klausur 'Programmieren I' am 10.02.05.eml b/Bachelor/Prog1/Klausur 'Programmieren I' am 10.02.05.eml new file mode 100644 index 0000000..068b100 --- /dev/null +++ b/Bachelor/Prog1/Klausur 'Programmieren I' am 10.02.05.eml @@ -0,0 +1,84 @@ +Return-Path: <h.p.weber@gmx.de>
+Received: from murder ([unix socket])
+ by ns1 (Cyrus v2.2.10-Gentoo) with LMTPA;
+ Fri, 28 Jan 2005 10:33:05 +0100
+X-Sieve: CMU Sieve 2.2
+Received: from localhost (localhost [127.0.0.1])
+ by ns1.eisy.net.eu.org (eisy's SMTP Server READY) with ESMTP id 73892625E1
+ for <sven@localhost.eisy.net.eu.org>; Fri, 28 Jan 2005 10:33:04 +0100 (CET)
+Received: from ns1.eisy.net.eu.org ([127.0.0.1])
+ by localhost (ns1 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
+ id 08412-04 for <sven@localhost.eisy.net.eu.org>;
+ Fri, 28 Jan 2005 10:32:50 +0100 (CET)
+Received: from localhost (localhost [127.0.0.1])
+ by ns1.eisy.net.eu.org (eisy's SMTP Server READY) with ESMTP id EE7D1625B0
+ for <sven@localhost>; Fri, 28 Jan 2005 10:32:49 +0100 (CET)
+Delivery-Date: Fri, 28 Jan 2005 10:32:16 +0100
+Received: from pop.kundenserver.de [212.227.15.149]
+ by localhost with POP3 (fetchmail-6.2.5)
+ for sven@localhost (single-drop); Fri, 28 Jan 2005 10:32:50 +0100 (CET)
+Received: from [213.165.64.20] (helo=mail.gmx.net)
+ by mxeu5.kundenserver.de with ESMTP (Nemesis),
+ id 0MKqpg-1CuSUB2ep0-00060g; Fri, 28 Jan 2005 10:32:15 +0100
+Received: (qmail 19885 invoked by uid 0); 28 Jan 2005 09:25:35 -0000
+Received: from 141.100.244.48 by www37.gmx.net with HTTP;
+ Fri, 28 Jan 2005 10:25:35 +0100 (MET)
+Date: Fri, 28 Jan 2005 10:25:35 +0100 (MET)
+From: "Hans-Peter Weber" <h.p.weber@gmx.de>
+To: Leistungsnachweis "Programmieren I" <h.p.weber@fbi.fh-darmstadt.de>
+MIME-Version: 1.0
+Subject: Klausur "Programmieren I" am 10.02.05
+X-Priority: 3 (Normal)
+X-Authenticated: #3431627
+Message-ID: <30230.1106904335@www37.gmx.net>
+X-Mailer: WWW-Mail 1.6 (Global Message Exchange)
+X-Flags: 0001
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Transfer-Encoding: 8bit
+Envelope-To: info@sven-eisenhauer.net
+X-SpamScore: 0.000
+X-Virus-Scanned: by amavisd-new at ns1
+
+An alle zur Klausur "Programmieren I" am 10.02.05 angemeldeten
+Studierenden,
+
+einige Hinweise zur Klausur:
+
+- Alle Studierenden, die das Praktikum nicht in einer meiner Veranstaltungen
+(in diesem Semester also bei Herrn Wolf oder mir)
+gemacht haben, müssen spätestens beim Betreten des Klausurraumes die
+Bestätigung ('grüner Schein' o.ä.) über die erfolgreiche Teilnahme am
+Praktikum 'Programmieren 1' bei mir abgeben. Fehlt diese Bestätigung, ist
+eine Klausurteilnahme nicht möglich.
+
+- Bringen Sie Ihren Studentenausweis mit und zeigen Sie ihn mir beim
+Betreten des Klausurraumes.
+
+- Alle Studenten, die nicht an meiner Vorlesung teilgenommen haben, weise
+ich hiermit auf den benutzten Codierungsstandard hin (s.
+http://www.fbi.fh-darmstadt.de/~h.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/Codierungsstandard.htm
+). Bei grober Missachtung dieses Standards kann ein Punktabzug erfolgen.
+
+- Aus gegebenem Anlass noch folgender Hinweis: Dies ist die PG I - Klausur
+von Hans-Peter Weber, nicht Wolfgang Weber. Die Klausur des Kollegen
+Wolfgang Weber findet am Do, 03.02.05 - also eine Woche vor meiner - statt.
+
+- Wenn Sie doch nicht an dieser (meiner) Klausur teilnehmen möchten, melden
+Sie sich im Online-Belegsystem wieder ab. Dies ist noch bis zum 06.02.05
+möglich.
+
+
+Eine gute Klausurvorbereitung und bis zum 10.02.
+Hans-Peter Weber
+
+--
+Prof.Dr.Hans-Peter Weber
+Fachhochschule Darmstadt
+Fachbereich Informatik, Standort Dieburg
+Max-Planck-Str.2
+64807 Dieburg
+
+Telefon: +49 6071 829-240
+Telefax: +49 6071 829-340
+e-mail: h.p.weber@fbi.fh-darmstadt.de
+
diff --git a/Bachelor/Prog1/Literatur.htm b/Bachelor/Prog1/Literatur.htm new file mode 100644 index 0000000..849e40c --- /dev/null +++ b/Bachelor/Prog1/Literatur.htm @@ -0,0 +1,105 @@ +<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+ <meta name="Author" content="H.P.Weber">
+
+ <title>Literatur</title><!-- base -->
+ <style>
+<!--
+.sans { font-family: verdana,arial,helvetica,sans-serif; font-size: small; }
+-->
+ </style></head>
+
+<body>
+<font color="#000000"><font size="+1">empfohlene Literatur</font></font>
+<br>
+<table border="1">
+<tbody><tr bgcolor="#efefde">
+
+<td><font color="#000000">Autor & Titel</font></td>
+
+<td><font color="#000000">Bemerkungen</font></td>
+</tr>
+
+<tr valign="top">
+
+<td><font color="#000000">H.M.Deitel,P.J.Deitel: C++ How To Program, 4th ed;
+ Prentice-Hall; 2003; EUR ca 60</font></td>
+
+<td><font color="#000000">Basistext der Vorlesung, deshalb primär empfohlen. Enthält auf CD die im Praktikum benutzte
+Entwicklungsumgebung MS Visual C++ 6.0 (Introductory Edition, englisch).</font>
+</td>
+</tr>
+
+<tr valign="top">
+
+<td><font color="#000000">P.Prinz,U.Kirch-Prinz: C++, Lernen und professionell
+ anwenden, 2.Auflage; MITP-Verlag; 2002; EUR 44.95</font></td>
+
+<td><font color="#000000">Gut zum Nachschlagen geeignet. Enthält auf CD die im Praktikum benutzte
+Entwicklungsumgebung MS Visual C++ 6.0 (Autorenversion, deutsch).</font>
+<br><font color="#000000">Vorsicht: Das ansonsten ähnliche Buch der gleichen
+Autoren 'Objektorientiert programmieren mit ANSI C++' enthält kein MS Visual C++ 6.0
+, sondern den GNU-C++ Compiler. </font></td>
+</tr>
+
+<tr valign="top">
+
+<td><font color="#000000">P.Prinz,U.Kirch-Prinz: C++, Das Übungsbuch; MITP-Verlag; 2003; EUR
+18.95</font></td>
+
+<td>25 Abschnitte zu den wichtigsten Themen der Vorlesung (außer STL) mit
+jeweils 20 Verständnisfragen (!) und 10 Programmieraufgaben zum Üben. Unbedingt
+empfehlenswert!</td>
+</tr>
+
+
+<tr valign="top">
+
+<td><font color="#000000">U.Breymann: C++. Eine Einführung, 7.Auflage; Hanser;
+ 2003; EUR 39,90.</font></td>
+
+<td>Deutschsprachiges Standardwerk zu Sprachsyntax und Objektorientierung.</td>
+</tr>
+
+<tr valign="top">
+
+<td>K.Schmaranz: Softwareentwicklung in C++; Springer-Verlag; 2003; EUR 49,95</td>
+
+<td>Viele für das Verständnis förderliche Details. Fachlich wird der
+fortgeschrittene erwachsene Entwickler angesprochen, stilistisch leider eher der
+jugendliche Anfänger :-)</td>
+</tr>
+
+<tr valign="top">
+
+<td><font color="#000000">N.Josuttis: Objektorientiertes Programmieren in C++ ,
+ 2.Auflage; Addison-Wesley; 2001; EUR 39,95</font></td>
+
+<td>Anderen deutschsprachigen C++-Lehrbüchern voraus, da
+ es konsequent die Möglichkeiten der Standardbibliothek nutzt. Eher für
+ Fortgeschrittene geeignet.</td>
+</tr>
+
+<tr valign="top">
+
+<td><font color="#000000" face="Times New Roman">A.Koenig, B.Moo: </font>
+<font face="Times New Roman">Intensivkurs C++<font color="#000000">;
+Addison-Wesley; 2003; EUR 34.95</font></font></td>
+
+<td>Übersetzung eines englischsprachigen Standardwerkes. Moderne, an den
+ Möglichkeiten der STL orientierte Einführung in
+ C++. Eher für Fortgeschrittene geeignet.</td>
+</tr>
+
+<tr valign="top">
+
+<td>T.Erler: UML; bhv-Verlag; 2000; EUR 10,12</td>
+
+<td>Kompakte und gut lesbare Einführung zu Grundbegriffen und Anwendung der
+ UML.</td>
+</tr>
+
+</tbody></table>
+</body></html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Op_Prec.htm b/Bachelor/Prog1/Op_Prec.htm new file mode 100644 index 0000000..3e0b1b1 --- /dev/null +++ b/Bachelor/Prog1/Op_Prec.htm @@ -0,0 +1,219 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!-- saved from url=(0070)http://cwx.prenhall.com/bookbind/pubbooks/deitelcpp/medialib/appa.html -->
+<HTML><HEAD><TITLE>Reference Material-Operator Precedence Chart</TITLE>
+<META http-equiv=Content-Type content="text/html; charset=windows-1252">
+<META content="MSHTML 5.50.4134.600" name=GENERATOR><LINK
+href="appa-Dateien/APPEN_A.css" rel=STYLESHEET></HEAD>
+<BODY text=#410d9c bgColor=#ffffff>
+<CENTER><FONT size=+3><B>Operator Precedence Chart</B></FONT>
+<P><BR>Operators are shown in decreasing order of precedence from top to bottom.
+</P>
+<TABLE cellSpacing=5 cellPadding=5 border=1>
+ <TBODY>
+ <TR>
+ <TH>
+ <P class=TCH><A name=pgfId=10391></A><EM class=Bold>Operator</EM> </P></TH>
+ <TH>
+ <P class=TCH><A name=pgfId=10393></A><EM class=Bold>Type</EM> </P></TH>
+ <TH>
+ <P class=TCH><A name=pgfId=10395></A><EM class=Bold>Associativity</EM>
+ </P></TH></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10397></A><EM class=Courier-Bold>::</EM>
+ </P>
+ <P class=CellBody><A name=pgfId=10398></A><EM class=Courier-Bold>::</EM>
+ </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10400></A>binary scope resolution</P>
+ <P class=CellBody><A name=pgfId=10401></A>unary scope resolution</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10403></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10405></A><EM
+ class=Courier-Bold>()<BR>[]<BR>.</EM> </P>
+ <P class=CellBody><A name=pgfId=10406></A><EM
+ class=Courier-Bold>-></EM> </P>
+ <P class=CellBody><A name=pgfId=10407></A>++</P>
+ <P class=CellBody><A name=pgfId=10408></A>--</P>
+ <P class=CellBody><A name=pgfId=10409></A><B>typeid</B></P>
+ <P class=CellBody><A name=pgfId=10410></A><B>dynamic_cast<</B><EM
+ class=Italic> type </EM> <B>></B></P>
+ <P class=CellBody><A name=pgfId=10411></A><B>static_cast<</B><EM
+ class=Italic> type </EM> <B>></B></P>
+ <P class=CellBody><A name=pgfId=10412></A><B>reinterpret_cast<</B><EM
+ class=Italic> type </EM> <B>></B></P>
+ <P class=CellBody><A name=pgfId=10413></A><B>const_cast<</B><EM
+ class=Italic> type </EM> <B>></B></P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10415></A>parentheses<BR>array
+ subscript<BR>member selection via object</P>
+ <P class=CellBody><A name=pgfId=10416></A>member selection via pointer</P>
+ <P class=CellBody><A name=pgfId=10417></A>unary postincrement</P>
+ <P class=CellBody><A name=pgfId=10418></A>unary postdecrement</P>
+ <P class=CellBody><A name=pgfId=10419></A>run-time type information</P>
+ <P class=CellBody><A name=pgfId=10420></A>run-time type-checked cast</P>
+ <P class=CellBody><A name=pgfId=10421></A>compile-time type-checked
+ cast</P>
+ <P class=CellBody><A name=pgfId=10422></A>cast for non-standard
+ conversions</P>
+ <P class=CellBody><A name=pgfId=10423></A>cast away <EM
+ class=Courier-Bold>const</EM>-ness</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10425></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10427></A><EM
+ class=Courier-Bold>++<BR>--<BR>+<BR>-<BR>!<BR>~<BR>( </EM><EM
+ class=Italic>type</EM> <EM class=Courier-Bold>)</EM> </P>
+ <P class=CellBody><A name=pgfId=10428></A><B>sizeof</B></P>
+ <P class=CellBody><A name=pgfId=10429></A><B>&</B></P>
+ <P class=CellBody><A name=pgfId=10430></A><B>*</B></P>
+ <P class=CellBody><A name=pgfId=10431></A><B>new</B></P>
+ <P class=CellBody><A name=pgfId=10432></A><B>new[]</B></P>
+ <P class=CellBody><A name=pgfId=10433></A><B>delete</B></P>
+ <P class=CellBody><A name=pgfId=10434></A><B>delete[]</B></P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10436></A>unary preincrement<BR>unary
+ predecrement<BR>unary plus<BR>unary minus<BR>unary logical
+ negation<BR>unary bitwise complement<BR>C-style unary cast</P>
+ <P class=CellBody><A name=pgfId=10437></A>determine size in bytes</P>
+ <P class=CellBody><A name=pgfId=10438></A>address</P>
+ <P class=CellBody><A name=pgfId=10439></A>dereference</P>
+ <P class=CellBody><A name=pgfId=10440></A>dynamic memory allocation</P>
+ <P class=CellBody><A name=pgfId=10441></A>dynamic array allocation</P>
+ <P class=CellBody><A name=pgfId=10442></A>dynamic memory deallocation</P>
+ <P class=CellBody><A name=pgfId=10443></A>dynamic array
+deallocation</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10445></A>right to left</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10447></A><B>.*</B></P>
+ <P class=CellBody><A name=pgfId=10448></A><B>->*</B></P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10450></A>pointer to member via object
+</P>
+ <P class=CellBody><A name=pgfId=10451></A>pointer to member via
+ pointer</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10453></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10455></A><EM
+ class=Courier-Bold>*<BR>/<BR>%</EM> </P></TD>
+ <TD>
+ <P class=CellBody><A
+ name=pgfId=10457></A>multiplication<BR>division<BR>modulus</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10459></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10461></A><EM
+ class=Courier-Bold>+<BR>-</EM> </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10463></A>addition<BR>subtraction</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10465></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10467></A><EM
+ class=Courier-Bold><<<BR>>></EM> </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10469></A>bitwise left shift<BR>bitwise
+ right shift</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10471></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10473></A><EM
+ class=Courier-Bold><<BR><=<BR>><BR>>=</EM> </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10475></A>relational less
+ than<BR>relational less than or equal to<BR>relational greater
+ than<BR>relational greater than or equal to</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10477></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10479></A><EM
+ class=Courier-Bold>==<BR>!=</EM> </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10481></A>relational is equal
+ to<BR>relational is not equal to</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10483></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10485></A><EM
+ class=Courier-Bold>&</EM> </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10487></A>bitwise AND</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10489></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10491></A><EM class=Courier-Bold>^</EM>
+ </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10493></A>bitwise exclusive OR </P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10495></A>left to right </P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10497></A><EM class=Courier-Bold>|</EM>
+ </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10499></A>bitwise inclusive OR </P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10501></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10503></A><EM
+ class=Courier-Bold>&&</EM> </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10505></A>logical AND</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10507></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10509></A><EM class=Courier-Bold>||</EM>
+ </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10511></A>logical OR</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10513></A>left to right</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10515></A><EM class=Courier-Bold>?:</EM>
+ </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10517></A>ternary conditional</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10519></A>right to left</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10521></A><EM
+ class=Courier-Bold>=<BR>+=<BR>-=<BR>*=<BR>/=<BR>%=<BR>&=<BR>^=<BR>|=<BR><<=<BR>>>=</EM>
+ </P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10523></A>assignment<BR>addition
+ assignment<BR>subtraction assignment<BR>multiplication
+ assignment<BR>division assignment<BR>modulus assignment<BR>bitwise AND
+ assignment<BR>bitwise exclusive OR assignment<BR>bitwise inclusive OR
+ assignment<BR>bitwise left shift assignment<BR>bitwise right shift with
+ sign</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10525></A>right to left</P></TD></TR>
+ <TR>
+ <TD>
+ <P class=CellBody><A name=pgfId=10527></A>,</P></TD>
+ <TD>
+ <P class=CellBody><A name=pgfId=10529></A>comma</P></TD>
+ <TD vAlign=top>
+ <P class=CellBody><A name=pgfId=10531></A>left to
+right</P></TD></TR></TBODY></TABLE>
+<DIV></DIV>
+<DIV></DIV>
+<DIV></DIV></CENTER></BODY></HTML>
diff --git a/Bachelor/Prog1/PG1Klaus.htm b/Bachelor/Prog1/PG1Klaus.htm new file mode 100644 index 0000000..38229c2 --- /dev/null +++ b/Bachelor/Prog1/PG1Klaus.htm @@ -0,0 +1,227 @@ +<html>
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<title>Praktikum 6</title>
+</head>
+
+<body>
+
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<caption> </caption>
+
+<tr>
+<td WIDTH="25%" BGCOLOR="#EFEFDE">FH Darmstadt
+<br>FB Informatik
+<br>Prof.Dr. H.P.Weber</td>
+
+<td>
+<center><font size="+3">Programmieren I </font>
+<br><font size="+3">Klausur</font></center>
+</td>
+
+<td WIDTH="25%" BGCOLOR="#EFEFDE">
+<center>
+<p><font size="6">20.01.04</font></p>
+</center>
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER COLS=3 WIDTH="100%" HEIGHT="60" >
+<tr>
+<td WIDTH="50%">Name:<p> </td>
+
+<td WIDTH="30%">MatNr.:<p> </td>
+
+<td WIDTH="20%">USER:<p> </td>
+</tr>
+</table>
+
+<br>
+<table BORDER="1" CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td COLSPAN = "3" height="60" width="1151">
+<h3 ALIGN = "left">
+Lottozahlen</h3>
+
+Definieren Sie eine Klasse <font face="Courier New"> <b>LottoGenerator</b></font> wie im folgenden
+Klassendiagramm beschrieben:</td>
+</tr>
+
+<tr>
+<td WIDTH="579" height="269">
+<table BORDER COLS=3 BGCOLOR="#EFEFDE" ALIGN="center">
+<tr>
+<td>
+<center><b>LottoGenerator</b></center>
+</td>
+</tr>
+
+<tr>
+<td>- ARRAY_SIZE : const int <i><br>
+</i>- sixNumbers : int*<br>- seventhNumber : int
+<br>- numberOf Draws : long</td>
+</tr>
+
+<tr>
+<td><i>Constructor</i>( )
+<br><i>Destructor</i>( )
+<br>+ drawAllNumbers( ) : void <br>
++ printAllNumbers( ) : void <br>
++ sortSixNumbers( ) : void
+<br>+ getAllNumbers( int* ) : int<br>+ getNumberOfDraws( ) : long</td>
+</tr>
+</table>
+</td>
+
+</tr>
+
+<td COLSPAN = "2" height="267" width="1151">
+<br>
+Besonderheiten der Methoden sind:
+<ul>
+<li>
+Der Konstruktor soll ein int-Array für die sechs Gewinnzahlen dynamisch
+erzeugen, das dann über das Attribut <b><font face="Courier New">sixNumbers</font></b>
+angesprochen wird. Dieses Array und die restlichen Attribute sollen sinnvoll
+initialisiert werden. Die Konstante <b><font face="Courier New">ARRAY_SIZE</font></b>
+gibt die Anzahl der Elemente des dynamischen int-Arrays an.</li>
+<li>
+Durch <b><font face="Courier New">drawAllNumbers</font></b> sollen sechs
+zufällig gezogene Zahlen im int-Array sixNumbers und eine siebte zufällige Zahl
+(die Zusatzzahl) im Attribut seventhNumber abgelegt werden. Es gelten die
+üblichen Lottoregeln: Die Zahlen sind aus dem Bereich 1 bis 49 und natürlich
+alle verschieden. (Die 'Superzahl' soll nicht berücksichtigt werden.)</li>
+<li>
+Im Attribut <b><font face="Courier New">numberOfDraws</font></b> soll über die
+Zahl der Ziehungen (d.h. die Zahl der Aufrufe von <b>
+<font face="Courier New">drawAllNumbers</font></b>) seit der Erzeugung eines <b>
+LottoGenerator</b>-Objekts Buch geführt werden.</li>
+
+<li>
+<b><font face="Courier New">printAllNumbers</font></b> soll die Nummer der
+Ziehung, die sechs gezogenen
+Zahlen und die Zusatzzahl in einer geeigneten Formatierung auf dem Bildschirm
+ausgeben.</li>
+
+<li>
+<b><font face="Courier New">sortSixNumbers</font></b> soll die sechs
+Gewinnzahlen im Array sixNumbers aufsteigend sortieren: Nach Aufruf von <b>
+<font face="Courier New">sortSixNumbers</font></b> steht die kleinste Zahl im
+ersten Platz des Arrays, die größte im sechsten. Sie können ein Sortierverfahren
+Ihrer Wahl benutzen. </li>
+
+<li>
+<b><font face="Courier New">getAllNumbers</font></b> soll alle sieben gezogenen
+Zahlen in das Anwendungsprogramm (main) für eine Weiterverarbeitung übergeben:
+Die Zusatzzahl als Rückgabewert und die sechs Gewinnzahlen in ein vom
+Anwendungsprogramm zur Verfügung gestelltes int-Array.</li>
+
+<li>
+Der Destruktor soll (neben seiner Hauptaufgabe!) <b><font face="Courier New">numberOfDraws</font></b> am Bildschirm
+ausgeben.<br>
+<br>
+<br>
+<br>
+ </li>
+ </ul>
+<p>Das <b>Anwendungsprogramm (<font face="Courier New">main</font>)</b> soll ein
+<font face="Courier New"> <b>LottoGenerator</b></font>-Objekt
+erzeugen und dann folgende Aktivitäten durchführen:
+<ul>
+<li>
+Durchführung von 10 Ziehungen und Ausgabe der Ziehungsergebnisse (einschließlich
+Zusatzzahl), wobei die sechs Gewinnzahlen aufsteigend sortiert sein sollen.
+</li>
+
+<li>
+Durchführung von einer Million Ziehungen und Ermitteln, wie oft eine einstellige
+Zusatzzahl auftrat.</li>
+
+<li>
+Führen Sie eine Million Ziehungen durch und übergeben Sie jeweils die sechs
+Gewinnzahlen an eine (globale) Funktion <b><font face="Courier New">average</font></b>.
+Diese Funktion soll den ganzzahligen (also auf- bzw. abgerundeten) Mittelwert
+der übergebenen Gewinnzahlen berechnen und zurückgeben. Für die zurückgegebenen
+Mittelwerte soll in <b><font face="Courier New">main</font></b> eine
+Häufigkeitsverteilung erstellt werden. Auf den Bildschirm auszugeben sind dann
+alle vorkommenden Mittelwerte zusammen mit ihrer Häufigkeit. (Die absoluten
+Zahlenwerte genügen, keine graphische Darstellung!)</li>
+</ul>
+<p> </p>
+<p> </p>
+<p> </p>
+<p> </p>
+<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="50%" id="AutoNumber1">
+ <tr>
+ <td width="33%"><b>Bewertung (Punkte):</b></td>
+ <td width="33%"><b>maximal</b></td>
+ <td width="34%"><b>erreicht</b></td>
+ </tr>
+ <tr>
+ <td width="33%">Klassendeklaration</td>
+ <td width="33%">12</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">Konstruktor</td>
+ <td width="33%">8</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">drawAllNumbers</td>
+ <td width="33%">12</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">printAllNumbers</td>
+ <td width="33%">8</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">sortSixNumbers</td>
+ <td width="33%">8</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">getAllNumbers</td>
+ <td width="33%">8</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">getNumberOfDraws</td>
+ <td width="33%">2</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">Destruktor</td>
+ <td width="33%">5</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">main</td>
+ <td width="33%">27</td>
+ <td width="34%"> </td>
+ </tr>
+ <tr>
+ <td width="33%">average</td>
+ <td width="33%">10</td>
+ <td width="34%"> </td>
+ </tr>
+ </table>
+<p><br>
+<b>Gesamtpunkte: </b></p>
+<p> </p>
+<p><b>Note:</b><br>
+ </p>
+ </td>
+
+</table>
+
+
+</body>
+</html>
\ No newline at end of file diff --git a/Bachelor/Prog1/PG1_inh.htm b/Bachelor/Prog1/PG1_inh.htm new file mode 100644 index 0000000..d24bc55 --- /dev/null +++ b/Bachelor/Prog1/PG1_inh.htm @@ -0,0 +1,120 @@ +<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="EXPIRATION_TIME" content="365">
+ <meta name="AUTHOR" content="h.p.weber@fbi.fh-darmstadt.de">
+ <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+ <meta name="Author" content="H.P.Weber">
+ <title>Programmieren I</title></head>
+
+<body>
+<p align="center">
+<font size="+1">Prof. Dr. Hans-Peter Weber : Programmieren I WS 04/05</font><br>
+</p><div align="center">
+ <center>
+<table border="1">
+<tbody><tr bgcolor="#efefde">
+
+<td><font size="+1">Vorlesung</font></td>
+
+<td><b>Praktikum</b></td>
+</tr>
+
+<tr>
+<td> </td>
+<td>
+</td>
+</tr>
+
+
+<tr bgcolor="#efefde">
+<td><h2>1 Einführung in die Programmierung mit C++</h2></td>
+<td><div align="right">1</div>
+</td></tr>
+
+<tr valign="top">
+<td>1a Einführung in Objekttechnologie und UML<br>
+</td>
+<td> </td>
+</tr>
+
+<tr bgcolor="#efefde">
+<td><h2>2 Kontrollstrukturen</h2></td>
+<td><div align="right">2</div>
+</td>
+</tr>
+
+<tr>
+<td>2a [Fallstudie] Identifizieren der Klassen in einer Problemstellung<br>
+</td>
+<td> </td>
+</tr>
+
+<tr bgcolor="#efefde">
+<td><h2>3 Funktionen</h2></td>
+<td><div align="right">3</div></td>
+</tr>
+
+<tr>
+<td>3a [Fallstudie] Identifizieren der Attribute einer Klasse<br>
+</td>
+<td> </td>
+</tr>
+
+<tr bgcolor="#efefde">
+<td><h2>4 Arrays</h2></td>
+<td><div align="right">4</div></td>
+
+</tr>
+
+<tr>
+<td>4a [Fallstudie] Identifizieren der Methoden einer Klasse<br>
+</td>
+<td> </td>
+</tr>
+
+<tr bgcolor="#efefde">
+<td><h2>5 Zeiger und Strings</h2></td>
+<td><div align="right">5</div></td>
+</tr>
+
+<tr>
+<td>5a [Fallstudie] Kollaborationen unter Objekten<br>
+</td>
+<td> </td>
+
+</tr>
+
+<tr bgcolor="#efefde">
+<td><h2>6 Klassen und Datenabstraktion</h2></td>
+<td><div align="right">6</div></td>
+</tr>
+
+<tr>
+<td>6a [Fallstudie] Beginn der Programmierung der Klassen für die Aufzug-Simulation<br>
+</td>
+<td> </td>
+</tr>
+
+<tr bgcolor="#efefde">
+<td><h2>7 Klassen: Teil II</h2></td>
+<td> </td>
+</tr>
+
+<tr>
+<td>7a [Fallstudie] Programmierung der Klassen für die Aufzug-Simulation<br>
+</td>
+<td> </td>
+</tr>
+
+<tr bgcolor="#efefde">
+<td><h2>8 Überladen von Operatoren<br>
+ </h2></td>
+<td> </td>
+</tr>
+
+</tbody></table>
+</center>
+</div>
+
+</body></html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp new file mode 100644 index 0000000..398c0e4 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.cpp @@ -0,0 +1,23 @@ +// Programmieren 1, Praktikum 1, Aufgabe 1
+// Sven Eisenhauer
+// 27.10.2004
+
+#include <iostream>
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int number = 7;
+
+ cout << number%2;
+ number = number/2;
+ cout << number%2;
+ number = number/2;
+ cout << number%2;
+ number = number/2;
+
+ cout << endl;
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp new file mode 100644 index 0000000..9a86bbf --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1pr1_1 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_1.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_1.mak" CFG="prg1pr1_1 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1pr1_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1pr1_1 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1pr1_1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1pr1_1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1pr1_1 - Win32 Release"
+# Name "prg1pr1_1 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1pr1_1.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsw new file mode 100644 index 0000000..0d797df --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_1/prg1pr1_1.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1pr1_1"=.\prg1pr1_1.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp new file mode 100644 index 0000000..b8467f1 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.cpp @@ -0,0 +1,22 @@ +// Programmieren 1, Praktikum 1, Aufgabe 2
+// Sven Eisenhauer
+// 27.10.2004
+
+#include <iostream.h>
+#include <stdlib.h>
+
+int main()
+{
+ cout << "Draußen brüllen Bären und Löwen!";
+
+ system( "cls" ); // clear screen
+
+ cout << "Drau\xe1\x65n br\x81llen B\x84ren und L\x94wen!";
+ //cout << "Drau\x00e1en br\x81llen B\x84ren und L\x94wen!";
+ cout << endl;
+
+ cout << "B\x8eREN UND L\x99WEN BR\x9aLLEN.";
+ cout << endl << endl;
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp new file mode 100644 index 0000000..ed33848 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1pr1_2 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_2.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_2.mak" CFG="prg1pr1_2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1pr1_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1pr1_2 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1pr1_2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1pr1_2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1pr1_2 - Win32 Release"
+# Name "prg1pr1_2 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1pr1_2.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsw new file mode 100644 index 0000000..6104bf5 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_2/prg1pr1_2.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1pr1_2"=.\prg1pr1_2.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp new file mode 100644 index 0000000..880b7b9 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.cpp @@ -0,0 +1,50 @@ +// Programmieren 1, Praktikum 1, Aufgabe 3
+// Sven Eisenhauer
+// 27.10.2004
+
+#include <iostream>
+
+int main()
+{
+ int iInOp1,iInOp2,iInOp3; // 3 operants, user input
+ int iMin,iMax;
+
+ std::cout << "Bitte drei unterschiedliche ganze Zahlen eingeben:\n";
+ std::cin >> iInOp1;
+ std::cin >> iInOp2;
+ std::cin >> iInOp3;
+ std::cout << "\nDie Summe ist " << iInOp1 + iInOp2 + iInOp3;
+ std::cout << "\nDer Mittelwert ist "<< (static_cast <double> (iInOp1 + iInOp2 + iInOp3))/3;
+ std::cout << "\nDas Produkt ist " << (iInOp1 * iInOp2 * iInOp3);
+
+ if (iInOp1<iInOp2 && iInOp1<iInOp3)
+ {
+ iMin=iInOp1;
+ }
+ if (iInOp2<iInOp1 && iInOp2<iInOp3)
+ {
+ iMin=iInOp2;
+ }
+ if (iInOp3<iInOp1 && iInOp3<iInOp2)
+ {
+ iMin=iInOp3;
+ }
+
+ if (iInOp1>iInOp2 && iInOp1>iInOp3)
+ {
+ iMax=iInOp1;
+ }
+ if (iInOp2>iInOp1 && iInOp2>iInOp1)
+ {
+ iMax=iInOp2;
+ }
+ if (iInOp3>iInOp1 && iInOp3>iInOp1)
+ {
+ iMax=iInOp3;
+ }
+
+ std::cout << "\nDer kleinste Wert ist "<<iMin;
+ std::cout << "\nDer groesste Wert ist "<<iMax<<"\n";
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsp new file mode 100644 index 0000000..0422643 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p1_3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p1_3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_3.mak" CFG="prg1p1_3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p1_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p1_3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p1_3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p1_3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p1_3 - Win32 Release"
+# Name "prg1p1_3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1pr1_3.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsw new file mode 100644 index 0000000..59d5b79 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_3/prg1pr1_3.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p1_3"=.\prg1p1_3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp new file mode 100644 index 0000000..8536977 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.cpp @@ -0,0 +1,40 @@ +// Programmieren 1, Praktikum 1, Aufgabe 4
+// Sven Eisenhauer
+// 27.10.2004
+
+#include <iostream>
+//#include <math.h>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+int main ()
+{
+ // const iDigits=6; // number of digits entered
+ int iZahl; // user input
+ // int iCounter=iDigits-1; // use digits from iDigits-1 to 0 of iZahl
+
+ // cout << "Bitte eine "<<iDigits<<"-stellige ganze Zahl eingeben: ";
+ cout << "Bitte eine fuenfstellige ganze Zahl eingeben: ";
+ cin >> iZahl;
+
+ /* for (iCounter;iCounter>=0;iCounter--)
+ {
+ cout << static_cast <int> (iZahl / pow(10,iCounter)) << "\n";
+ iZahl=iZahl%static_cast <int> (pow(10,iCounter));
+ }
+ */
+
+ cout << iZahl/10000 << endl;
+ iZahl=iZahl%10000;
+ cout << iZahl/1000 << endl;
+ iZahl=iZahl%1000;
+ cout << iZahl/100 << endl;
+ iZahl=iZahl%100;
+ cout << iZahl/10 << endl;
+ iZahl=iZahl%10;
+ cout << iZahl << endl;
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp new file mode 100644 index 0000000..decf90b --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_4" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1pr1_4 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_4.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_4.mak" CFG="prg1pr1_4 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1pr1_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1pr1_4 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1pr1_4 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1pr1_4 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1pr1_4 - Win32 Release"
+# Name "prg1pr1_4 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1pr1_4.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsw new file mode 100644 index 0000000..d1654c2 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_4/prg1pr1_4.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1pr1_4"=.\prg1pr1_4.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp new file mode 100644 index 0000000..e17a0bc --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.cpp @@ -0,0 +1,25 @@ +// Programmieren 1, Praktikum 1, Aufgabe 5
+// Sven Eisenhauer
+// 27.10.2004
+
+#include <iostream>
+
+int main ()
+{
+ char cInput;
+
+ do
+ {
+ system( "cls" );
+ std::cout << "Bitte ein Zeichen eingeben: ";
+ std::cin >> cInput;
+ std::cout << "ASCII Code der Eingabe: "<< static_cast< int >(cInput) << "\n";
+ std::cout << "Hex ASCII Code der Eingabe: "<< std::hex << static_cast< int >(cInput) << "\n";
+ std::cout << "\nWeiter mit beliebiger Taste, Abbruch mit \"0\"\n";
+ std::cin >> cInput;
+
+ }
+ while (cInput != 0x30);
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp new file mode 100644 index 0000000..820b122 --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1pr1_5" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1pr1_5 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_5.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1pr1_5.mak" CFG="prg1pr1_5 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1pr1_5 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1pr1_5 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1pr1_5 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1pr1_5 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1pr1_5 - Win32 Release"
+# Name "prg1pr1_5 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1pr1_5.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsw b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsw new file mode 100644 index 0000000..ca1dd2a --- /dev/null +++ b/Bachelor/Prog1/Prakt1/prg1pr1_5/prg1pr1_5.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1pr1_5"=.\prg1pr1_5.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt2/index.htm b/Bachelor/Prog1/Prakt2/index.htm new file mode 100644 index 0000000..872f2ac --- /dev/null +++ b/Bachelor/Prog1/Prakt2/index.htm @@ -0,0 +1,156 @@ +<html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<title>Praktikum 2</title></head>
+
+<body>
+
+
+<table border="1" cellspacing="0" width="100%">
+<caption> </caption>
+
+<tbody><tr>
+<td bgcolor="#efefde" width="25%">FH Darmstadt
+<br>FB Informatik
+<br>Prof.Dr. H.P.Weber</td>
+
+<td>
+<center><font size="+3">Programmieren I </font>
+<br><font size="+3">Praktikum</font></center>
+</td>
+
+<td bgcolor="#efefde" width="25%">
+<center><font size="+4">2</font></center>
+</td>
+</tr>
+</tbody></table>
+
+<br>
+<table border="1" width="100%">
+<tbody><tr valign="top">
+<td>Ziel:</td><td>
+Sie sollen einfache und komplexere Kontrollstrukturen üben.
+</td>
+</tr>
+</tbody></table>
+<br>
+
+<table border="1" width="100%">
+<tbody><tr>
+<td><b><font size="+1">1 Einfaches Histogramm erstellen</font></b>
+
+<ul>
+<li>
+Schreiben Sie ein Programm, das fünf Zahlen (jede zwischen 1 und 80) von der
+ Konsole einliest. Für jede eingegebene Zahl soll Ihr Programm eine Zeile mit
+ entsprechend vielen aneinander hängenden Sternchen (*) ausgeben. Zum Beispiel
+ soll für eine eingegebene Zahl 7 folgende Zeile ausgegeben werden:<br>
+ <br>*******</li>
+
+</ul>
+
+</td>
+
+</tr>
+</tbody></table>
+
+
+<table border="1" width="100%">
+<tbody><tr>
+<td><b><font size="+1">2 Binär-Dezimalwandlung</font></b>
+<ul>
+<li>
+Schreiben Sie ein Programm, das eine binäre Zahl (also eine
+ganze Zahl, die als Ziffern nur 0 oder 1 enthält) einliest und ihr dezimales
+Äquivalent ausgibt. Die eingegebene binäre Zahl soll maximal 10-stellig
+sein.</li>
+<li>
+Hinweis: Nutzen Sie modulo- und Divisionsoperator, um die binären Ziffern eine
+nach der anderen von rechts nach links abzuspalten. Bauen Sie aus den binären
+Ziffern zusammen mit ihrer jeweiligen Wertigkeit die dezimale Zahl auf</li>
+
+<li>
+Realisieren Sie auch die umgekehrte Operation: Das Programm soll eine
+eingegebene Dezimalzahl in ihre binäre Darstellung umwandeln. </li>
+
+</ul>
+</td>
+
+</tr>
+</tbody></table>
+
+
+<table border="1" width="100%">
+<tbody><tr>
+<td><b><font size="+1">3 Ganzzahlige rechtwinklige Dreiecke</font></b>
+<ul>
+<li>
+Es gibt rechtwinklige Dreiecke (d.h. Dreiecke für die der Satz des Pythagoras
+gilt), deren Seitenlängen alle ganze Zahlen sind. </li>
+<li>
+Schreiben Sie ein Programm, das alle diese Dreiecke in Form der Längen ihrer
+drei Seiten findet. Hierbei sollen nur Seitenlängen, die nicht größer als 500
+sind, berücksichtigt werden. Geben Sie zusätzlich die Anzahl der gefundenen
+Dreiecke aus.</li>
+
+<li>
+Hinweis: Nutzen Sie eine dreifach geschachtelte for-Schleife, die alle
+Möglichkeiten ausprobiert. Diese Vorgehensweise ist ein Beispiel für eine
+sogenannte "Brute Force"-Methode.</li>
+
+</ul>
+</td>
+
+</tr>
+</tbody></table>
+
+<table border="1" width="100%">
+<tbody><tr>
+<td><b><font size="+1">4 Primzahlen</font></b><ul>
+<li>
+Schreiben Sie ein Programm, das eine positive ganze Zahl von der Tastatur
+einliest und alle Primzahlen, die kleiner als diese Zahl sind, ausgibt.
+
+</li></ul>
+</td>
+
+</tr>
+</tbody></table>
+
+<table border="1" width="100%">
+<tbody><tr>
+<td><b><font size="+1">5 Primzahlzwillinge (fakultativ)</font></b>
+
+<ul>
+<li>
+Schreiben Sie ein Programm, das zwei positive ganze Zahlen von der Tastatur
+einliest und alle Primzahlzwillinge, die zwischen diesen beiden Zahlen liegen, ausgibt.
+</li><li>
+Als Primzahlzwillinge bezeichnet man zwei Primzahlen, die 'direkt' benachbart
+sind, also nur durch die zwischen ihnen liegende gerade Zahl getrennt sind.
+Beispiele sind 3 und 5 oder 17 und 19.
+
+</li></ul>
+</td>
+
+</tr>
+</tbody></table>
+
+<table border="1" width="100%">
+<tbody><tr>
+<td><font size="+1"><b>6</b></font><b><font size="+1"> Binär-,
+Oktal- und Hexadezimaldarstellung (fakultativ)</font></b>
+
+<ul>
+<li>
+Schreiben Sie ein Programm, das eine Tabelle der binären, oktalen und
+hexadezimalen Darstellung der ganzen Dezimalzahlen von 1 bis 256 ausgibt.
+
+</li></ul>
+</td>
+
+</tr>
+</tbody></table>
+
+</body></html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp new file mode 100644 index 0000000..98036aa --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.cpp @@ -0,0 +1,77 @@ +// Programmieren 1, Praktikum 2, Aufgabe 1
+// Sven Eisenhauer
+// 29.10.2004
+//
+// file: prg1p2_1.cpp
+//
+// purpose: program to read 5 integer numbers (between 1 and 80) from keyboard and for each
+// number to draw the amount of "*"-characters in one line on the screen.
+//
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int iNumber1,iNumber2,iNumber3,iNumber4,iNumber5;
+
+ cout << "Please enter number 1: ";
+ cin >> iNumber1;
+ cout << "Please enter number 2: ";
+ cin >> iNumber2;
+ cout << "Please enter number 3: ";
+ cin >> iNumber3;
+ cout << "Please enter number 4: ";
+ cin >> iNumber4;
+ cout << "Please enter number 5: ";
+ cin >> iNumber5;
+
+ for (int iCounter=1;iCounter<=iNumber1;iCounter++)
+ cout << "*";
+ cout << endl;
+ for (iCounter=1;iCounter<=iNumber2;iCounter++)
+ cout << "*";
+ cout << endl;
+ for (iCounter=1;iCounter<=iNumber3;iCounter++)
+ cout << "*";
+ cout << endl;
+ for (iCounter=1;iCounter<=iNumber4;iCounter++)
+ cout << "*";
+ cout << endl;
+ for (iCounter=1;iCounter<=iNumber5;iCounter++)
+ cout << "*";
+ cout << endl;
+/*
+
+ int iInput[5];
+
+ //input repitition
+ for (int iCounter=1;iCounter<=5;iCounter++)
+ {
+ cout << "Please enter " << iCounter << ". number (between 1 and 80): ";
+ cin >> iInput[iCounter-1];
+
+ // check input
+ while (iInput[iCounter-1]<1 || iInput[iCounter-1]>80)
+ {
+ cout<<"\nNumber not between 1 and 80, please enter a new one: ";
+ cin >> iInput[iCounter-1];
+ }// end while
+
+
+ }// end for input repitition
+
+ //output repition
+ for (iCounter=1;iCounter<=5;iCounter++)
+ {
+ // draw star characters
+ for (int iStarCounter=1;iStarCounter<=iInput[iCounter-1];iStarCounter++)
+ cout <<"*";
+
+ // new line for next number
+ cout << endl;
+ }// end output
+*/
+ return 0; // everything ok
+}// end main
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp new file mode 100644 index 0000000..bf231f2 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p2_1 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_1.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_1.mak" CFG="prg1p2_1 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p2_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p2_1 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p2_1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p2_1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p2_1 - Win32 Release"
+# Name "prg1p2_1 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1p2_1.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsw b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsw new file mode 100644 index 0000000..9a01f06 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_1/prg1p2_1.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p2_1"=.\prg1p2_1.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp new file mode 100644 index 0000000..1ac93e1 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.cpp @@ -0,0 +1,86 @@ +// Programmieren 1, Praktikum 2, Aufgabe 2
+// Sven Eisenhauer
+// 29.10.2004
+//
+// file: prg1p2_2.cpp
+//
+// purpose: convert bin to dec numbers or dec numbers to bin
+// 10 digits mean 2exp9 to 2exp0
+//
+#include <iostream>
+#include <cmath>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int main()
+{
+ const iBit=10; //define how large the binary output should be.
+
+ int iMode;
+ int iBin=0;
+ int iActualFactor=0;
+ int iDec=0;
+ int iCounter=0;
+ int iCounter2=0;
+ //int iBinOut[iBit];
+ int iBinOut=0;
+
+
+ do
+ {
+ system("cls");
+ cout << "Please select Converter:\n1) Bin -> Dec\n2) Dec -> Bin\n\n0) End\n\n"
+ "Your selection: ";
+ cin >> iMode;
+ switch (iMode) {
+ case 1:
+ cout << "\nPlease enter a binary number (max 10 characters): ";
+ cin >> iBin;
+ for (iCounter = 9;iCounter>=0;iCounter--)
+ {
+ iActualFactor=iBin/pow(10,iCounter);
+ iDec+=(iActualFactor * static_cast <int> (pow(2,iCounter)));
+ iBin=iBin%static_cast <int>(pow(10,iCounter));
+ }
+ cout << "\nDecimal: " << iDec;
+ cout << endl;
+ system ("pause");
+ break; // end bin2dec
+ case 2://dec2bin
+ cout << "\nPlease enter a decimal number: ";
+ cin >> iDec;
+ cout << "\n"<<iBit<<"-bit Integer is: ";
+ /* // fill the array
+ for (iCounter=iBit-1;iCounter>=0;iCounter--)
+ {
+ iBinOut[iCounter]=iDec%2;
+ iDec=iDec/2;
+ }
+ // print array in reverse order
+ for (iCounter=0;iCounter<=iBit-1;iCounter++)
+ {
+ cout << iBinOut[iCounter];
+ if (0==((iCounter+1)%4)) // space separator after 4 bit
+ cout <<" ";
+ }
+ */
+ iBinOut=0;
+ for (iCounter2=iBit;iCounter2>=0;iCounter2--)
+ {
+ iBin=iDec%2;
+ iDec=iDec/2;
+ iBinOut += iBin * static_cast <int> (pow(10,iBit-iCounter2));
+ }
+ cout << iBinOut << endl;
+ system ("pause");
+ break; // end dec2bin
+ case 0: // end selected... we are leaving...
+ break;
+ default: // wrong selection
+ cout << "\n !! No functon selected !!";
+ } // end switch
+ } // end while
+ while (iMode != 0);
+ return 0; // so far, we are ok
+}// end main
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp new file mode 100644 index 0000000..63ba0bc --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p2_2 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_2.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_2.mak" CFG="prg1p2_2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p2_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p2_2 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p2_2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p2_2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p2_2 - Win32 Release"
+# Name "prg1p2_2 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1p2_2.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsw b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsw new file mode 100644 index 0000000..8fa2314 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_2/prg1p2_2.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p2_2"=.\prg1p2_2.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp new file mode 100644 index 0000000..259648e --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.cpp @@ -0,0 +1,31 @@ +// Programmieren 1, Praktikum 2, Aufgabe 3
+// Sven Eisenhauer
+// 29.10.2004
+//
+// file: prg1p2_3.cpp
+//
+// purpose: find triangles, which fit a*a + b*b = c*c, for integer a,b,c < 500
+//
+//
+#include <iostream>
+#include <iomanip>
+
+using std::cin;
+using std::cout;
+using std::endl;
+using std::setw;
+
+int main()
+{
+ int a,b,c=1;
+
+ cout <<setw(4)<<"A"<<setw(4)<<"B"<<setw(4)<<"C";
+
+ for (a=1;a<500;a++)
+ for (b=1;b<500;b++)
+ for (c=1;c<500;c++)
+ if ((a*a)+(b*b)==(c*c))
+ cout <<setw(4)<<a<<setw(4)<<b<<setw(4)<<c<<endl;
+
+ return 0; // so far, we are ok
+}// end main
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsp b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsp new file mode 100644 index 0000000..5fc793c --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p2_3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_3.mak" CFG="prg1p2_3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p2_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p2_3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p2_3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p2_3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p2_3 - Win32 Release"
+# Name "prg1p2_3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1p2_3.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsw b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsw new file mode 100644 index 0000000..6045ba4 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_3/prg1p2_3.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p2_3"=.\prg1p2_3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp new file mode 100644 index 0000000..b649a6a --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.cpp @@ -0,0 +1,51 @@ +// Programmieren 1, Praktikum 2, Aufgabe 4
+// Sven Eisenhauer
+// 05.11.2004
+//
+// file: prg1p2_4.cpp
+//
+// purpose: Program to find all prime numbers, which are smaller than the entered positive number
+//
+
+#include <iostream>
+#include <iomanip>
+
+using std::cin;
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int iNumber=0;
+ int iIsPrime=0;
+
+ system ("cls");
+ cout << "Please enter a positive number: ";
+ cin >> iNumber;
+ if (0 >= iNumber) // handle wrong input in some way
+ {
+ cout << "Not a positive number!!!";
+ system ("pause");
+ }
+ else // end error handler
+ { // let's begin
+ for (int iOuterCounter=iNumber;iOuterCounter>1;iOuterCounter--)
+ { // decrement the number and check, if it is a prime (modulo any number is 0)
+ iIsPrime=0; // we asume actual number is a prime
+ for (int iInnerCounter=iOuterCounter-1;iInnerCounter>1;iInnerCounter--)
+ {
+ if ( 0 == iOuterCounter%iInnerCounter)
+ {
+ iIsPrime=1; // actual number is NOT a prime
+ }
+ }// end inner for routine
+ if (0 == iIsPrime)
+ cout << endl << iOuterCounter;
+
+ } // end outer for routine
+ cout << endl;
+ system ("pause"); // wait a moment for user to read
+
+ } // end else
+ return 0;
+}// end main
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp new file mode 100644 index 0000000..b3ac1d9 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_4" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p2_4 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_4.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_4.mak" CFG="prg1p2_4 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p2_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p2_4 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p2_4 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p2_4 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p2_4 - Win32 Release"
+# Name "prg1p2_4 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1p2_4.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsw b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsw new file mode 100644 index 0000000..1d4963a --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_4/prg1p2_4.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p2_4"=.\prg1p2_4.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp new file mode 100644 index 0000000..0691d20 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.cpp @@ -0,0 +1,73 @@ +// Programmieren 1, Praktikum 2, Aufgabe 5
+// Sven Eisenhauer
+// 06.11.2004
+//
+// file: prg1p2_5.cpp
+//
+// purpose: program to reads 2 integers from keyboard and finds all prime number twins
+// between them, like 3 and 5 or 17 and 19
+//
+
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int iNumberA, iNumberB;
+ int iMin, iMax;
+ int iIsPrime1=0;
+ int iIsPrime2=0;
+ int iPrime1=0;
+ int iPrime2=0;
+ int iToTest=0;
+
+ cout << "Please enter 1st number: ";
+ cin >> iNumberA;
+ cout << "Please enter 2nd number: ";
+ cin >> iNumberB;
+ cout << endl;
+
+ // first find out, which is the bigger value.
+ iMax=iNumberA;
+ iMin=iNumberB;
+
+ if (iNumberB > iNumberA)
+ {
+ iMax=iNumberB;
+ iMin=iNumberA;
+ }
+ // First loop: Get all numbers between the 2 entered
+ for (int iOuterCounter=iMax-1;iOuterCounter>iMin;iOuterCounter--)
+ {
+ iIsPrime1=0;
+ for (int iInnerCounter=iOuterCounter-1;iInnerCounter>1;iInnerCounter--)
+ {
+ if ( 0 == iOuterCounter%iInnerCounter)
+ iIsPrime1=1; // actual number is NOT a prime
+ }// end inner for routine
+ if (0 == iIsPrime1)
+ {
+ iPrime1=iOuterCounter;
+ // now test, if iPrime1 - 2 is a prime
+ iIsPrime2 = 0;
+ iToTest = iOuterCounter - 2;
+ for (int iInnerCounter2=iToTest-1;iInnerCounter2>1;iInnerCounter2--)
+ {
+ if (0 == iToTest%iInnerCounter2)
+ iIsPrime2=1;
+ }
+ if (0 == iIsPrime2)
+ iPrime2=iToTest;
+
+ if ((0 == iIsPrime1) && (0 == iIsPrime2) && (iPrime2 > iMin))
+ cout << iPrime1 << "\t" << iPrime2 << endl;
+ }
+ // if (iIsPrime1 && iIsPrime2)
+ // cout << iPrime1 << "\t" << iPrime2 << endl;
+ }
+// system ("pause");
+
+ return 0;
+}// end main
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp new file mode 100644 index 0000000..7ad88a6 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_5" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p2_5 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_5.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_5.mak" CFG="prg1p2_5 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p2_5 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p2_5 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p2_5 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p2_5 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p2_5 - Win32 Release"
+# Name "prg1p2_5 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1p2_5.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsw b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsw new file mode 100644 index 0000000..d819093 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_5/prg1p2_5.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p2_5"=.\prg1p2_5.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp new file mode 100644 index 0000000..70abc04 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp @@ -0,0 +1,59 @@ +// Programmieren 1, Praktikum 2, Aufgabe 6
+// Sven Eisenhauer
+// 06.11.2004
+//
+// file: prg1p2_6.cpp
+//
+// purpose: generate a table of bin, oct and hex presentation of the numbers from 1 to 256
+//
+//
+
+#include <iostream>
+#include <iomanip>
+#include <cmath>
+
+using std::cin;
+using std::cout;
+using std::endl;
+using std::setw;
+using std::hex;
+using std::dec;
+
+const int iBit=8; // 256 is 8 bit
+
+int iDec,iOct,iHex,iBin,iTemp;
+
+int main()
+{
+ cout << setw(5) << "Dec" << setw (11) << "Binary" << setw(7) << "Octal" << setw(5) << "Hex" << endl;
+
+ for (int iCounter=1;iCounter<=256;iCounter++)
+ {
+ iDec=iCounter;
+ iTemp=0;
+ iBin=0;
+ iOct=0;
+ // generate binary
+ for (int iBinC=iBit;iBinC>=0;iBinC--)
+ {
+ iTemp = iDec % 2;
+ iDec = iDec / 2;
+ iBin += iTemp * static_cast <int> (pow(10,iBit-iBinC));
+
+ }
+ // generate octal
+ iDec=iCounter;
+ for ( int iOctC=3;iOctC>=0;iOctC--)
+ {
+ iTemp = iDec % 8;
+ iDec = iDec / 8;
+ iOct += iTemp * static_cast <int> (pow(10,3-iOctC));
+ }
+ cout << setw(5) << dec << iCounter << setw (11) << iBin << setw(7) << iOct << setw(5) << hex << iCounter << endl;
+ if (!(iCounter%23))
+ cout << endl << setw(5) << "Dec" << setw (11) << "Binary" << setw(7) << "Octal" << setw(5) << "Hex" << endl;
+ }
+
+
+ return 0;
+}// end main
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp new file mode 100644 index 0000000..5958ba3 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p2_6" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p2_6 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_6.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p2_6.mak" CFG="prg1p2_6 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p2_6 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p2_6 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p2_6 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p2_6 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p2_6 - Win32 Release"
+# Name "prg1p2_6 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\prg1p2_6.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsw b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsw new file mode 100644 index 0000000..6de9111 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p2_6"=.\prg1p2_6.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt3/index.htm b/Bachelor/Prog1/Prakt3/index.htm new file mode 100644 index 0000000..367abf1 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/index.htm @@ -0,0 +1,197 @@ +<html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<title>Praktikum 3</title></head>
+
+<body>
+
+
+<table border="1" cellspacing="0" width="100%">
+<caption> </caption>
+
+<tbody><tr>
+<td bgcolor="#efefde" width="25%">FH Darmstadt
+<br>FB Informatik
+<br>Prof.Dr. H.P.Weber</td>
+
+<td>
+<center><font size="+3">Programmieren I </font>
+<br><font size="+3">Praktikum</font></center>
+</td>
+
+<td bgcolor="#efefde" width="25%">
+<center><font size="+4">3</font></center>
+</td>
+</tr>
+</tbody></table>
+
+<br>
+<table border="1" width="100%">
+<tbody><tr valign="top">
+<td>Ziel:</td><td> Sie sollen den modularen Programmaufbau mit
+Funktionen, die Simulation von Zufallsereignissen und einfache
+Rekursion üben.
+</td>
+</tr>
+</tbody></table>
+
+<br>
+<table border="1" cellspacing="0" width="100%">
+<tbody><tr>
+<td>
+<h3>
+<b>1 Verwenden einer einfachen Funktion</b></h3>
+
+<ul>
+<li>
+Schreiben Sie eine Funktion, die die Uhrzeit als drei <b>
+<font face="Courier New">integer</font></b>-Argumente übernimmt (<b><font face="Courier New">hour</font></b>,
+<b><font face="Courier New">minute</font></b>, <b><font face="Courier New">
+second</font></b>) und die Anzahl der Sekunden seit 0 Uhr zurückgibt.</li>
+
+<li>
+Benutzen Sie diese Funktion, um die Zeitspanne in Sekunden zwischen zwei
+Zeitpunkten (am gleichen Tag) zu berechnen.</li>
+</ul>
+</td>
+</tr>
+</tbody></table>
+
+<br>
+<table border="1" cellspacing="0" width="100%">
+<tbody><tr>
+<td>
+<h3>
+<b>2 Einfache Simulation und Analyse von Zufallsereignissen</b></h3>
+
+<ul>
+<li>
+Schreiben Sie ein Programm, das simuliert, zwei Würfel 6000mal
+zu werfen. </li>
+
+<li>
+Ergänzen Sie die Simulation um eine Häufigkeitstabelle, die angibt,
+wie oft die möglichen Augenzahlen eines Wurfes (2 bis 12) gefallen sind. </li>
+</ul>
+</td>
+</tr>
+</tbody></table>
+
+<br>
+
+<table border="1" cellspacing="0" width="100%">
+<tbody><tr>
+<td>
+<h3>
+<b>3 Vollkommene Zahlen </b></h3>
+
+<ul>
+<li>
+Eine ganze Zahl wird eine <i>vollkommene Zahl</i> genannt, falls die Summe ihrer
+Faktoren (also der Zahlen, durch die die Zahl ohne Rest teilbar ist) gleich der Zahl selbst
+ist. Bei der Bildung der Summe wird die 1 eingeschlossen, aber nicht die Zahl
+selbst. Zum Beispiel ist 6 eine vollkommene Zahl, denn es gilt 6 = 1 + 2 + 3.</li>
+
+<li>
+Schreiben Sie eine Funktion <b><font face="Courier New">isPerfect</font></b>,
+die bestimmt, ob ihr Parameter <b><font face="Courier New">number</font></b> eine
+vollkommene Zahl ist.</li>
+
+<li>
+Benutzen Sie diese Funktion in einem Programm, das alle vollkommenen Zahlen
+zwischen 1 und 1000 bestimmt und ausgibt. Geben Sie die Faktoren jeder
+vollkommenen Zahl mit aus, damit Ihr Ergebnis besser überprüft werden kann.</li>
+
+<li>
+Fordern Sie die Rechenleistung Ihres Computers, indem Sie Zahlen testen, die
+deutlich größer als 1000 sind. </li>
+</ul>
+</td>
+</tr>
+</tbody></table>
+
+
+
+<br>
+<table border="1" cellspacing="0" width="100%">
+<tbody><tr>
+<td>
+ <b><h3>4 Größter gemeinsamer Teiler - rekursiv</h3></b>
+
+<ul>
+<li>
+Der größte gemeinsame Teiler (greatest common divisor: gcd) zweier ganzer Zahlen
+x und y ist die größte ganze Zahl, die x und y ohne Rest teilt.</li>
+
+<li>
+Schreiben Sie eine rekursive Funktion <b> <font face="Courier New">gcd</font></b><font face="Times New Roman">,
+die </font>den größten gemeinsamen Teiler von x und y zurückgibt. Nutzen Sie
+dabei folgende rekursive Beziehung:</li>
+
+<li>
+Falls y gleich 0 ist, dann ist <b> <font face="Courier New">gcd(x,y)</font></b>
+gleich <b> <font face="Courier New">x</font></b>.<br>
+Sonst gilt: <b> <font face="Courier New">gcd(x,y)</font></b> ist <b> <font face="Courier New">
+gcd(y,x%y)</font></b>.</li>
+
+<li>
+Testen Sie Ihre Funktion, indem Sie Werte für x und y einlesen und den
+zugehörigen größten gemeinsamen Teiler ausgeben.</li>
+
+</ul>
+</td>
+</tr>
+</tbody></table>
+
+<br>
+<table border="1" cellspacing="0" width="100%">
+<tbody><tr>
+<td>
+ <b><h3>5 Ägyptische Multiplikation (fakultativ)</h3></b>
+
+<ul>
+<li>
+Schreiben Sie eine Funktion <font face="Courier New"><b>multIterative</b></font>,
+die das Produkt zweier ganzer Zahlen a und b auf folgende Weise berechnet.<br>
+Ausgehend von den der Funktion übergebenen Werten a und b wird eine
+Reihe von gleichartigen Schritten durchgeführt:
+<ul>
+<li>
+Falls b ungeradzahlig ist, wird der Wert von a zur Variablen
+<font face="Courier New"><b>product</b></font>
+addiert.
+</li>
+<li>
+Danach wird der Wert von
+a verdoppelt und der Wert von b halbiert (ohne Rest und
+ohne Rundung).
+</li>
+</ul>
+Diese beiden Schritte werden solange wiederholt, bis b durch die fortlaufende Halbierung den Wert 0
+annimmt. Die in <font face="Courier New"><b>product</b></font> gebildete Summe
+ist dann gleich dem Produkt von a
+und b. </li>
+
+<li>
+Hinweis: Realisieren Sie die Verdoppelung von a durch den Operator zur bitweisen
+Linksverschiebung <b><font face="Courier New"><<</font></b> und die Halbierung von b ohne Rest und Rundung durch
+den Operator zur bitweisen Rechtsverschiebung <b><font face="Courier New">>></font></b>. </li>
+
+<li>
+Schreiben Sie ein Programm, das zwei ganze Zahlen von der Tastatur einliest und
+das mit der Funktion <font face="Courier New"><b>multIterative</b></font>
+berechnete Produkt ausgibt. </li>
+
+<li>
+Schreiben Sie eine zweite Funktion <font face="Courier New"><b>multRecursive</b></font>,
+die die oben beschriebene Verdopplung, Halbierung und Summation durch rekursive
+Aufrufe von sich selbst realisiert. Testen Sie auch diese Funktion mit von der
+Tastatur eingegebenen Werten. </li>
+
+</ul>
+</td>
+</tr>
+</tbody></table>
+
+</body></html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp new file mode 100644 index 0000000..9c84841 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp @@ -0,0 +1,65 @@ +// Programmieren 1, Praktikum 3, Aufgabe 1
+// Sven Eisenhauer
+// 12.11.2004
+//
+// file: main.cpp
+//
+// purpose: read 2 times (hours, minutes, seconds) from keyboard
+// calculate seconds between this two times
+// uses a function to convert times to seconds
+//
+//
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int seconds(int, int, int);
+
+int main()
+{
+ int hours1,
+ minutes1,
+ seconds1,
+ totalSeconds1,
+ hours2,
+ minutes2,
+ seconds2,
+ totalSeconds2;
+
+ // read times from keyboard
+ cout << "Please enter 1st hours (0-24): ";
+ cin >> hours1;
+ cout << "Please enter 1st minutes (0-60): ";
+ cin >> minutes1;
+ cout << "Please enter 1st seconds (0-60): ";
+ cin >> seconds1;
+
+ cout << "Please enter 2nd hours (0-24): ";
+ cin >> hours2;
+ cout << "Please enter 2nd minutes (0-60): ";
+ cin >> minutes2;
+ cout << "Please enter 2nd seconds (0-60): ";
+ cin >> seconds2;
+
+ // convert to seconds
+ totalSeconds1=seconds(hours1,minutes1,seconds1);
+ totalSeconds2=seconds(hours2,minutes2,seconds2);
+
+ cout << endl << "Difference in seconds is: ";
+ // which is the bigger value and substract the lower one
+ if (totalSeconds1 > totalSeconds2)
+ cout << totalSeconds1 - totalSeconds2;
+ else
+ cout << totalSeconds2 - totalSeconds1;
+
+ cout << endl;
+
+ return 0;
+}// end main
+
+// function seconds
+int seconds (int h, int min, int sec)
+{
+ return h*3600+min*60+sec;
+} // end function seconds
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp new file mode 100644 index 0000000..fc5a7cf --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p3_1 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_1.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_1.mak" CFG="prg1p3_1 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p3_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p3_1 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p3_1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p3_1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p3_1 - Win32 Release"
+# Name "prg1p3_1 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsw b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsw new file mode 100644 index 0000000..4d304d8 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_1/prg1p3_1.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p3_1"=.\prg1p3_1.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp new file mode 100644 index 0000000..35796d5 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp @@ -0,0 +1,81 @@ +// Programmieren 1, Praktikum 3, Aufgabe 2
+// Sven Eisenhauer
+// 12.11.2004
+//
+// file: main.cpp
+//
+// purpose: roll 2 dice 6000 times and build a table, how often each possible sum occured
+//
+//
+//
+//
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+#include <ctime>
+#include <cstdlib>
+
+int rollDice(void);
+
+int main ()
+{
+ int stats[13] = {0};
+
+ srand(time(0));
+
+ for (int Counter=0;Counter <= 6000;Counter++)
+ {
+ /* switch (rollDice())
+ {
+ case 2:
+ stats[0]++;
+ break;
+ case 3:
+ stats[1]++;
+ break;
+ case 4:
+ stats[2]++;
+ break;
+ case 5:
+ stats[3]++;
+ break;
+ case 6:
+ stats[4]++;
+ break;
+ case 7:
+ stats[5]++;
+ break;
+ case 8:
+ stats[6]++;
+ break;
+ case 9:
+ stats[7]++;
+ break;
+ case 10:
+ stats[8]++;
+ break;
+ case 11:
+ stats[9]++;
+ break;
+ case 12:
+ stats[10]++;
+ break;
+ default:
+ cout << "Uuups... we should never get here...";
+ }*/
+ ++stats[rollDice()];
+ }
+ for (int i=2;i<=12;i++)
+ {
+ cout << endl << i << ": " << stats[i];
+ }
+ cout << endl;
+ return 0;
+}
+
+int rollDice(void)
+{
+ return (( 1 + (rand() % 6)) + ( 1 + (rand() % 6)));
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp new file mode 100644 index 0000000..2d4b338 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p3_2 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_2.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_2.mak" CFG="prg1p3_2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p3_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p3_2 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p3_2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p3_2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p3_2 - Win32 Release"
+# Name "prg1p3_2 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsw b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsw new file mode 100644 index 0000000..332d7bf --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_2/prg1p3_2.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p3_2"=.\prg1p3_2.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp new file mode 100644 index 0000000..c0c9cfc --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_3/main.cpp @@ -0,0 +1,57 @@ +// Programmieren 1, Praktikum 3, Aufgabe 3
+// Sven Eisenhauer
+// 17.11.2004
+//
+// file: main.cpp
+//
+// purpose: find "perfect numbers": The sum of all integer factors of a number is the number.
+//
+//
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int isPerfect(int);
+
+int main()
+{
+ // how far to search
+ const int maxNumbers=1000;
+
+ for (int j=1;j<=maxNumbers;j++)
+ {
+ if (0 == isPerfect(j))
+ {
+ cout << ": " << j << endl;
+ }
+ }
+
+ cout << "\n";
+
+ return 0;
+}
+
+int isPerfect(int number)
+{
+ int sum=0;
+ // check for all numbers between the number, exclusive the number itself and 1 inclusive
+ for (int i=number-1;i>=1;i--)
+ {
+ // is the actual number a factor???
+ if (0 == number%i)
+ // if it is, add it
+ sum+=i;
+ }
+ // the sum of all factors... and so on
+ if (sum == number)
+ {
+ // so we have a perfect number here... fine... find the factors again and cout them
+ for (int k=number-1;k>=1;k--)
+ if (0 == number%k)
+ cout << k << " ";
+ return 0;
+ }
+ else
+ return 1;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp new file mode 100644 index 0000000..0a8d693 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p3_3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_3.mak" CFG="prg1p3_3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p3_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p3_3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p3_3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p3_3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p3_3 - Win32 Release"
+# Name "prg1p3_3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsw b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsw new file mode 100644 index 0000000..fd4519a --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_3/prg1p3_3.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p3_3"=.\prg1p3_3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp new file mode 100644 index 0000000..d66c34c --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_4/main.cpp @@ -0,0 +1,43 @@ +// Programmieren 1, Praktikum 3, Aufgabe 4
+// Sven Eisenhauer
+// 17.11.2004
+//
+// file: main.cpp
+//
+// purpose: find the greatest common divisor of two numbers, recursive...
+//
+//
+
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int gcd(int,int);
+
+int main()
+{
+ int number1,
+ number2;
+
+ cout << "1st number: ";
+ cin >> number1;
+ cout << "2nd number: ";
+ cin >> number2;
+
+ cout <<endl<<"Greatest common divisor: "<< gcd(number1,number2) << endl;
+
+ return 0;
+}
+
+int gcd(int x, int y)
+{
+ if (0 == y)
+ {
+ return x;
+ }
+ else
+ {
+ return gcd (y,x%y);
+ }
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsp b/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsp new file mode 100644 index 0000000..39e531b --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_4" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p3_4 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_4.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_4.mak" CFG="prg1p3_4 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p3_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p3_4 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p3_4 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p3_4 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p3_4 - Win32 Release"
+# Name "prg1p3_4 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsw b/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsw new file mode 100644 index 0000000..3b1991e --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_4/prg1p3_4.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p3_4"=.\prg1p3_4.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp new file mode 100644 index 0000000..03c35e7 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp @@ -0,0 +1,67 @@ +// Programmieren 1, Praktikum 3, Aufgabe 5
+// Sven Eisenhauer
+// 17.11.2004
+//
+// file: main.cpp
+//
+// purpose: egypt multiplication
+//
+//
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int multIterative(int,int);
+void multRecursive(int,int, int &);
+
+int main()
+{
+ int number1,
+ number2,
+ erg;
+
+ cout << "1st number: ";
+ cin >> number1;
+ cout << "2nd number: ";
+ cin >> number2;
+
+ cout << "Product: " << multIterative(number1,number2) << endl;
+ multRecursive(number1,number2,erg);
+ cout << "Product: " << erg << endl;
+
+ return 0;
+}
+
+int multIterative(int a,int b)
+{
+ int product=0;
+ while (b>0)
+ {
+ if (0 != b%2)
+ product+=a;
+
+ a = a << 1;
+ b = b >> 1;
+ }
+ return product;
+}
+
+void multRecursive(int a,int b, int &product)
+{
+ int x,y;
+
+ if (b<=1)
+ product=a;
+
+ else
+ {
+ x=a<<1;
+ y=b>>1;
+ multRecursive(x,y,product);
+ if (0!=b%2)
+ product+=a;
+
+ }
+
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp new file mode 100644 index 0000000..5344ee4 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p3_5" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p3_5 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_5.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p3_5.mak" CFG="prg1p3_5 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p3_5 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p3_5 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p3_5 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p3_5 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p3_5 - Win32 Release"
+# Name "prg1p3_5 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsw b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsw new file mode 100644 index 0000000..6fd9859 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_5/prg1p3_5.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p3_5"=.\prg1p3_5.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt4/index.htm b/Bachelor/Prog1/Prakt4/index.htm new file mode 100644 index 0000000..6989787 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/index.htm @@ -0,0 +1,253 @@ +<html>
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<title>Praktikum 4</title>
+</head>
+
+<body>
+
+
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<caption> </caption>
+
+<tr>
+<td WIDTH="25%" BGCOLOR="#EFEFDE">FH Darmstadt
+<br>FB Informatik
+<br>Prof.Dr. H.P.Weber</td>
+
+<td>
+<center><font size="+3">Programmieren I </font>
+<br><font size=+3>Praktikum</font></center>
+</td>
+
+<td WIDTH="25%" BGCOLOR="#EFEFDE">
+<center><font size=+4>4</font></center>
+</td>
+</tr>
+</table>
+
+<br>
+<table border WIDTH="100%" >
+<tr VALIGN=TOP>
+<td>Ziel:</td><td>
+ Sie sollen die Verwendung von Arrays, Funktionen und Rekursion üben sowie
+ grundlegende Sortierverfahren kennen.
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+<b>1 Analyse von Craps</b></h3>
+
+<ul>
+<li>
+Schreiben Sie ein Programm, das 1000000-mal das Würfelspiel Craps simuliert.
+Ihr Programm soll folgende Fragen beantworten:</li>
+<ul>
+<li>
+Wieviele Spiele werden gewonnen beim ersten Wurf, beim zweiten Wurf,
+...(usw)..., beim 20.
+Wurf und nach dem 20.Wurf?</li>
+
+<li>
+Wieviele Spiele werden verloren beim ersten Wurf, beim zweiten Wurf,
+...(usw)..., beim 20.
+Wurf und nach dem 20.Wurf?</li>
+
+<li>
+Wie groß sind die Chancen Craps zu gewinnen? (Sie sollten herausfinden, dass
+Craps eines der fairsten in Spielkasinos gespielten Spiele ist. Was bedeutet
+diese Aussage?)</li>
+
+<li>
+Wie lang dauert ein Craps-Spiel im Durchschnitt?</li>
+
+<li>
+Erhöhen sich die Gewinnchancen mit der Dauer eines Craps-Spieles?</li>
+</ul>
+</ul>
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER="1" CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+<b>2 Sortierverfahren 'Direkte Auswahl (Selection Sort)' und
+'Direktes Einfügen </b>
+<b>(Insertion Sort)' </b></h3>
+
+<ul>
+<li>
+Das Sortierverfahren 'Direkte Auswahl' durchsucht ein unsortiertes Array nach dem kleinsten
+Element in dem Array. Danach wird das kleinste Element mit dem ersten Element
+des Arrays ausgetauscht. Dieser Prozess wird für das unsortierte Teilarray, das mit dem
+zweiten Element des Arrays beginnt, wiederholt. Jeder derartige Durchlauf durch
+das Array bewirkt, dass ein weiteres Element an die Stelle kommt, an die es
+gehört. Sobald das unsortierte Teilarray nur noch ein Element enthält, ist das Array
+sortiert.</li>
+
+<li>
+Schreiben Sie eine iterative Funktion <b><font face="Courier New">selectionSort</font></b>
+für diesen Algorithmus.</li>
+
+<li>
+Das Sortierverfahren 'Direktes Einfügen' fasst das erste Element eines
+unsortierten Arrays als bereits sortiertes Teilarray auf, in das sukzessive die
+weiteren Elemente eingefügt werden. Bei diesem Einfügeprozess muss das immer
+größer werdende Teilarray zu jedem Zeitpunkt sortiert bleiben. Jedes weitere
+Element muss also an die richtige Stelle eingefügt werden. Damit dies möglich
+ist, müssen alle Elemente, die größer sind als das Einfügeelement, jeweils
+um einen Platz verschoben werden. Sobald das sortierte Teilarray alle Elemente enthält, ist das Array
+sortiert.</li>
+
+<li>
+Schreiben Sie eine iterative Funktion <b><font face="Courier New">insertionSort</font></b>
+für diesen Algorithmus.</li>
+
+</ul>
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3><b>3 Verteilung der Augenzahlen bei Würfen mit vielen
+Würfeln </b></h3>
+
+<ul>
+<li>
+Entwickeln Sie ein Programm, das es dem Benutzer ermöglicht, Würfe mit mehreren Würfeln zu simulieren. Das Simulationsergebnis
+ist dann eine Gesamt-Augenzahl, die sich als Summe der Augenzahlen der
+einzelnen Würfel ergibt. Werden viele dieser Würfe mit mehreren
+Würfeln durchgeführt, ergibt sich eine Häufigkeitsverteilung
+für die Gesamt-Augenzahlen. Diese Häufigkeitsverteilung soll
+im Konsolenfenster in Form einer Tabelle und als einfache Übersichtsgraphik
+ausgegeben werden.</li>
+
+<li>
+Zu Beginn sollen vom Benutzer folgende Eingaben abgefragt werden:</li>
+
+<ul>
+<li>
+Die Zahl der Würfel, die er bei einem Wurf werfen möchte.</li>
+
+<li>
+Die Zahl der Würfe, die er mit der gewählten Anzahl von Würfeln
+durchführen möchte.</li>
+</ul>
+
+<li>
+Die Häufigkeitsverteilung für die erzielten Gesamt-Augenzahlen
+soll auf zwei verschiedene Arten dargestellt werden:</li>
+
+<ul>
+<li>
+Tabellarische Darstellung als Gegenüberstellung von erzielter Augenzahl
+und zugehöriger Häufigkeit. Dabei sollen sowohl die Absolutwerte
+der Häufigkeit als auch normierte Werte, die sich bei Division der
+Absolutwerte durch die Gesamtzahl der Würfe ergeben, ausgegeben werden.</li>
+
+<li>
+Graphische Darstellung als ein einfaches (um 90 Grad gekipptes) Säulendiagramm
+(z.B. entsprechende Anzahl von *).</li>
+</ul>
+
+<li>
+Strukturieren Sie Ihr Programm mit Hilfe von geeignet gewählten Funktionen
+für einzelne Teilaufgaben. </li>
+</ul>
+</td>
+</tr>
+</table>
+
+<br>
+<TABLE BORDER CELLSPACING=0 width="100%">
+<tr>
+<td>
+ <b><h3>4 Galton-Brett (fakultativ)</h3></b>
+ Entwickeln Sie ein Programm, das ein "Galton-Brett" und dessen Benutzung simuliert. Das
+ Simulationsergebnis soll im Konsolenfenster in Form von Zahlenkolonnen und als einfache Übersichtsgraphik ausgegeben werden.
+ <br><h4>Funktionsprinzip des Galton-Bretts</h4>
+ <TABLE>
+ <TBODY>
+ <TR vAlign=top>
+
+ <TD>
+ <p class="MsoNormal">Mit Hilfe eines Galton-Bretts (nach Sir Francis
+ Galton, 1822-1911) lassen sich wichtige Verteilungen aus der
+ Statistik experimentell erzeugen. Dabei laufen auf einem geneigt
+ aufgestellten Nagelbrett Kugeln durch die Nagelreihen. In Sammelbehältern am Fuß des Nagelbretts werden die
+ Kugeln aufgefangen. Sind die Nägel im Brett so angeordnet, daß
+ der Abstand zweier nebeneinander liegender Nägel durch den darüberliegenden
+ Nagel genau halbiert wird, so ist als Verteilung der Kugeln in den
+ Sammelbehältern die Normalverteilung (Gaußsche Glockenkurve) zu
+ erwarten.</TD>
+ <TD width=250 bgcolor="#EFEFDE">
+ <div style="mso-element:frame;mso-element-frame-hspace:7.05pt;mso-element-wrap:
+auto;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:page;
+mso-element-left:368.95pt;mso-element-top:2.05pt;mso-height-rule:exactly">
+ <p class="MsoNormal"><img src="index.1.gif" v:shapes="_x0000_i1025" width="192" height="138">
+ </div>
+ </TD></TR></TBODY></TABLE>
+ <h4>Darstellung des Simulationsergebnisses</h4>
+ <p class="MsoNormal">Das Ergebnis der Simulation soll durch Angabe der
+ Anzahl von Kugeln, die in 25 Sammelbehältern jeweils aufgefangen werden,
+ ausgegeben werden (Funktion <b><font face="Courier New">textOutput</font></b>).
+ Dabei sollen sowohl die Absolutwerte als auch normierte Werte, die sich
+ bei Division der Absolutwerte durch die Gesamtanzahl der Kugeln ergeben,
+ ausgegeben werden. Zusätzlich soll durch eine Funktion <b>
+ <font face="Courier New">graphicalOutput</font></b><i> </i>ein
+ einfaches (um 90 Grad gekipptes) Säulendiagramm (z.B. entsprechende
+ Anzahl von <span style="font-family:Courier">*</span><span style="mso-bidi-font-family:Arial">)
+ im Konsolenfenster ausgegeben werden können.<o:p>
+ </o:p>
+ </span></p>
+ <p class="MsoNormal">Die Bedienung des Programms erfolgt im
+ Konsolenfenster durch Angabe der gewünschten Anzahl von Kugeln und der
+ gewünschten Darstellungsart des Ergebnisses. Wenn Sie wollen, können Sie
+ natürlich auch die Anzahl der Sammelbehälter nicht auf genau 25
+ beschränken, sondern vom Benutzer des Programms vorgeben lassen.</p>
+ <div style="border:none;border-top:solid windowtext .75pt;padding:1.0pt 0cm 0cm 0cm">
+ <h4>Implementierungshinweis</h4>
+ </div>
+ <TABLE>
+ <TBODY>
+ <TR vAlign=top>
+
+ <TD><p class="MsoNormal" style="tab-stops:134.7pt">Es ist Zufall, ob eine
+ Kugel an einem Nagel nach links oder rechts rollt. Deshalb sollen
+ Zufallszahlen, die die Funktion
+ <span style="font-family:"Letter Gothic"; font-weight:700">
+ <font face="Courier New">rand</font></span><span style="font-family:"Letter Gothic""> </span>liefert, verwendet werden. Bedenken Sie, dass an jedem Nagel (d.h. auf
+ jeder Ebene) nur eine Entscheidung (links oder rechts) zu
+ treffen ist. Mit jeder Ebene, die die Kugel passiert, wird dadurch die
+ Menge der noch erreichbaren Sammelbehälter sukzessive eingeschränkt.
+ Dieses Verhalten soll in eine <b> rekursive</b> Funktion abgebildet werden.</p>
+ </TD>
+ <TD width=250 bgcolor="#EFEFDE">
+ <div style="mso-element:frame;mso-element-frame-hspace:7.05pt;mso-element-wrap:
+auto;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:page;
+mso-element-left:368.95pt;mso-element-top:2.05pt;mso-height-rule:exactly">
+ <p class="MsoNormal">
+ <img src="index.2.gif" v:shapes="_x0000_i1025" width="192" height="143">
+ </div>
+ </TD></TR></TBODY></TABLE>
+</td>
+</tr>
+</TABLE>
+
+</body>
+
+</html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp new file mode 100644 index 0000000..f9e3e90 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_1/main.cpp @@ -0,0 +1,148 @@ +// Programmieren 1, Praktikum 4, Aufgabe 1
+// Sven Eisenhauer
+// 08.12.2004
+//
+// file: main.cpp
+//
+// purpose: Play craps and analyse results
+//
+//
+//
+//
+
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setprecision;
+using std::setw;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+#include <ctime> // contains prototype for function time
+
+int rollDice( void ); // function prototype
+
+int main()
+{
+ // enumeration constants represent game status
+ enum Status { CONTINUE, WON, LOST };
+
+ int sum;
+ int myPoint;
+
+ const int maxGames=1000000;
+ const int maxRounds=22;
+
+ int round=1,
+ sumWon=0,
+ sumLost=0,
+ wRounds=0;
+
+ int nrLost[maxRounds]={0},
+ nrWon[maxRounds]={0};
+
+ Status gameStatus; // can contain CONTINUE, WON or LOST
+
+ // randomize random number generator using current time
+ srand( time( 0 ) );
+
+ for (int i=1;i<=maxGames;i++)
+ {
+ round=1;
+ sum = rollDice(); // first roll of the dice
+
+ // determine game status and point based on sum of dice
+ switch ( sum ) {
+
+ // win on first roll
+ case 7:
+ case 11:
+ gameStatus = WON;
+ break;
+
+ // lose on first roll
+ case 2:
+ case 3:
+ case 12:
+ gameStatus = LOST;
+ break;
+
+ // remember point
+ default:
+ gameStatus = CONTINUE;
+ myPoint = sum;
+ // cout << "Point is " << myPoint << endl;
+ break; // optional
+
+ } // end switch
+
+ // while game not complete ...
+ while ( gameStatus == CONTINUE ) {
+ sum = rollDice(); // roll dice again
+ round++;
+
+ // determine game status
+ if ( sum == myPoint ) // win by making point
+ gameStatus = WON;
+ else
+ if ( sum == 7 ) // lose by rolling 7
+ gameStatus = LOST;
+
+ } // end while
+
+ // display won or lost message
+ if ( gameStatus == WON )
+ //cout << "Player wins" << endl;
+ if (round<maxRounds)
+ nrWon[round]++;
+ else
+ nrWon[maxRounds-1]++;
+ else
+ //cout << "Player loses" << endl;
+ if (round<maxRounds)
+ nrLost[round]++;
+ else
+ nrLost[maxRounds-1]++;
+
+ }
+
+ cout << setw(7)<<"Round"<< setw(7)<< "won" << setw(7)<<"lost"<<endl;
+
+ for (i=1;i<maxRounds;i++)
+ {
+ cout << setw(7) << i << setw(7) << nrWon[i] << setw(7) << nrLost[i] << endl;
+ sumWon+=nrWon[i];
+ sumLost+=nrLost[i];
+ wRounds+=((nrWon[i]*i)+(nrLost[i]*i));
+ }
+ cout << endl <<"Total won: " << sumWon << " Total lost: " << sumLost << " Chance to win: "
+ << setprecision(4) << (static_cast <double> (sumWon)/maxGames)*100 << "%" << endl;
+ cout << "Average Game length: "<< setprecision(2) << static_cast <double> (wRounds)/maxGames << " Rounds" << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// roll dice, calculate sum and display results
+int rollDice( void )
+{
+ int die1;
+ int die2;
+ int workSum;
+
+ die1 = 1 + rand() % 6; // pick random die1 value
+ die2 = 1 + rand() % 6; // pick random die2 value
+ workSum = die1 + die2; // sum die1 and die2
+
+ // display results of this roll
+ // cout << "Player rolled " << die1 << " + " << die2
+ // << " = " << workSum << endl;
+
+ return workSum; // return sum of dice
+
+} // end function rollDice
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp new file mode 100644 index 0000000..d954bb5 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p4_1 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_1.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_1.mak" CFG="prg1p4_1 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p4_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p4_1 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p4_1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p4_1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p4_1 - Win32 Release"
+# Name "prg1p4_1 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsw b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsw new file mode 100644 index 0000000..4b8cd6b --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_1/prg1p4_1.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p4_1"=.\prg1p4_1.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp new file mode 100644 index 0000000..6c30139 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp @@ -0,0 +1,123 @@ +// Programmieren 1, Praktikum 4, Aufgabe 2
+// Sven Eisenhauer
+// 08.12.2004
+//
+// file: main.cpp
+//
+// purpose: Implementation of Selection Sort and Insertion Sort algorithm
+//
+
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setprecision;
+using std::setw;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+#include <ctime>
+
+void selectionSort(int[], int);
+void insertionSort(int[], int);
+
+int main ()
+{
+ const int arraySize=5;
+ int array1[arraySize],array2[arraySize];
+
+ srand(time(0));
+
+ // fill the arrays with some random stuff
+ for (int i=0;i<arraySize;i++)
+ {
+ array1[i]=rand()%1000;
+ array2[i]=array1[i];
+ }
+
+ // shown the unsorted random array
+ cout << "Unsorted Array:" << endl;
+ for (i=0;i<arraySize;i++)
+ {
+ cout << setw(5) << array1[i];
+ }
+ cout << endl;
+
+ // selectionSort
+ selectionSort(array1,arraySize);
+
+ cout << "Selection sorted Array:" << endl;
+ for (i=0;i<arraySize;i++)
+ {
+ cout << setw(5) << array1[i];
+ }
+ cout << endl;
+
+ // insertionSort
+ insertionSort(array2,arraySize);
+
+ cout << "Insertion sorted Array:" << endl;
+ for (i=0;i<arraySize;i++)
+ {
+ cout << setw(5) << array2[i];
+ }
+ cout << endl;
+
+ return 0;
+}
+
+void selectionSort(int a[],int aSize)
+{
+ int hold;
+
+ for (int i=0;i<aSize;i++)
+ {
+ // start from actual position...
+ for (int j=i;j<aSize;j++)
+ {
+ // ... search the minimum...
+ if(a[j]<a[i])
+ {
+ //... and insert it
+ hold=a[i];
+ a[i]=a[j];
+ a[j]=hold;
+ }
+ }
+ }
+} // end function selectionSort
+
+void insertionSort(int a[],int aSize)
+{
+ int temp,i;
+
+ for (int n=1;n<aSize;n++)
+ {
+ // only if we have a wrong order
+ if (a[n]<a[n-1])
+ {
+ // save the value, we want to insert
+ temp=a[n];
+ // we need a second variable
+ i=n-1;
+ // shift all values up till we are at the right place
+ // while the value, which is to be inserted, is smaller than
+ // actual array value
+ while (temp < a[i] && (i>= 0))
+ {
+ // always copy the value from the array field before
+ // so the gap "walks" to the left, until a[i] is at the right place
+ // and we can put temp in it.
+ a[i+1]=a[i];
+ i--;
+ }
+ // i+1 to compensate the last i--, because we want a[i] before the last i--
+ a[i+1]=temp;
+ }
+
+ }
+} // end function insertionSort
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp new file mode 100644 index 0000000..954904e --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p4_2 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_2.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_2.mak" CFG="prg1p4_2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p4_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p4_2 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p4_2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p4_2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p4_2 - Win32 Release"
+# Name "prg1p4_2 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsw b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsw new file mode 100644 index 0000000..fe3d2a4 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_2/prg1p4_2.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p4_2"=.\prg1p4_2.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp new file mode 100644 index 0000000..fb7e564 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp @@ -0,0 +1,102 @@ +// Programmieren 1, Praktikum 4, Aufgabe 3
+// Sven Eisenhauer
+// 14.12.2004
+//
+// file: main.cpp
+//
+// purpose: Analyse multiple rolls of multiple dice
+//
+
+#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setprecision;
+using std::setw;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+#include <ctime>
+
+void roll(const int, const int, int[]);
+void getPara(int &, int &);
+void printResultTbl(const int[], const int, const int);
+void printResultGrph(const int[], const int, const int);
+
+const int maxDice=20,
+ maxEyes=6,
+ minEyes=1;
+
+int main()
+{
+
+
+ int nrDice,
+ nrRolls;
+
+ int result[(maxDice*maxEyes)+1]={0};
+
+ // initialize random number generator
+ srand(time(0));
+
+ getPara(nrDice,nrRolls);
+
+ roll(nrDice,nrRolls,result);
+
+ printResultTbl(result, nrDice, nrRolls);
+ printResultGrph(result, nrDice, nrRolls);
+
+ return 0;
+}// end main
+
+void getPara(int &nrDice,int &nrRolls)
+{
+ cout << "Please enter number of dice to roll (max. "<<maxDice<<"): ";
+ cin >> nrDice;
+ cout << "Please enter number of rolls: ";
+ cin >> nrRolls;
+} // end function getPara
+
+void roll (const int nDice, const int nrRolls, int resultArray[])
+{
+ int sum;
+
+ for (int n=1;n<=nrRolls;n++)
+ {
+ sum=0;
+ for (int i=1;i<=nDice;i++)
+ sum+=(rand()%6)+1;
+ ++resultArray[sum];
+ }
+
+} // end fnction roll
+
+void printResultTbl(const int resArray[],const int nrDice, const int nrRolls)
+{
+ cout << setw(5) << "Sum" << setw(12) << "Frequency" << setw(20) << "norm. Frequency"<< endl;
+
+ for (int n=(nrDice*minEyes);n<=(nrDice*maxEyes);n++)
+ {
+ cout << setw(5) << n << setw(12) << resArray[n] << setprecision(2)<< setw(20) << (static_cast <double> (resArray[n]))/nrRolls << endl;
+ }
+}// end function printResultTbl
+
+void printResultGrph(const int resArray[],const int nrDice, const int nrRolls)
+{
+ cout << endl;
+
+ const int maxColumns=75;
+
+ for (int n=(nrDice*minEyes);n<=(nrDice*maxEyes);n++)
+ {
+ cout << setw(2) << n << ": ";
+ for (int i=0;i<static_cast <int>(((static_cast <double> (resArray[n]))/nrRolls)*maxColumns);i++)
+ cout<<"*";
+ cout << endl;
+ }
+}// end function printResultGrph
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp new file mode 100644 index 0000000..ba2f06a --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p4_3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_3.mak" CFG="prg1p4_3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p4_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p4_3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p4_3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p4_3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p4_3 - Win32 Release"
+# Name "prg1p4_3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw new file mode 100644 index 0000000..b24236f --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p4_3"=.\prg1p4_3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp new file mode 100644 index 0000000..8f481ff --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp @@ -0,0 +1,122 @@ +// Programmieren 1, Praktikum 4, Aufgabe 4
+// Sven Eisenhauer
+// 14.12.2004
+//
+// file: main.cpp
+//
+// purpose: Simulate a Galton Board
+//
+
+#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setprecision;
+using std::setw;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+#include <ctime>
+
+const int maxBoxes=100;
+const int minBoxes=1;
+
+int fall(int &,int &);
+void getInput(int &,int &, char &);
+void textOutput(int[], const int, const int);
+void graphicalOutput(int[], const int, const int);
+
+int main()
+{
+ srand(time(0));
+
+ int nrBalls;
+ int minBox,maxBox,nrBox;
+ int box;
+ int result[maxBoxes+1]={0};
+ char outputMode;
+
+ getInput(nrBalls,nrBox,outputMode);
+ for (int i=1;i<=nrBalls;i++)
+ {
+ minBox=minBoxes;
+ maxBox=nrBox;
+ box=fall(minBox,maxBox);
+ result[box]++;
+ }
+ if (outputMode=='t' || outputMode=='T')
+ textOutput(result,nrBalls,nrBox);
+ else
+ graphicalOutput(result,nrBalls,nrBox);
+
+ return 0;
+}// end function main
+
+void getInput(int& nrBa, int& nrBo, char &outpMode)
+{
+ cout << "Please enter number of boxes (max." << maxBoxes <<"): ";
+ cin>>nrBo;
+ cout << "Please enter number of balls: ";
+ cin>>nrBa;
+ cout << "Please enter output mode: [T/t] table, [G/g] graphical: ";
+ cin >> outpMode;
+}// end function getInput
+
+int fall(int &minB, int &maxB)
+{
+ // if we are not over last 2 boxes
+ if((maxB-minB)>1)
+ {
+ if (0==rand()%2)
+ // ball falls to the right => we cannot reach the most left box anymore
+ minB++;
+ else
+ // ball falls to the left => we cannot reach the most right box anymore
+ maxB--;
+ fall(minB,maxB);
+ //return 0;
+ }
+ // only 2 possible boxes left... the base case
+ else
+ {
+ if (0==rand()%2)
+ // left box
+ return minB;
+ else
+ // right box
+ return maxB;
+ }
+}
+
+void textOutput(int resArray[], const int balls,const int nrBox)
+{
+ //int sum=0;
+
+ cout << endl << setw(10) << "Box" << setw(10) << "Balls" << setw(16) << "Norm." <<endl;
+ for (int n=1;n<=nrBox;n++)
+ {
+ cout << setw(10) << n << setw(10) << resArray[n] << setw(16)<<static_cast <double>(resArray[n])/balls<<endl;
+ // sum+=resArray[n];
+ }
+ //cout << endl << "Sum: " << sum << endl << endl;
+}// end function textOutput
+
+void graphicalOutput(int resArray[], const int balls, const int nrBox)
+{
+ const int maxColumns=75;
+
+ for (int n=1;n<=nrBox;n++)
+ {
+ cout << setw(2) << n << ": ";
+ for (int i=0;i<static_cast <int>(((static_cast <double> (resArray[n]))/balls)*maxColumns);i++)
+ cout<<"*";
+ cout << endl;
+
+
+ }
+}// end function graphicalOutput
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp new file mode 100644 index 0000000..760be15 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_4" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p4_4 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_4.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p4_4.mak" CFG="prg1p4_4 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p4_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p4_4 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p4_4 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p4_4 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p4_4 - Win32 Release"
+# Name "prg1p4_4 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw new file mode 100644 index 0000000..85399da --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p4_4"=.\prg1p4_4.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt5/index.htm b/Bachelor/Prog1/Prakt5/index.htm new file mode 100644 index 0000000..a96b249 --- /dev/null +++ b/Bachelor/Prog1/Prakt5/index.htm @@ -0,0 +1,414 @@ +<html>
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<title>Praktikum 5</title>
+</head>
+
+<body>
+
+
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<caption> </caption>
+
+<tr>
+<td WIDTH="25%" BGCOLOR="#EFEFDE">FH Darmstadt
+<br>FB Informatik
+<br>Prof.Dr. H.P.Weber</td>
+
+<td>
+<center><font size="+3">Programmieren I </font>
+<br><font size=+3>Praktikum</font></center>
+</td>
+
+<td WIDTH="25%" BGCOLOR="#EFEFDE">
+<center><font size=+4>5</font></center>
+</td>
+</tr>
+</table>
+
+<br>
+<table border WIDTH="100%" >
+<tr VALIGN=TOP>
+<td>Ziel:</td><td>
+ Sie sollen die Verwendung von Zeigern, Arrays, Funktionen und Rekursion üben
+ sowie das Sortierverfahren Quicksort und einen Backtrackingalgorithmus
+ realisieren.
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+<b>1 Verbesserter Misch- und Gebe-Algorithmus</b></h3>
+<ul>
+<li>
+Im Kartenmisch- und -gebeprogramm der Vorlesung wurde ein ineffizienter
+Mischalgorithmus verwendet, bei dem es nicht garantiert war, dass er in einer
+bestimmten Zeit abgeschlossen ist. Dieser Algorithmus soll verbessert werden.</li>
+
+<li>
+Initialisieren Sie das <font face="Courier New"><b> deck</b></font> Array wie folgt:
+<table border="1">
+ <tr>
+ <td> </td>
+ <td><i>0</i></td>
+ <td><i>1</i></td>
+ <td><i>2</i></td>
+ <td><i>3</i></td>
+ <td><i>4</i></td>
+ <td><i>5</i></td>
+ <td><i>6</i></td>
+ <td><i>7</i></td>
+ <td><i>8</i></td>
+ <td><i>9</i></td>
+ <td><i>10</i></td>
+ <td><i>11</i></td>
+ <td><i>12</i></td>
+ </tr>
+ <tr>
+ <td><i>0</i></td>
+ <td><b>1</b></td>
+ <td><b>2</b></td>
+ <td><b>3</b></td>
+ <td><b>4</b></td>
+ <td><b>5</b></td>
+ <td><b>6</b></td>
+ <td><b>7</b></td>
+ <td><b>8</b></td>
+ <td><b>9</b></td>
+ <td><b>10</b></td>
+ <td><b>11</b></td>
+ <td><b>12</b></td>
+ <td><b>13</b></td>
+ </tr>
+ <tr>
+ <td><i>1</i></td>
+ <td><b>14</b></td>
+ <td><b>15</b></td>
+ <td><b>16</b></td>
+ <td><b>17</b></td>
+ <td><b>18</b></td>
+ <td><b>19</b></td>
+ <td><b>20</b></td>
+ <td><b>21</b></td>
+ <td><b>22</b></td>
+ <td><b>23</b></td>
+ <td><b>24</b></td>
+ <td><b>25</b></td>
+ <td><b>26</b></td>
+ </tr>
+ <tr>
+ <td><i>2</i></td>
+ <td><b>27</b></td>
+ <td><b>28</b></td>
+ <td><b>29</b></td>
+ <td><b>30</b></td>
+ <td><b>31</b></td>
+ <td><b>32</b></td>
+ <td><b>33</b></td>
+ <td><b>34</b></td>
+ <td><b>35</b></td>
+ <td><b>36</b></td>
+ <td><b>37</b></td>
+ <td><b>38</b></td>
+ <td><b>39</b></td>
+ </tr>
+ <tr>
+ <td><i>3</i></td>
+ <td><b>40</b></td>
+ <td><b>41</b></td>
+ <td><b>42</b></td>
+ <td><b>43</b></td>
+ <td><b>44</b></td>
+ <td><b>45</b></td>
+ <td><b>46</b></td>
+ <td><b>47</b></td>
+ <td><b>48</b></td>
+ <td><b>49</b></td>
+ <td><b>50</b></td>
+ <td><b>51</b></td>
+ <td><b>52</b></td>
+ </tr>
+</table>
+<br>
+</li>
+
+<li>
+Modifizieren Sie die <font face="Courier New"><b>shuffle</b></font> Funktion so,
+dass sie Zeile für Zeile und Spalte für Spalte durch das Array läuft und
+jedes Element einmal bearbeitet: Jedes Element soll mit einem zufällig
+ausgewählten Element des Arrays vertauscht werden. Die <font face="Courier New"><b>shuffle</b></font>
+Funktion soll so oft ausgeführt werden, bis das Blatt gut gemischt ist.
+Überprüfen Sie dies durch Ausdrucken des Arrays.</li>
+
+<li>
+Optimieren Sie zusätzlich auch den Gebe-Algorithmus in der <font face="Courier New"><b>deal</b></font>
+Funktion: Sobald eine Karte ausgegeben ist, soll nicht weiter nach der Nummer
+dieser Karte gesucht werden, sondern das Programm soll sofort mit dem Geben der
+nächsten Karte fortfahren.</li>
+
+</ul>
+
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER="1" CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+<b>2 Sortierverfahren 'Quicksort'</b></h3>
+
+<ul>
+<li>
+Das rekursive Sortierverfahren 'Quicksort' besteht aus zwei Schritten:
+<ul>
+<li>
+<b>
+Partitionierungsschritt:</b> Nimm das erste Element des unsortierten Arrays
+('Partitionierungselement') und bestimme seine endgültige Position im sortierten Array (d.h. alle Werte
+links des Elementes sind kleiner und alle Werte rechts des Elementes sind
+größer). Ergebnis dieses Schrittes ist ein Element an der richtigen Position
+und zwei unsortierte Teilarrays.
+</li>
+
+<li>
+<b>Rekursionschritt:</b> Führe den Partitionierungsschritt für jedes
+unsortierte Teilarray aus, solange, bis die Teilarrays nur noch aus einem
+Element bestehen.</li>
+
+</ul>
+<li>Die Bestimmung der endgültigen Position des Partitionierungselementes im
+ Partitionierungsschritt läuft folgendermaßen ab:
+<ul>
+<li>
+
+Beginnend beim letzten Element des Arrays wird das erste Element gesucht, das
+kleiner als das Partitionierungselement ist und dieses wird mit dem
+Partitionierungselement vertauscht:
+<table border="1">
+ <tr>
+ <td><b>37</b></td>
+ <td>2</td>
+ <td>6</td>
+ <td>4</td>
+ <td>89</td>
+ <td>8</td>
+ <td>10</td>
+ <td><i>12</i></td>
+ <td>68</td>
+ <td>45</td>
+ </tr>
+</table>
+führt also zu
+<table border="1">
+ <tr>
+ <td><i>12</i></td>
+ <td>2</td>
+ <td>6</td>
+ <td>4</td>
+ <td>89</td>
+ <td>8</td>
+ <td>10</td>
+ <td><b>37</b></td>
+ <td>68</td>
+ <td>45</td>
+ </tr>
+</table>
+
+</li>
+<li>
+Nun wird von links aus (aber ohne das bereits behandelte Element 12) das erste
+Element gesucht, das größer als das Partitionierungselement ist und dieses wird mit dem
+Partitionierungselement vertauscht:
+<table border="1">
+ <tr>
+ <td>12</td>
+ <td>2</td>
+ <td>6</td>
+ <td>4</td>
+ <td><b>37</b></td>
+ <td>8</td>
+ <td>10</td>
+ <td><i>89</i></td>
+ <td>68</td>
+ <td>45</td>
+ </tr>
+</table>
+</li>
+<li>
+
+Wieder von rechts, aber beginnend mit dem Element vor dem gerade behandelten
+Element 89 wird das erste Element gesucht, das
+kleiner als das Partitionierungselement ist und dieses wird mit dem
+Partitionierungselement vertauscht:
+<table border="1">
+ <tr>
+ <td>12</td>
+ <td>2</td>
+ <td>6</td>
+ <td>4</td>
+ <td><i>10</i></td>
+ <td>8</td>
+ <td><b>37</b></td>
+ <td><i>89</i></td>
+ <td>68</td>
+ <td>45</td>
+ </tr>
+</table>
+</li>
+<li>
+
+Wieder von links, aber beginnend mit dem Element hinter dem gerade behandelten
+Element 10 wird das erste
+Element gesucht, das größer als das Partitionierungselement ist. Es wird keins
+mehr gefunden, so dass beim Vergleich von <b>37</b> mit sich selbst die
+endgültige Position von <b>37</b> fest steht.
+
+</ul>
+<li>Schreiben Sie eine rekursive Funktion <font face="Courier New"><b>quickSort</b></font>,
+ die ein Array mit 100 zufälligen int-Werten (aus dem Bereich von 1 bis 1000) sortiert. Die Funktion soll als Argumente
+ das int-Array, einen Anfangsindex und einen Endindex erhalten. Eine Funktion <font face="Courier New"><b>partition</b></font>
+ soll von <b><font face="Courier New">quickSort</font> </b>zur Durchführung
+ des
+ Partitionierungsschritts aufgerufen werden.</li>
+</ul>
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+3<b> Labyrinth (Backtracking)</b></h3>
+<ul>
+
+<li>
+Folgendes Gitter aus Kreuzen(<font face="Courier New"><b>#</b></font>),
+Leerstellen(<font face="Courier New"><b> </b></font>) und Punkten(<font face="Courier New"><b>.</b></font>) stellt ein Labyrinth in Form eines
+doppelt indizierten Arrays dar:
+<br>
+<br>
+<font face="Courier New"><b>..............<br>
+.############.<br>
+.# # #.<br>
+. # # #### #.<br>
+.### # # #.<br>
+. ### # .<br>
+.#### # # # #.<br>
+.# # # # # #.<br>
+.## # # # # #.<br>
+.# # #.<br>
+.###### ### #.<br>
+.# # #.<br>
+.######## ###.<br>
+..............</b></font>
+<br>
+<br>
+In dem doppelt indizierten Array repräsentieren die Kreuze die Mauern des
+Labyrinths, die Leerstellen die möglichen Wege durch das Labyrinth und die Punkte
+die Welt außerhalb des Labyrinths. Man kann also
+nur zu einem Ort im Array 'laufen', der eine Leerstelle enthält und man hat
+einen Ausgang gefunden, sobald man auf einen Punkt trifft.
+</li>
+
+<li>
+Schreiben Sie eine rekursive Funktion <font face="Courier New"><b>mazeTraverse</b></font>
+zum Durchlaufen des Labyrinths. Die Funktion soll als Argumente ein 14mal14 <b>
+<font face="Courier New">ch</font></b><font face="Courier New"><b>ar</b></font>-Array
+für das Labyrinth und außerdem die Koordinaten für einen Ort innerhalb des
+Labyrinths (beim ersten Aufruf der Eingang) übernehmen. Während <font face="Courier New"><b>
+mazeTraverse</b></font> versucht, den Ausgang aus dem Labyrinth zu finden, soll
+jede Leerstelle auf dem gelaufenen Weg durch ein <font face="Courier New"><b>x</b></font>
+ersetzt werden. Die Funktion soll das Labyrinth bei jedem Schritt ausgeben, so
+dass der Nutzer des Programms zusehen kann, wie das Labyrinth durchlaufen wird.
+Die Anzahl der gefundenen Ausgänge soll mitgezählt werden und jeder Ausgang
+mit seiner laufenden Nummer gekennzeichnet werden.</li>
+
+<li>
+Hinweis: Von einem gegebenen Ort im Labyrinth kann man versuchen nach rechts,
+unten, links oder oben weiterzulaufen. Jeder dieser Versuche wird durch einen
+rekursiven Aufruf von <font face="Courier New"><b>
+mazeTraverse</b></font> realisiert. Ist ein Weiterlaufen möglich, folgt der
+nächste rekursive Aufruf. Wird hingegen ein Ort erreicht, von dem aus kein
+Weiterlaufen mehr möglich ist, wird eine Rekursionsstufe zurückgenommen. Dies
+hat den Effekt, dass von einem früher erreichten Ort eine neue Möglichkeit des
+Weiterkommens ausprobiert wird. Einen solchen Algorithmus bezeichnet man als
+'Backtracking'.</li>
+
+</ul>
+
+</td>
+</tr>
+</table>
+
+<br>
+
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>4<b> Geben und Beurteilen eines Pokerblatts </b>
+ <b>(fakultativ)</b>
+</h3>
+
+<ul>
+<li>
+Modifizieren Sie das Kartenmisch- und -gebeprogramm der Vorlesung, so dass ein
+Pokerblatt mit fünf Karten gegeben wird. Schreiben Sie zusätzliche Funktionen,
+die folgendes leisten:
+<ul>
+
+<li>Bestimmen, ob das Blatt 'One pair' (z.B. 2 Buben) enthält.</li>
+<li>Bestimmen, ob das Blatt 'Two pair' enthält.</li>
+
+<li>
+Bestimmen, ob das Blatt 'Three-of-a-kind' (z.B. 3 Damen) enthält.</li>
+
+<li>
+Bestimmen, ob das Blatt 'Straight' (5 direkt aufeinander folgende Karten
+beliebiger Farbe)
+enthält.</li>
+
+<li>
+Bestimmen, ob das Blatt 'Flush' (5 Karten der gleichen Farbe) enthält.</li>
+
+<li>
+Bestimmen, ob das Blatt 'Full house' ('One pair' + 'Three of a kind') enthält. </li>
+
+<li>
+Bestimmen, ob das Blatt 'Four-of-a-kind' (z.B. 4 Asse) enthält.</li>
+
+<li>
+Bestimmen, ob das Blatt 'Straight flush' (5 direkt aufeinander folgende Karten
+einer Farbe)
+enthält.</li>
+
+<li>
+Bestimmen, ob das Blatt 'Royal flush' (Zehn, Bube, Dame, König, Ass in einer
+Farbe)
+enthält.</li>
+</ul>
+<li>Wie oft erhalten Sie die angegebenen Pokerblätter von 'One pair' bis
+ 'Royal flush', wenn Sie 1000 Blätter geben lassen? Wie oft, wenn Sie eine
+ Million Blätter (oder mehr) geben lassen? Bestätigen Ihre Ergebnisse die
+ Tatsache, dass die angegebenen neun Blätter von oben nach unten als zunehmend
+ besser gewertet werden?</li>
+<li>Anmerkung: Um realistischere Ergebnisse zu erhalten, können Sie die Aufgabe
+ auch in der folgenden Variante bearbeiten ('Seven-card stud'): Der Spieler
+ erhält sieben Karten, aus denen er sich sein Blatt mit fünf Karten
+ zusammenstellt.</li>
+</td>
+</tr>
+</table>
+
+</body>
+</html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp new file mode 100644 index 0000000..61644cc --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp @@ -0,0 +1,124 @@ +// Programmieren 1, Praktikum 5, Aufgabe 1
+// Sven Eisenhauer
+// 16.12.2004
+//
+// file: main.cpp
+//
+// purpose: Shuffle a standard deck of 52 cards and deal them
+//
+
+#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
+using std::left;
+using std::right;
+
+
+#include <iomanip>
+
+using std::setprecision;
+using std::setw;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+#include <ctime>
+
+const int maxColumns=13;
+const int maxRows=4;
+const int maxCards=52;
+
+// prototypes
+void shuffle( int [][ maxColumns ] );
+void deal( const int [][ maxColumns ], const char *[], const char *[] );
+
+
+
+int main()
+{
+ // initialize suit array
+ const char *suit[ 4 ] =
+ { "Hearts", "Diamonds", "Clubs", "Spades" };
+
+ // initialize face array
+ const char *face[ 13 ] =
+ { "Ace", "Deuce", "Three", "Four",
+ "Five", "Six", "Seven", "Eight",
+ "Nine", "Ten", "Jack", "Queen", "King" };
+
+ // initialize deck array
+ int deck[ maxRows ][ maxColumns ] =
+ {
+ { 1,2,3,4,5,6,7,8,9,10,11,12,13 },
+ { 14,15,16,17,18,19,20,21,22,23,24,25,26 },
+ { 27,28,29,30,31,32,33,34,35,36,37,38,39 },
+ { 40,41,42,43,44,45,46,47,48,49,50,51,52 }
+ };
+
+ srand( time( 0 ) ); // seed random number generator
+
+ shuffle( deck );
+ deal( deck, face, suit );
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// shuffle cards in deck
+void shuffle( int wDeck[][ 13 ] )
+{
+ int temp=0;
+ int randRow,
+ randCol;
+
+ for (int column=0;column<maxColumns;column++) {
+ for (int row=0;row<maxRows;row++) {
+ randCol=rand()%maxColumns;
+ randRow=rand()%maxRows;
+ temp=wDeck[row][column];
+ wDeck[row][column]=wDeck[randRow][randCol];
+ wDeck[randRow][randCol]=temp;
+ }
+ }
+ for (int row=0;row<maxRows;row++) {
+ for (column=0;column<maxColumns;column++) {
+ cout << setw(4) << wDeck[row][column];
+ }
+ cout<<endl;
+ }
+
+
+} // end function shuffle
+
+// deal cards in deck
+void deal( const int wDeck[][ 13 ], const char *wFace[],
+ const char *wSuit[] )
+{
+ enum found {FALSE,TRUE};
+ int row,column;
+ found cardFound=FALSE;
+ // for each of the 52 cards
+ for ( int card = 1; card <= maxCards; card++ ) {
+ cardFound=FALSE;
+ row=0;
+ while ((row<maxRows)&&cardFound==FALSE)
+ {
+ column=0;
+ while((column<maxColumns)&&cardFound==FALSE)
+ {
+ // if slot contains current card, display card
+ if ( wDeck[ row ][ column ] == card ) {
+ cout << setw( 5 ) << right << wFace[ column ]
+ << " of " << setw( 8 ) << left
+ << wSuit[ row ]
+ << ( card % 2 == 0 ? '\n' : '\t' );
+ cardFound=TRUE;
+ }
+ column++;
+
+ } // end while
+ row++;
+ }
+ }
+} // end function deal
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsp b/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsp new file mode 100644 index 0000000..3318d1a --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p5_1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p5_1 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_1.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_1.mak" CFG="prg1p5_1 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p5_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p5_1 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p5_1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p5_1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p5_1 - Win32 Release"
+# Name "prg1p5_1 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsw b/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsw new file mode 100644 index 0000000..08dce0d --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_1/prg1p5_1.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p5_1"=.\prg1p5_1.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp new file mode 100644 index 0000000..5d5b74e --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_2/main.cpp @@ -0,0 +1,178 @@ +// Programmieren 1, Praktikum 5, Aufgabe 2
+// Sven Eisenhauer
+// 16.12.2004
+//
+// file: main.cpp
+//
+// purpose: QuickSort algorithm
+//
+
+#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setprecision;
+using std::setw;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+#include <ctime>
+
+// constant definitions
+const int arraySize=100; // number of array elements
+const int maxNum=1000; // max. Number in Array plus 1
+const int arrayStart=0; // first array element
+const int arrayEnd=arraySize-1; // last array element
+
+// function prototypes
+void quickSort(int [],int,int);
+int partition(int [], int,int,int&);
+void swapRight(int [], int &,int &, int &, int &, int &);
+void swapLeft(int [], int&,int &, int&, int &, int &);
+
+int main()
+{
+ int array[arraySize];
+
+ // initialize random number generator
+ srand(time(0));
+
+ // generate array with random content
+ for (int i=0;i<arraySize;i++) {
+ array[i]=rand()%maxNum;
+ }
+
+ // show it unsorted
+ cout << "Unsorted:" << endl;
+ for (i=0;i<arraySize;i++) {
+ cout << setw(4) << array[i];
+ }
+ cout << endl;
+
+ // sort it
+ quickSort(array,arrayStart,arrayEnd);
+
+ // show it sorted
+ cout << "Sorted:" << endl;
+ for (i=0;i<arraySize;i++) {
+ cout << setw(4) << array[i];
+ }
+ cout << endl;
+ // habe fertisch
+ return 0;
+}// end function main
+
+void quickSort(int toSort[], int start, int end)
+{
+ int pos;
+ // partition the array and get pos, where array is divided
+ partition(toSort,start,end,pos);
+ if (pos > start)
+ // now sort lower part
+ quickSort(toSort,start,pos-1);
+ if (pos < end)
+ // and higher part
+ quickSort(toSort,pos+1,end);
+}// end function quicksort
+
+int partition(int array[],int start, int end, int &pos)
+{
+ int loop=0;
+ int foundL,foundR;
+ int newStart=start;
+ int newEnd=end;
+ int nextStart=start;
+
+ pos=start;
+
+ do {
+ foundR=0;
+ foundL=0;
+ // decide whether to search from left or right
+ // 0: right, 1: left
+ if (0==(loop%2)) {
+ swapRight(array,newEnd,newStart,nextStart,pos,foundR);
+ // set newStart for the next call of a swap fct.
+ newStart=nextStart;
+ /*cout << endl << " right "<< loop << " "<< endl;
+ for (int j=0;j<=end;j++)
+ cout << setw(4) << array[j];
+ cout << endl;*/
+ }
+ else {
+ swapLeft(array,newEnd,newStart,nextStart,pos,foundL);
+ // set newStart for the next call of a swap fct.
+ newStart=nextStart;
+ /*cout << endl << " left "<< loop << " "<< endl;
+ for (int j=0;j<=end;j++)
+ cout << setw(4) << array[j];
+ cout << endl;*/
+ }
+ loop++;
+ } while (((1==foundL)||(1==foundR)));
+
+ return 0;
+}// end function partition
+
+void swapRight(int arr[], int &end,int &newStart,int &nextStart, int &pos, int &found)
+{
+ int i,temp;
+ // here we start to walk through array, from RIGHT!!!
+ i=end;
+ // newStart is the beginning of the area to check of the array
+ // when newStart==pos (which is the position of we element, which we order at the moment)
+ // this means: we are done here!
+ while((i>=newStart)&&(i!=pos)) {
+ // if we have found a smaller value, when searching from right
+ if (arr[i]<=arr[pos]) {
+ // swap the values
+ temp=arr[i];
+ arr[i]=arr[pos];
+ arr[pos]=temp;
+ // now set the next Start of search from left to one field right of
+ // the element, we currently searched and swapped
+ nextStart=newStart+1;
+ // in i is the actual position of the element which should be ordered
+ // we should not forget this and tell this the place, from where we were called
+ pos=i;
+ // YES!!! we found a smaller value by searching from right
+ found=1;
+ break;
+ }
+ i--;
+ }
+}// end function swapRight
+
+void swapLeft(int arr[], int &end,int &newStart,int &nextStart, int &pos, int &found)
+{
+ int i,temp;
+ // here we start to walk through array, from LEFT!!!
+ i=newStart;
+ // newStart is the beginning of the area to check of the array
+ // when newStart==pos (which is the position of we element, which we order at the moment)
+ // this means: we are done here!
+ while((i<=end)&&(i!=pos)) {
+ // if we have found a bigger value, when searching from left
+ if (arr[i]>arr[pos]) {
+ // swap the values
+ temp=arr[i];
+ arr[i]=arr[pos];
+ arr[pos]=temp;
+ // now set the next Start of search from right to one field left of
+ // the element, we currently searched and swapped
+ nextStart=newStart-1;
+ // in i is the actual position of the element which should be ordered
+ // we should not forget this and tell this the place, from where we were called
+ pos=i;
+ // YES!!! we found a smaller value by searching from right
+ found=1;
+ break;
+ }
+ i++;
+ }
+}// end function swapLeft
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp new file mode 100644 index 0000000..8d19b08 --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p5_2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p5_2 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_2.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_2.mak" CFG="prg1p5_2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p5_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p5_2 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p5_2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p5_2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p5_2 - Win32 Release"
+# Name "prg1p5_2 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsw b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsw new file mode 100644 index 0000000..b0380fc --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_2/prg1p5_2.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p5_2"=.\prg1p5_2.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp new file mode 100644 index 0000000..b99a0ab --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp @@ -0,0 +1,128 @@ +// Programmieren 1, Praktikum 5, Aufgabe 3
+// Sven Eisenhauer
+// 10.01.2005
+//
+// file: main.cpp
+//
+// purpose: Find all exists of a given maze
+//
+
+#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+// constant definitions
+const int maxLines=14;
+const int maxRows=14;
+const int startRow=1;
+const int startLine=3;
+
+//function prototypes
+//void mazePrint(const char[][maxRows], const int);
+void mazePrint(const char[][maxRows]);
+void mazeTraverse(char [][maxRows],int,int,int&);
+
+int main ()
+{
+ int exitCount=0;
+
+ char maze[maxLines][maxRows] =
+ {
+ {'.','.','.','.','.','.','.','.','.','.','.','.','.','.'},
+ {'.','#','#','#','#','#','#','#','#','#','#','#','#','.'},
+ {'.','#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#','.'},
+ {'.',' ',' ','#',' ','#',' ','#','#','#','#',' ','#','.'},
+ {'.','#','#','#',' ','#',' ',' ',' ',' ','#',' ','#','.'},
+ {'.',' ',' ',' ',' ',' ','#','#','#',' ','#',' ',' ','.'},
+ {'.','#','#','#','#',' ','#',' ','#',' ','#',' ','#','.'},
+ {'.','#',' ',' ','#',' ','#',' ','#',' ','#',' ','#','.'},
+ {'.','#','#',' ','#',' ','#',' ','#',' ','#',' ','#','.'},
+ {'.','#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#','.'},
+ {'.','#','#','#','#','#','#',' ','#','#','#',' ','#','.'},
+ {'.','#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#','.'},
+ {'.','#','#','#','#','#','#','#','#',' ','#','#','#','.'},
+ {'.','.','.','.','.','.','.','.','.','.','.','.','.','.'}
+ };
+
+ mazeTraverse(maze,startRow,startLine,exitCount);
+
+ cout << "\nNumber of Exits: " << exitCount << endl;
+
+ return 0;
+}
+
+void mazeTraverse(char laby[][maxRows],int x,int y,int &count)
+{
+ char temp=' ';
+
+ if (x < maxLines && y < maxRows && x > 0 && y > 0)
+ {
+
+ if (laby[y][x] == ' ')
+ laby[y][x] = 'x';
+
+ if (laby[y+1][x] == '.')
+ {
+ count++;
+ itoa(count,&temp,10);
+ laby[y+1][x]=temp;
+ }
+ if (laby[y][x+1] == '.')
+ {
+ count++;
+ itoa(count,&temp,10);
+ laby[y][x+1]=temp;
+ }
+ if (laby[y-1][x] == '.')
+ {
+ count++;
+ itoa(count,&temp,10);
+ laby[y-1][x]=temp;
+ }
+ if (laby[y][x-1] == '.')
+ {
+ count++;
+ itoa(count,&temp,10);
+ laby[y][x-1]=temp;
+ }
+
+ //mazePrint(laby,count);
+ mazePrint(laby);
+
+ if (laby[y+1][x] == ' ')
+ mazeTraverse(laby,x,y+1,count);
+
+
+ if (laby[y][x+1] == ' ')
+ mazeTraverse(laby,x+1,y,count);
+
+
+ if (laby[y-1][x] == ' ')
+ mazeTraverse(laby,x,y-1,count);
+
+
+ if (laby[y][x-1] == ' ')
+ mazeTraverse(laby,x-1,y,count);
+
+ }
+
+}
+
+void mazePrint(const char array[][maxRows])
+//void mazePrint(const char array[][maxRows],const int count)
+{
+ system ("cls");
+ for (int i=0;i<maxLines;i++)
+ {
+ for (int j=0;j<maxRows;j++)
+ cout << array[i][j];
+ cout << "\n";
+ }
+ //cout << "\n" << count;
+ //system ("pause");
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsp b/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsp new file mode 100644 index 0000000..f9bca6e --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p5_3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p5_3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_3.mak" CFG="prg1p5_3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p5_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p5_3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p5_3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p5_3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p5_3 - Win32 Release"
+# Name "prg1p5_3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsw b/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsw new file mode 100644 index 0000000..5abecf4 --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_3/prg1p5_3.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p5_3"=.\prg1p5_3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp new file mode 100644 index 0000000..260ff9c --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_4/main.cpp @@ -0,0 +1,438 @@ +// Programmieren 1, Praktikum 5, Aufgabe 4
+// Sven Eisenhauer
+// 10.01.2005
+//
+// file: main.cpp
+//
+// purpose: Shuffle a standard deck of 52 cards, deal a poker game and analyse the cards of the player
+//
+
+#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
+using std::left;
+using std::right;
+
+
+#include <iomanip>
+
+using std::setprecision;
+using std::setw;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+#include <ctime>
+
+const int maxColumns=13;
+const int maxRows=4;
+const int maxCards=52;
+const int cards=7;
+const int maxResults=10;
+const int nrGames=1000000;
+
+struct hand {
+ const char *farbe;
+ const char *wert;
+};
+
+
+// prototypes
+void shuffle( int [][ maxColumns ] );
+void deal( const int [][ maxColumns ], const char *[], const char *[], hand[] );
+void printHand(const hand []);
+void analyseCards(const hand[], const char *[], const char *[],int[],const char *[]);
+void printResults(const int[],const char *[]);
+
+int onePair(const hand[], const char *[]);
+int twoPairs(const hand[], const char *[]);
+int threeOfAKind(const hand[], const char *[]);
+int straight(const hand[], const char *[]);
+int flush(const hand[], const char *[]);
+int fullHouse(const hand[], const char *[]);
+int fourOfAKind(const hand[], const char *[]);
+int straightFlush(const hand[], const char *[], const char *[]);
+int royalFlush(const hand[], const char *[], const char *[]);
+
+int main()
+{
+ hand blatt[cards];
+
+ int erg[maxResults]={0};
+
+ const char *results[maxResults] =
+ { "Nothing","One Pair","Two Pairs","Three of a kind",
+ "Straight","Flush","Full house","Four of a kind",
+ "Straight Flush","Royal Flush" };
+
+ // initialize suit array
+ const char *suit[ 4 ] =
+ { "Hearts", "Diamonds", "Clubs", "Spades" };
+
+ // initialize face array
+ const char *face[ 13 ] =
+ { "Ace", "Deuce", "Three", "Four",
+ "Five", "Six", "Seven", "Eight",
+ "Nine", "Ten", "Jack", "Queen", "King" };
+
+ // initialize deck array
+ int deck[ maxRows ][ maxColumns ] =
+ {
+ { 1,2,3,4,5,6,7,8,9,10,11,12,13 },
+ { 14,15,16,17,18,19,20,21,22,23,24,25,26 },
+ { 27,28,29,30,31,32,33,34,35,36,37,38,39 },
+ { 40,41,42,43,44,45,46,47,48,49,50,51,52 }
+ };
+
+ srand( time( 0 ) ); // seed random number generator
+
+ for (int n=1;n<=nrGames;n++)
+ {
+ shuffle( deck );
+ deal( deck, face, suit, blatt );
+ //printHand(blatt);
+ analyseCards(blatt,face,suit,erg,results);
+ }
+ printResults(erg,results);
+
+ return 0; // indicates successful termination
+
+} // end main
+
+void printHand(const hand blatt[])
+{
+ cout << endl << endl << "Player's cards:" << endl;
+ for (int i=0;i<cards;i++)
+ cout << blatt[i].wert << " of " << blatt[i].farbe << endl;
+}// end function print hand
+
+void printResults(const int erg[], const char *results[])
+{
+ cout << endl;
+ for (int i=0;i<maxResults;i++)
+ {
+ cout << results[i] << ": " << erg[i] << endl;
+ }
+}
+
+void analyseCards(const hand blatt[],const char *wFace[],
+ const char *wSuit[],int erg[], const char *results[])
+{
+ int hasOnePair=0;
+ int hasTwoPairs=0;
+ int hasThreeOfAKind=0;
+ int hasFullHouse=0;
+ int hasFourOfAk=0;
+ int hasFlush=0;
+ int hasStraight=0;
+ int hasStraightFlush=0;
+ int hasRoyalFlush=0;
+
+ hasOnePair=onePair(blatt,wFace);
+ hasTwoPairs=twoPairs(blatt,wFace);
+ hasThreeOfAKind=threeOfAKind(blatt,wFace);
+ hasFullHouse=fullHouse(blatt,wFace);
+ hasFourOfAk=fourOfAKind(blatt,wFace);
+
+ if (1 == hasOnePair)
+ {
+ erg[1]++;
+ }
+
+ if (1 == hasTwoPairs)
+ {
+ erg[2]++;
+ }
+ if (1 == hasThreeOfAKind)
+ {
+ if(1==hasFullHouse)
+ {
+ erg[6]++;
+ }
+ else
+ {
+ erg[3]++;
+ }
+ }
+
+ if (1==hasFourOfAk)
+ erg[7]++;
+
+ hasFlush=flush(blatt,wSuit);
+ hasStraight=straight(blatt,wFace);
+ hasStraightFlush=straightFlush(blatt,wFace,wSuit);
+ hasRoyalFlush=royalFlush(blatt,wFace,wSuit);
+ if(1==hasFlush)
+ {
+ if(1==hasStraight)
+ {
+
+ if(1==hasStraightFlush)
+ {
+ if(1==hasRoyalFlush)
+ {
+ erg[9]++;
+ }
+ else
+ {
+ erg[8]++;
+ }
+ }
+ }
+ else
+ {
+ erg[5]++;
+ }
+ }
+ else
+ {
+ if(1==hasStraight)
+ {
+ erg[4]++;
+ }
+ }
+
+ if (hasOnePair==0 && hasTwoPairs==0 && hasThreeOfAKind==0 && hasFullHouse==0 && hasFourOfAk==0 && hasFlush==0 && hasStraight==0 && hasStraightFlush==0 && hasRoyalFlush==0)
+ erg[0]++;
+}
+
+
+// shuffle cards in deck
+void shuffle( int wDeck[][ 13 ] )
+{
+ int temp=0;
+ int randRow,
+ randCol;
+
+ for (int column=0;column<maxColumns;column++) {
+ for (int row=0;row<maxRows;row++) {
+ randCol=rand()%maxColumns;
+ randRow=rand()%maxRows;
+ temp=wDeck[row][column];
+ wDeck[row][column]=wDeck[randRow][randCol];
+ wDeck[randRow][randCol]=temp;
+ }
+ }
+} // end function shuffle
+
+// deal cards in deck
+void deal( const int wDeck[][ 13 ], const char *wFace[],
+ const char *wSuit[], hand karten[cards] )
+{
+ enum found {FALSE,TRUE};
+ int row,column;
+ found cardFound=FALSE;
+ // give first 5 cards
+ for ( int card = 1; card <= cards; card++ ) {
+ cardFound=FALSE;
+ row=0;
+ while ((row<maxRows)&&cardFound==FALSE)
+ {
+ column=0;
+ while((column<maxColumns)&&cardFound==FALSE)
+ {
+ // if slot contains current card, display card
+ if ( wDeck[ row ][ column ] == card ) {
+ /* cout << setw( 5 ) << right << wFace[ column ]
+ << " of " << setw( 8 ) << left
+ << wSuit[ row ]
+ << ( card % 2 == 0 ? '\n' : '\t' );
+ */
+ karten[card-1].farbe=wSuit[row];
+ karten[card-1].wert=wFace[column];
+ cardFound=TRUE;
+ }
+ column++;
+
+ } // end while
+ row++;
+ }
+ }
+} // end function deal
+
+int onePair(const hand mycards[], const char *myFace[])
+{
+ int faces[13]={0};
+ int pairCounter=0;
+ int pair=0;
+ int n;
+
+ for (int i=0;i<cards;i++)
+ {
+ for (n=0;n<13;n++)
+ if (mycards[i].wert == myFace[n])
+ faces[n]++;
+ }
+ for (n=0;n<13;n++)
+ {
+ if (faces[n]==2)
+ pairCounter++;
+ }
+ if (pairCounter==1)
+ pair=1;
+ return pair;
+}
+
+int twoPairs(const hand mycards[], const char *myFace[])
+{
+ int faces[13]={0};
+ int twoPairs=0;
+ int pairCounter=0;
+ int n;
+
+ for (int i=0;i<cards;i++)
+ {
+ for (n=0;n<13;n++)
+ if (mycards[i].wert == myFace[n])
+ faces[n]++;
+ }
+ for (n=0;n<13;n++)
+ {
+ if (faces[n]==2)
+ pairCounter++;
+ }
+ if (pairCounter==2)
+ twoPairs=1;
+
+ return twoPairs;
+}
+int threeOfAKind(const hand mycards[], const char *myFace[])
+{
+ int faces[13]={0};
+ int toak=0;
+ int n;
+
+ for (int i=0;i<cards;i++)
+ {
+ for (n=0;n<13;n++)
+ if (mycards[i].wert == myFace[n])
+ faces[n]++;
+ }
+ for (n=0;n<13;n++)
+ {
+ if (faces[n]==3)
+ toak=1;
+ }
+ return toak;
+}
+int straight(const hand mycards[], const char *myFace[])
+{
+ int str=0;
+ int n;
+ int faces[13]={0};
+
+ for (int i=0;i<cards;i++)
+ {
+ for (n=0;n<13;n++)
+ if (mycards[i].wert == myFace[n])
+ faces[n]++;
+ }
+ for (n=0;n<13;n++)
+ {
+ if (faces[n]==1 && faces[n+1]==1 && faces[n+2]==1 && faces[n+3]==1 && faces[n+4]==1)
+ str=1;
+ }
+ return str;
+}
+int flush(const hand mycards[], const char *mySuit[])
+{
+ int suits[4]={0};
+ int flush=0;
+ int n;
+ const int countingCards=5;
+
+ for (int i=0;i<cards;i++)
+ {
+ for (n=0;n<4;n++)
+ if (mycards[i].farbe == mySuit[n])
+ suits[n]++;
+ }
+ for (n=0;n<4;n++)
+ {
+ if (suits[n]==countingCards)
+ flush=1;
+ }
+ return flush;
+}
+int fullHouse(const hand mycards[], const char *myFace[])
+{
+ int full=0;
+ if(1==threeOfAKind(mycards,myFace)&&1==twoPairs(mycards,myFace))
+ {
+ full=1;
+ //cout << endl << "Full House" <<endl;
+ }
+ return full;
+}
+int fourOfAKind(const hand mycards[], const char *myFace[])
+{
+ int faces[13]={0};
+ int foak=0;
+ int n;
+
+ for (int i=0;i<cards;i++)
+ {
+ for (n=0;n<13;n++)
+ if (mycards[i].wert == myFace[n])
+ faces[n]++;
+ }
+ for (n=0;n<13;n++)
+ {
+ if (faces[n]==4)
+ {
+ foak=1;
+ }
+ }
+
+ return foak;
+}
+int straightFlush(const hand mycards[], const char *myFace[], const char *mySuit[])
+{
+ int strFlu=0;
+ if (1==straight(mycards,myFace) && 1==flush(mycards,mySuit))
+ {
+ strFlu=1;
+ //printHand(mycards);
+ }
+ return strFlu;
+}
+int royalFlush(const hand mycards[], const char *myFace[], const char *mySuit[])
+{
+ int roy1=0;
+ int roy2=0;
+ int roy=0;
+ int i,n;
+ int faces[13]={0};
+ int suits[4]={0};
+ const int countingCards=5;
+
+ for (i=0;i<cards;i++)
+ {
+ for (n=0;n<13;n++)
+ if (mycards[i].wert == myFace[n])
+ faces[n]++;
+ }
+
+ if (faces[0]==1 && faces[9]==1 && faces[10]==1 && faces[11]==1 && faces[12]==1)
+ roy1=1;
+
+
+ for (i=0;i<cards;i++)
+ {
+ for (n=0;n<4;n++)
+ if (mycards[i].farbe == mySuit[n])
+ suits[n]++;
+ }
+ for (n=0;n<4;n++)
+ {
+ if (suits[n]==countingCards)
+ roy2=1;
+ }
+ if (roy1==1 && roy2==1)
+ {
+ //printHand(mycards);
+ roy=1;
+ }
+ return roy;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsp b/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsp new file mode 100644 index 0000000..5150ad2 --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p5_4" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p5_4 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_4.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p5_4.mak" CFG="prg1p5_4 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p5_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p5_4 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p5_4 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p5_4 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p5_4 - Win32 Release"
+# Name "prg1p5_4 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsw b/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsw new file mode 100644 index 0000000..a01539b --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_4/prg1p5_4.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p5_4"=.\prg1p5_4.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt6.zip b/Bachelor/Prog1/Prakt6.zip Binary files differnew file mode 100644 index 0000000..805d968 --- /dev/null +++ b/Bachelor/Prog1/Prakt6.zip diff --git a/Bachelor/Prog1/Prakt6/index.htm b/Bachelor/Prog1/Prakt6/index.htm new file mode 100644 index 0000000..03c361b --- /dev/null +++ b/Bachelor/Prog1/Prakt6/index.htm @@ -0,0 +1,249 @@ +<html>
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<title>Praktikum 6</title>
+</head>
+
+<body>
+
+<table BORDER CELLSPACING=0 WIDTH="100%" >
+<caption> </caption>
+
+<tr>
+<td WIDTH="25%" BGCOLOR="#EFEFDE">FH Darmstadt
+<br>FB Informatik
+<br>Prof.Dr. H.P.Weber</td>
+
+<td>
+<center><font size="+3">Programmieren I </font>
+<br><font size=+3>Praktikum</font></center>
+</td>
+
+<td WIDTH="25%" BGCOLOR="#EFEFDE">
+<center><font size=+4>6</font></center>
+</td>
+</tr>
+</table>
+
+<br>
+<table border WIDTH="100%" >
+<tr VALIGN=TOP>
+<td>Ziel:</td><td>
+Sie sollen problemangepasste Datentypen als Klassen entwerfen und ein
+ Anwendungsprogramm als System aus Objekten implementieren können.
+</td>
+</tr>
+</table>
+
+<br>
+<table BORDER="1" CELLSPACING=0 WIDTH="100%" height="608" >
+<tr>
+<td COLSPAN = "2" height="60">
+<h3 ALIGN = "left">
+<b>1 Erwärmen eines Tiefkühlgerichts in einer Mikrowelle
+</b>
+</h3>
+
+Realisieren Sie eine Klasse <i>Microwave</i> sowie eine Klasse <i>FrozenMeal</i>:
+</td>
+</tr>
+
+<tr>
+<td WIDTH="370" height="269">
+<table BORDER COLS=1 BGCOLOR="#EFEFDE" ALIGN="center">
+<tr>
+<td>
+<center><b>Microwave</b></center>
+</td>
+</tr>
+
+<tr>
+<td>- power : int
+<br>- volume : int
+<br>- period : double</td>
+</tr>
+
+<tr>
+<td><i>Constructor</i>(a certain volume)
+<br><i>Destructor</i>()
+<br>+ morePower() : void
+<br>+ lessPower() : void
+<br>+ setPeriod(a certain period) : void
+<br>+ heatMeal(a certain FrozenMeal) : void
+<br>+ getPower() : int
+<br>+ getPeriod() : double</td>
+</tr>
+</table>
+</td>
+
+<td WIDTH="400" height="269">
+<table BORDER="1" COLS=1 BGCOLOR="#EFEFDE" ALIGN="center">
+<tr>
+<td>
+<center><b>FrozenMeal</b></center>
+</td>
+</tr>
+
+<tr>
+<td>- name : char* (or string)
+<br>- volume : int
+<br>- temperature : double
+<br>- coeffizient : double</td>
+</tr>
+
+<tr>
+<td><i>Constructor</i>(a certain name, a certain volume)
+<br><i>Destructor</i>()
+<br>+ changeTemperature(a certain temperature) : void
+<br>+ getName() : char* (or string)
+<br>+ getVolume() : int
+<br>+ getCoeffizient() : double
+<br>+ getTemperature() : double</td>
+</tr>
+</table>
+</td>
+</tr>
+
+<td COLSPAN = "2" height="267">
+<br>
+Besonderheiten der Methoden sind:
+<ul>
+<li>
+Durch morePower() und lessPower() soll die Leistung im Bereich
+von minimal 200 W bis maximal 1000 W in Schritten von 200 W geändert
+werden.</li>
+
+<li>
+Das Erwärmen eines Gerichtes wird durch folgenden Zusammenhang beschrieben:<br>
+Temperatur = Anfangstemperatur + ( Koeffizient * Leistung * Zeitdauer
+/ Volumen)</li>
+
+<li>
+Als Erwärmungskoeffizient soll der Wert für Wasser verwendet
+werden: Koeffizient = 0.24 cm<sup>3</sup> * Grad / Ws.</li>
+
+<li>
+Achten Sie auf die Einheiten: am einfachsten ist es, wenn Volumen von Mikrowelle
+und Tiefkühlgericht in cm<sup>3</sup> vom Anwendungsprogramm übernommen
+werden.</li>
+
+<li>
+Beim Erzeugen soll ein Tiefkühlgericht eine Temperatur von -18 Grad
+haben.</li>
+
+<li>
+Die Destruktoren sollen den Endzustand des jeweiligen Objektes am Bildschirm
+ausgeben.</li>
+
+<li>
+Keine Methode der beiden Klassen liest irgendwelche Daten von Tastatur ein oder
+gibt etwas auf den Bildschirm aus. Dafür ist allein das Anwendungsprogramm
+zuständig.</li>
+ </ul>
+<p>Realisieren Sie zum Testen Ihrer Klassen ein <b>Anwendungsprogramm</b>, das mit verschiedenen
+Tiefkühlgerichten und einer geeigneten Mikrowelle die vorhandenen Methoden benutzt.
+</td>
+
+</table>
+
+<br>
+
+<table BORDER="1" CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+<b>2 Tic-Tac-Toe</b></h3>
+
+<p>Entwickeln Sie einen Datentyp <font face="Courier New"><b>TicTacToe</b></font>,
+der es ermöglicht ein vollständiges Programm zum Spielen von Tic-Tac-Toe zu
+schreiben.
+<ul>
+<li>Die Klasse <font face="Courier New"><b>TicTacToe</b></font> soll als <b><font face="Courier New">private</font></b>
+ Attribut
+ ein <b><font face="Courier New">char</font></b>-Array mit neun Elementen enthalten.
+</li>
+<li>
+Der Konstruktor soll ein leeres Spielfeld initialisieren.
+</li>
+<li>
+Die <font face="Courier New"><b>public</b></font> Methode <font face="Courier New"><b>playOneGame</b></font>
+soll den Ablauf eines Tic-Tac-Toe-Spieles realisieren. Dabei soll sie
+verschiedene <b><font face="Courier New">private</font></b> Methoden aufrufen,
+die die verschiedenen Teilaufgaben während des Spielablaufs (Eingaben,
+Ausgaben, Ermitteln eines Siegers, Realisierung einer Strategie für die
+Computerzüge) erledigen.
+</li>
+<li>
+Das Spiel soll für zwei Spieler realisiert werden, wobei der Computer einen der
+beiden Spieler spielt. Der menschliche Spieler soll aussuchen können, ob er
+erster oder zweiter Spieler ist.Wenn der erste
+Spieler zieht, soll ein <b><font face="Courier New">X</font></b> in das
+entsprechende Kästchen gesetzt werden, wenn der zweite Spieler zieht, soll ein <b><font face="Courier New">O</font></b>
+in das entsprechende Kästchen gesetzt werden. Es darf nur in ein leeres
+Kästchen gezogen werden.
+</li>
+<li>
+Nach jedem Zug soll bestimmt werden, ob ein Spieler gewonnen hat oder ob das
+Spiel unentschieden endete.
+</li>
+</ul>
+
+</td>
+</tr>
+</table>
+
+<br>
+
+<table BORDER="1" CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+<b>3 Große Integer-Zahlen (fakultativ)</b></h3>
+
+<p>Entwickeln Sie einen Datentyp <font face="Courier New"><b>Integer40</b></font>,
+der ein Array mit 40 Elementen benutzt, um ganze Zahlen mit bis zu 40 Dezimalstellen zu
+speichern.
+<ul>
+<li>Implemetieren Sie die Methoden <b><font face="Courier New">read</font></b>,
+<b><font face="Courier New">write</font></b>, <font face="Courier New"><b>add</b></font>,
+<font face="Courier New"><b>subtract</b></font>.
+</li>
+<li>
+Für den Vergleich von <font face="Courier New"><b>Integer40</b></font>-Objekten
+sollen die Methoden <font face="Courier New"><b>isEqual</b></font>, <font face="Courier New"><b>isNotEqual</b></font>,
+<font face="Courier New"><b>isGreaterThan</b></font>, <font face="Courier New"><b>
+isSmallerThan</b></font>,
+<font face="Courier New"><b>isGreaterOrEqual</b></font>,
+<font face="Courier New"><b>isSmallerOrEqual</b></font>
+zur Verfügung stehen. Jede dieser Methoden ist eine Prädikat-Funktion, die <font face="Courier New"><b>true</b></font>
+zurückgibt, wenn die entsprechende Beziehung zwischen zwei Objekten stimmt und <font face="Courier New"><b>false</b></font>,
+wenn sie nicht stimmt. Realisieren Sie außerdem eine Prädikat-Funktion <font face="Courier New"><b>
+isZero</b></font>.
+</li>
+</ul>
+<p>Testen Sie Ihre Klasse in einem <b>Anwendungsprogramm</b>, das die
+vorhandenen Operationen mit geeignet gewählten <font face="Courier New"><b>Integer40</b></font>-Objekten
+ausführt.
+</td>
+</tr>
+</table>
+
+<br>
+
+<table BORDER="1" CELLSPACING=0 WIDTH="100%" >
+<tr>
+<td>
+<h3>
+4<b> Übungsklausur (fakultativ)</b></h3>
+<p>
+Als Klausurvorbereitung können Sie die <a href="PG1Klaus.htm">PG 1-Klausur vom letzten Jahr</a> bearbeiten.
+Am besten halten Sie sich dabei auch schon an die <a href="Hinweise.pdf">allgemeinen Hinweise</a>, die Sie
+bei der Klausur am 10.02.05 beachten müssen.</table>
+
+<br>
+
+</body>
+</html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp new file mode 100644 index 0000000..07b7dfd --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.cpp @@ -0,0 +1,30 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 13.01.2005
+// File: frozenm.cpp
+// Description: Implementation of class FrozenMeal
+
+#include "frozenm.h"
+#include "microwave.h"
+#include <iostream>
+using std::cout;
+using std::endl;
+
+FrozenMeal::FrozenMeal(string mealname, int vol) {
+ name=mealname;
+ volume=vol;
+ temperature=-18.0;
+ coefficient=.24;
+ cout << endl << "Constructor of class FrozenMeal for object " << mealname;
+}
+
+FrozenMeal::~FrozenMeal()
+{
+ cout << endl << "Destructor of class FrozenMeal for object " << name
+ << ", Temperature: "<< temperature;
+}
+
+void FrozenMeal::changeTemperature(double &temp)
+{
+ temperature=temp;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h new file mode 100644 index 0000000..7631346 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/frozenm.h @@ -0,0 +1,31 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 13.01.2005
+// File: frozenm.h
+// Description: class FrozenMeal
+
+
+
+#ifndef FROZENM_1
+#define FROZENM_1
+
+#include <string>
+using std::string;
+
+class FrozenMeal {
+public:
+ //FrozenMeal(char *, int);
+ FrozenMeal (string, int);
+ ~FrozenMeal();
+ void changeTemperature(double &);
+ string getName() { return name; }
+ int getVolume() { return volume; }
+ double getCoefficient() { return coefficient; }
+ double getTemperature() { return temperature; }
+private:
+ string name;
+ int volume;
+ double temperature;
+ double coefficient;
+};
+#endif
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp b/Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp new file mode 100644 index 0000000..6c26572 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/main.cpp @@ -0,0 +1,25 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 13.01.2005
+// File: main.cpp
+// Description: Application
+
+#include "frozenm.h"
+#include "microwave.h"
+#include <string>
+
+int main()
+{
+ Microwave micro(22000);
+ FrozenMeal lasagne("Lasagne",200);
+ micro.setPeriod(120.0);
+ micro.morePower();
+ micro.morePower();
+ micro.morePower();
+ micro.heatMeal(lasagne);
+ FrozenMeal something("Something",250);
+ micro.lessPower();
+ micro.setPeriod(180.0);
+ micro.heatMeal(something);
+ return 0;
+}
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h b/Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h new file mode 100644 index 0000000..48d0654 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/microwave.h @@ -0,0 +1,30 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 13.01.2005
+// File: mircowave.h
+// Description: class microwave
+
+#ifndef MICROW_1
+#define MICROW_1
+
+#include "frozenm.h"
+
+class Microwave {
+
+public:
+ Microwave(int = 20000);
+ ~Microwave();
+ void morePower();
+ void lessPower();
+ void setPeriod(double per) { period=per; }
+ void heatMeal(FrozenMeal &);
+ int getPower() { return power;}
+ double getPeriod() { return period; };
+
+private:
+ int power;
+ int volume;
+ double period;
+};
+
+#endif
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp b/Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp new file mode 100644 index 0000000..467a1b3 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/mircowave.cpp @@ -0,0 +1,41 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 13.01.2005
+// File: mircowave.cpp
+// Description: Implementation of class microwave
+
+#include "microwave.h"
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+Microwave::Microwave(int vol)
+{
+ volume=vol;
+ power=200;
+ cout<<endl<<"Constructor class Mircowave";
+}
+
+Microwave::~Microwave()
+{
+ cout << endl << "Destructor class Mircowave: Power is " << getPower() << " Period is " << getPeriod();
+}
+
+void Microwave::morePower()
+{
+ if (getPower() <= 800)
+ power+=200;
+}
+void Microwave::lessPower()
+{
+ if (getPower() >= 400)
+ power-=200;
+}
+
+void Microwave::heatMeal(FrozenMeal &myMeal)
+{
+ double newTemp=myMeal.getTemperature()+((myMeal.getCoefficient()*getPower()*getPeriod())/myMeal.getVolume());
+ if (myMeal.getVolume() <= volume)
+ myMeal.changeTemperature(newTemp);
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp new file mode 100644 index 0000000..672fa8b --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsp @@ -0,0 +1,116 @@ +# Microsoft Developer Studio Project File - Name="prg1p6_1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p6_1 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_1.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_1.mak" CFG="prg1p6_1 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p6_1 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p6_1 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p6_1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p6_1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p6_1 - Win32 Release"
+# Name "prg1p6_1 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\frozenm.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mircowave.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\frozenm.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\microwave.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsw b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsw new file mode 100644 index 0000000..a809ab7 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_1/prg1p6_1.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p6_1"=.\prg1p6_1.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp b/Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp new file mode 100644 index 0000000..79ab352 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/main.cpp @@ -0,0 +1,15 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 14.01.2005
+// File: main.cpp
+// Description: Application for class TicTacToe
+
+#include "tictactoe.h"
+
+int main()
+{
+ TicTacToe game;
+ game.playOneGame();
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp new file mode 100644 index 0000000..3a9b49a --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsp @@ -0,0 +1,108 @@ +# Microsoft Developer Studio Project File - Name="prg1p6_2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p6_2 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_2.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_2.mak" CFG="prg1p6_2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p6_2 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p6_2 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p6_2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p6_2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p6_2 - Win32 Release"
+# Name "prg1p6_2 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\tictactoe.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\tictactoe.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsw b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsw new file mode 100644 index 0000000..3b81189 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/prg1p6_2.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p6_2"=.\prg1p6_2.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp new file mode 100644 index 0000000..0b9693d --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.cpp @@ -0,0 +1,385 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 14.01.2005
+// File: tictactoe.cpp
+// Description: Implementation of class TicTacToe
+
+#include "tictactoe.h"
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::cin;
+
+TicTacToe::TicTacToe()
+:nrFields(9)
+{
+ for (int i=0;i<nrFields;i++)
+ field[i]=static_cast <char> (i+49);
+ winner="";
+ round=0;
+}
+
+TicTacToe::~TicTacToe()
+{
+ cout << endl << "Game Over!" << endl;
+}
+
+void TicTacToe::eraseField()
+{
+ for (int i=0;i<nrFields;i++)
+ field[i]=' ';
+}
+
+void TicTacToe::playOneGame()
+{
+ srand(time(0));
+ welcome();
+ print();
+ eraseField();
+ setBeginner();
+ print();
+ while (""==getWinner())
+ {
+ if("Player" == getNext())
+ {
+ movePlayer();
+ }
+ else
+ {
+ moveComputer();
+
+ }
+ print();
+ setWinner();
+ }
+ printWinner();
+}
+
+void TicTacToe::print()
+{
+
+ cout << endl;
+ for (int i=0;i<nrFields;i+=3)
+ {
+ cout << field[i] << " | "<< field[i+1]<< " | "<< field[i+2]<<endl;
+ if (i<6)
+ {
+ for (int n=0;n<10;n++)
+ cout << "-";
+ cout << endl;
+ }
+ }
+ cout << endl;
+}
+
+void TicTacToe::welcome()
+{
+ cout << endl << "TicTacToe!" << endl <<
+ "To mark a field, just enter the according number ('1' means field one)!" << endl;
+}
+
+void TicTacToe::setWinner()
+{
+ int n=0;
+
+ while (n<7 && ""==getWinner())
+ {
+ if (0==(n%3))
+ {
+ if (field[n]=='X' &&field[n+1]=='X' &&field[n+2]=='X')
+ winner="Player";
+ if (field[n]=='O' &&field[n+1]=='O' &&field[n+2]=='O')
+ winner="Computer";
+ }
+ if (n<=2)
+ {
+ if (field[n]=='X' &&field[n+3]=='X' &&field[n+6]=='X')
+ winner="Player";
+ if (field[n]=='O' &&field[n+3]=='O' &&field[n+6]=='O')
+ winner="Computer";
+ }
+ if (n==0)
+ {
+ if (field[n]=='X' &&field[n+4]=='X' &&field[n+8]=='X')
+ winner="Player";
+ if (field[n]=='O' &&field[n+4]=='O' &&field[n+8]=='O')
+ winner="Computer";
+ }
+ if (n==2)
+ {
+ if (field[n]=='X' &&field[n+2]=='X' &&field[n+4]=='X')
+ winner="Player";
+ if (field[n]=='O' &&field[n+2]=='O' &&field[n+4]=='O')
+ winner="Computer";
+ }
+ n++;
+ }
+ if (round==nrFields && getWinner()=="")
+ {
+ winner="Draw";
+ }
+}
+
+void TicTacToe::setBeginner()
+{
+ char input;
+ cout << endl << "Who has first move?" << endl
+ << "[P]layer or [C]omputer: ";
+ do
+ {
+ cin >> input;
+ switch (input)
+ {
+ case 'p':
+ case 'P':
+ nextPlayer="Player";
+ break;
+ case 'c':
+ case 'C':
+ nextPlayer="Computer";
+ break;
+ default:
+ cout << endl << "Bad selection! Enter new selection: ";
+ }
+ } while (input!='P' && input!='C' && input!='p' && input!='c');
+}
+void TicTacToe::movePlayer()
+{
+ int draw=0;
+ cout << endl << "Enter your move: ";
+ //print();
+ cin >> draw;
+ while (testField(draw-1))
+ {
+ cout << endl << "Irregular move... please enter a new one" << endl;
+ cin >> draw;
+ }
+ field[draw-1]='X';
+ setNext("Computer");
+ round++;
+}
+
+int TicTacToe::testField(int f)
+{
+ if (field[f]==' ')
+ return 0;
+ else
+ return 1;
+}
+
+void TicTacToe::moveComputer()
+{
+ int move=4;
+ int vertX[3]={0};
+ int horX[3]={0};
+ int diagX[2]={0};
+ int vertO[3]={0};
+ int horO[3]={0};
+ int diagO[2]={0};
+ int n=0,
+ x=0,
+ y=0,
+ d=0;
+
+ if (testField(move))
+ {
+ while(testField(n) && n<nrFields)
+ {
+ n+=2;
+ }
+ move=n;
+ }
+
+ if (testField(move))
+ {
+ n=1;
+ while(testField(n) && n<nrFields)
+ {
+ n+=2;
+ }
+ move=n;
+ }
+
+ //defense
+ for (n=0;n<3;n++)
+ if (field[n]=='X')
+ vertX[0]++;
+ for (n=3;n<6;n++)
+ if (field[n]=='X')
+ vertX[1]++;
+ for (n=6;n<9;n++)
+ if (field[n]=='X')
+ vertX[2]++;
+
+ for (n=0;n<=6;n+=3)
+ if (field[n]=='X')
+ horX[0]++;
+ for (n=1;n<=7;n+=3)
+ if (field[n]=='X')
+ horX[1]++;
+ for (n=2;n<=8;n+=3)
+ if (field[n]=='X')
+ horX[2]++;
+
+ for (n=0;n<=8;n+=4)
+ if (field[n]=='X')
+ diagX[0]++;
+ for (n=2;n<=6;n+=2)
+ if (field[n]=='X')
+ diagX[1]++;
+
+ // offense
+
+ for (n=0;n<3;n++)
+ if (field[n]=='O')
+ vertO[0]++;
+ for (n=3;n<6;n++)
+ if (field[n]=='O')
+ vertO[1]++;
+ for (n=6;n<9;n++)
+ if (field[n]=='O')
+ vertO[2]++;
+
+ for (n=0;n<=6;n+=3)
+ if (field[n]=='O')
+ horO[0]++;
+ for (n=1;n<=7;n+=3)
+ if (field[n]=='O')
+ horO[1]++;
+ for (n=2;n<=8;n+=3)
+ if (field[n]=='O')
+ horO[2]++;
+
+ for (n=0;n<=8;n+=4)
+ if (field[n]=='O')
+ diagO[0]++;
+ for (n=2;n<=6;n+=2)
+ if (field[n]=='O')
+ diagO[1]++;
+
+
+ for (n=0;n<3;n++)
+ if (vertX[n]==2 && vertO[n]==0)
+ {
+ switch(n) {
+ case 0: x=n;
+ while (testField(x) && x<nrFields)
+ x++;
+ break;
+ case 1: x=n+2;
+ while (testField(x) && x<nrFields)
+ x++;
+ break;
+ case 2: x=n+5;
+ while (testField(x) && x<nrFields)
+ x++;
+ break;
+ }
+ move=x;
+ }
+ for (n=0;n<3;n++)
+ if (horX[n]==2 && horO[n]==0)
+ {
+ switch(n) {
+ case 0: y=n;
+ while (testField(y)&& y<nrFields)
+ y+=3;
+ break;
+ case 1: y=n;
+ while (testField(y)&& y<nrFields)
+ y+=3;
+ break;
+ case 2: y=n;
+ while (testField(y)&& y<nrFields)
+ y+=3;
+ break;
+ }
+ move=y;
+ }
+ for (n=0;n<2;n++)
+ if (diagX[n]==2 && diagO[n]==0)
+ {
+ switch(n) {
+ case 0: d=n;
+ while (testField(d)&& d<nrFields)
+ d+=4;
+ break;
+ case 1: d=2;
+ while (testField(d)&& d<nrFields)
+ d+=2;
+ break;
+ }
+ move=d;
+ }
+ for (n=0;n<3;n++)
+ if (vertO[n]==2 && vertX[n]==0)
+ {
+ switch(n) {
+ case 0: x=n;
+ while (testField(x) && x<nrFields)
+ x++;
+ break;
+ case 1: x=n+2;
+ while (testField(x) && x<nrFields)
+ x++;
+ break;
+ case 2: x=n+5;
+ while (testField(x) && x<nrFields)
+ x++;
+ break;
+ }
+ move=x;
+ }
+ for (n=0;n<3;n++)
+ if (horO[n]==2 && horX[n]==0)
+ {
+ switch(n) {
+ case 0: y=n;
+ while (testField(y)&& y<nrFields)
+ y+=3;
+ break;
+ case 1: y=n;
+ while (testField(y)&& y<nrFields)
+ y+=3;
+ break;
+ case 2: y=n;
+ while (testField(y)&& y<nrFields)
+ y+=3;
+ break;
+ }
+ move=y;
+ }
+ for (n=0;n<2;n++)
+ if (diagO[n]==2 && diagX[n]==0)
+ {
+ switch(n) {
+ case 0: d=n;
+ while (testField(d)&& d<nrFields)
+ d+=4;
+ break;
+ case 1: d=2;
+ while (testField(d)&& d<nrFields)
+ d+=2;
+ break;
+ }
+ move=d;
+ }
+
+ cout << endl << "Computer moves: ";
+ field[move]='O';
+ //print();
+ setNext("Player");
+ round++;
+}
+
+void TicTacToe::printWinner()
+{
+ system("cls");
+ if (getWinner()!="Draw")
+ cout << getWinner() << " won the match!" << endl;
+ else
+ cout << "Draw Game, no winner!" << endl;
+ print();
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.h b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.h new file mode 100644 index 0000000..27929e8 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_2/tictactoe.h @@ -0,0 +1,36 @@ +// Programmieren 1, Praktikum 6, Aufgabe 1
+// Author: Sven Eisenhauer
+// Date: 14.01.2005
+// File: tictactoe.h
+// Description: class TicTacToe
+
+#ifndef TICTACTOE_1
+#define TICTACTOE_1
+
+class TicTacToe
+{
+public:
+ TicTacToe();
+ ~TicTacToe();
+ void playOneGame();
+private:
+ char field[9];
+ const int nrFields;
+ int round;
+ char *nextPlayer;
+ char *winner;
+ void print();
+ void printWinner();
+ void welcome();
+ void setNext(char *n) {nextPlayer=n;}
+ void setBeginner();
+ void setWinner();
+ char * getNext() {return nextPlayer;}
+ char * getWinner() {return winner;}
+ void movePlayer();
+ void moveComputer();
+ void eraseField();
+ int testField(int);
+};
+
+#endif
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h b/Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h new file mode 100644 index 0000000..c4949f3 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h @@ -0,0 +1,55 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3
+// Author: Sven Eisenhauer
+// Date: 17.01.2005
+// File: Int40.h
+// Description: class Integer40
+
+#ifndef INT40_1
+#define INT40_1
+
+#include<iostream>
+using std::ostream;
+using std::istream;
+
+
+const static int ARRAYSIZE=40;
+
+class Integer40
+{
+public:
+ Integer40();
+ Integer40(const Integer40&);
+ ~Integer40();
+ const Integer40& read();
+ friend istream& operator>> (istream&, Integer40 &);
+ const Integer40& write();
+ friend ostream& operator<< (ostream&, const Integer40&);
+ friend Integer40& operator+ (const Integer40&, const Integer40&);
+ friend Integer40& operator- (const Integer40&, const Integer40&);
+ const Integer40& add(const Integer40&);
+ const Integer40& operator+=(const Integer40&);
+ const Integer40& substract(const Integer40&);
+ const Integer40& operator-=(const Integer40&);
+ const Integer40& operator=(const Integer40&);
+ bool isEqual(const Integer40&) const;
+ bool operator==(const Integer40&) const;
+ bool isNotEqual(const Integer40&) const;
+ bool operator!=(const Integer40&) const;
+ bool isGreaterThan(const Integer40&) const;
+ bool operator>(const Integer40&) const;
+ bool isSmallerThan(const Integer40&) const;
+ bool operator<(const Integer40&) const;
+ bool isGreaterOrEqual(const Integer40&) const;
+ bool operator>=(const Integer40&) const;
+ bool isSmallerOrEqual(const Integer40&) const;
+ bool operator<=(const Integer40&) const;
+ bool isZero();
+ //const Integer40& operator-(const Integer40&);
+ //const Integer40& operator+(const Integer40&);
+
+private:
+ int *int40;
+ //static int nrInt40;
+};
+
+#endif
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp b/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp new file mode 100644 index 0000000..16e3f67 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp @@ -0,0 +1,344 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3
+// Author: Sven Eisenhauer
+// Date: 17.01.2005
+// File: int40.cpp
+// Description: Implementation of class Integer40
+
+#include "int40.h"
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <new>
+
+using std::cout;
+using std::endl;
+using std::cin;
+using std::ostream;
+using std::istream;
+
+
+
+ostream& operator<<(ostream &out, Integer40 &right)
+{
+ right.write();
+
+ return out;
+}
+
+istream& operator>> (istream &in, Integer40 &right)
+{
+ right.read();
+
+ return in;
+}
+
+Integer40& operator+ (const Integer40& left, const Integer40& right)
+{
+ static Integer40 temp;
+
+ int sum=0;
+ int carry=0;
+
+ for (int i=ARRAYSIZE-1;i>=0;i--)
+ {
+ sum=(left.int40[i]+right.int40[i]+carry);
+ if (sum >= 10)
+ {
+ temp.int40[i]=sum%10;
+ carry=1;
+ }
+ else
+ {
+ temp.int40[i]=sum;
+ carry=0;
+ }
+ }
+
+ return temp;
+
+}
+Integer40& operator- (const Integer40& left, const Integer40& right)
+{
+ static Integer40 temp;
+
+ int diff=0;
+ int carry=0;
+
+ for (int i=ARRAYSIZE-1;i>=0;i--)
+ {
+ if (right.int40[i] > left.int40[i])
+ {
+ temp.int40[i]=(left.int40[i]+10)-right.int40[i]-carry;
+ carry=1;
+ }
+ else
+ {
+ temp.int40[i]=left.int40[i]-right.int40[i]-carry;
+ carry=0;
+ }
+
+ }
+
+ return temp;
+}
+
+Integer40::Integer40()
+{
+ int40=new int[ARRAYSIZE];
+ for (int n=0;n<ARRAYSIZE;n++)
+ int40[n]=0;
+// ++nrInt40;
+}
+
+Integer40::Integer40(const Integer40 &toCopy)
+{
+ int40=new int[ARRAYSIZE];
+ for (int n=0;n<ARRAYSIZE;n++)
+ int40[n]=toCopy.int40[n];
+}
+
+Integer40::~Integer40()
+{
+ delete[] int40;
+ //--nrInt40;
+}
+
+const Integer40& Integer40::read()
+{
+ char input[ARRAYSIZE];
+ int i=0;
+ int n=0;
+ int temp[ARRAYSIZE];
+ cout << endl << "Please enter Integer40: ";
+ cin.get(input,ARRAYSIZE);
+ cin.sync();
+ for (n=ARRAYSIZE-strlen(input);n>=0;n--)
+ {
+ temp[n]=0;
+ }
+ i=strlen(input)-1;
+ for (n=ARRAYSIZE-1;n>=ARRAYSIZE-strlen(input);n--)
+ {
+ int40[n]=input[i]-48;
+ i--;
+ }
+ return *this;
+}
+
+const Integer40& Integer40::write()
+{
+ cout << endl;
+ for (int n=0;n<ARRAYSIZE;n++)
+ cout << int40[n];
+ cout << endl;
+
+ return *this;
+}
+
+const Integer40& Integer40::add(const Integer40 &toAdd)
+{
+ int sum=0;
+ int carry=0;
+
+ for (int i=ARRAYSIZE-1;i>=0;i--)
+ {
+ sum=(int40[i]+toAdd.int40[i]+carry);
+ int40[i]=sum%10;
+ if (sum >= 10)
+ carry=1;
+ else
+ carry=0;
+ }
+ return *this;
+}
+
+/*const Integer40& Integer40::operator+(const Integer40 &toAdd)
+{
+ add(toAdd);
+
+ return *this;
+}
+*/
+const Integer40& Integer40::operator+=(const Integer40 &toAdd)
+{
+ add(toAdd);
+
+ return *this;
+}
+
+const Integer40& Integer40::substract(const Integer40 &toSub)
+{
+ int temp=0;
+
+ for (int i=ARRAYSIZE-1;i>=0;i--)
+ {
+ if (toSub.int40[i] > int40[i])
+ {
+ int40[i]=((int40[i])+10)-toSub.int40[i];
+ (int40[i-1])--;
+ }
+ else
+ int40[i]=((int40[i]))-toSub.int40[i];
+
+ }
+ return *this;
+}
+
+/*const Integer40& Integer40::operator-(const Integer40 &toSub)
+{
+ substract(toSub);
+
+ return *this;
+}*/
+
+const Integer40& Integer40::operator-=(const Integer40 &toSub)
+{
+ substract(toSub);
+
+ return *this;
+}
+
+const Integer40& Integer40::operator =(const Integer40 &right)
+{
+ if(&right!=this)
+ {
+ for (int n=0;n<ARRAYSIZE;n++)
+ int40[n]=right.int40[n];
+ }
+
+ return *this;
+}
+
+
+bool Integer40::isGreaterOrEqual(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] < toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+
+bool Integer40::operator>=(const Integer40 &toCompare) const
+{
+ return isGreaterOrEqual(toCompare);
+}
+
+bool Integer40::isSmallerOrEqual(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] > toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+
+bool Integer40::operator<=(const Integer40 &toCompare) const
+{
+ return isSmallerOrEqual(toCompare);
+}
+
+
+bool Integer40::isGreaterThan(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] <= toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+bool Integer40::operator>(const Integer40 &toCompare) const
+{
+ return isGreaterThan(toCompare);
+}
+
+bool Integer40::isSmallerThan(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] >= toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+
+bool Integer40::operator<(const Integer40 &toCompare) const
+{
+ return isSmallerThan(toCompare);;
+}
+
+bool Integer40::isEqual(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] != toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+
+bool Integer40::operator ==(const Integer40 &toCompare) const
+{
+ return isEqual(toCompare);
+}
+
+bool Integer40::isNotEqual(const Integer40 &toCompare) const
+{
+ return !(*this==toCompare);
+}
+
+bool Integer40::operator !=(const Integer40 &toCompare) const
+{
+ return !(*this==toCompare);
+}
+
+bool Integer40::isZero()
+{
+ int i=0;
+ bool retval=true;
+
+ while (i<ARRAYSIZE)
+ {
+ if(this->int40[i]!=0)
+ {
+ retval=false;
+ break;
+ }
+ i++;
+ }
+
+ return retval;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp b/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp new file mode 100644 index 0000000..60b73dc --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp @@ -0,0 +1,74 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3
+// Author: Sven Eisenhauer
+// Date: 17.01.2005
+// File: main.cpp
+// Description: Application to test class Integer40
+
+#include "Int40.h"
+#include <new>
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+
+
+ostream& operator<<(ostream &out, Integer40 &right);
+istream& operator>> (istream &in, Integer40 &right);
+Integer40& operator+ (const Integer40&, const Integer40&);
+Integer40& operator- (const Integer40&, const Integer40&);
+
+int main()
+{
+ Integer40 bigint1;
+ Integer40 bigint2;
+
+ //bigint1.read();
+ cin >> bigint1 >> bigint2;
+ //bigint1.write();
+ //cout << bigint1 ;
+
+ //bigint2.read();
+ //cin >> bigint2;
+ //bigint2.write();
+ cout << bigint1 <<bigint2;
+
+ //bigint1->add(bigint2);
+
+ /*bigint1+=bigint2;
+ cout << bigint1;
+ bigint1-=bigint2;
+ cout << bigint1;
+ */
+
+ cout << bigint1 - bigint2;
+ cout << bigint1 + bigint2;
+
+ if(bigint1 >= bigint2)
+ cout << endl << "BigInt1 is greater or equal BigInt2" << endl;
+ if(bigint1 <= bigint2)
+ cout << endl << "BigInt1 is smaller or equal BigInt2" << endl;
+ if(bigint1 > bigint2)
+ cout << endl << "BigInt1 is greater than BigInt2" << endl;
+ if(bigint1 < bigint2)
+ cout << endl << "BigInt1 is smaller than BigInt2" << endl;
+ if(bigint1 == bigint2)
+ cout << endl << "BigInt1 is equal BigInt2" << endl;
+ if(bigint1.isZero())
+ cout << endl << "BigInt1 is zero" << endl;
+
+ if(bigint2 >= bigint1)
+ cout << endl << "BigInt2 is greater or equal BigInt1" << endl;
+ if(bigint2 <= bigint1)
+ cout << endl << "BigInt2 is smaller or equal BigInt1" << endl;
+ if(bigint2 > bigint1)
+ cout << endl << "BigInt2 is greater than BigInt1" << endl;
+ if(bigint2 < bigint1)
+ cout << endl << "BigInt2 is smaller than BigInt1" << endl;
+ if(bigint2 == bigint1)
+ cout << endl << "BigInt2 is equal BigInt1" << endl;
+ if(bigint2.isZero())
+ cout << endl << "BigInt2 is zero" << endl;
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp new file mode 100644 index 0000000..aec95a9 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp @@ -0,0 +1,108 @@ +# Microsoft Developer Studio Project File - Name="prg1p6_3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p6_3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_3.mak" CFG="prg1p6_3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p6_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p6_3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p6_3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p6_3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p6_3 - Win32 Release"
+# Name "prg1p6_3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\int40.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Int40.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw new file mode 100644 index 0000000..0f372ae --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p6_3"=.\prg1p6_3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Bachelor/Prog1/Vorlesung.htm b/Bachelor/Prog1/Vorlesung.htm new file mode 100644 index 0000000..62dfd47 --- /dev/null +++ b/Bachelor/Prog1/Vorlesung.htm @@ -0,0 +1,31 @@ +<html><head>
+<meta http-equiv="Content-Language" content="de">
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+
+<title>Material zur Vorlesung</title><link href="Vorlesung_files/style.css" type="text/css" rel="stylesheet"></head>
+
+<body>
+
+<p><a href="http://www.fbi.fh-darmstadt.de/%7Eh.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/PG1_inh.htm">Inhaltsübersicht</a></p>
+
+<p><a href="http://www.fbi.fh-darmstadt.de/%7Eh.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/Literatur.htm">Literatur</a></p>
+
+<p><a href="http://www.fbi.fh-darmstadt.de/%7Eh.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/Codierungsstandard.htm">Codierungs-Standard</a></p>
+<p><a href="http://www.fbi.fh-darmstadt.de/%7Eh.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/chap1_8.zip">PowerPoint-Folien</a> (gezipt: 940 kB)<br>
+<font class="Copyright">(Reproduced from the <b><i>PowerPoints</i></b> for <b>C++ How to
+Program 3rd ed, by Deitel and Deitel © 2001 <br>
+</b>and <b>C++ How to Program 4th ed, by Deitel and Deitel © 2003. <br>
+</b>Reproduced by permission of Pearson Education, Inc.)</font></p>
+<p><a href="http://www.fbi.fh-darmstadt.de/%7Eh.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/ex1_8.zip">Code-Beispiele</a> (gezipt: 180 kB)</p>
+
+<p>zusätzliche Beispiele aus der Vorlesung</p>
+
+<p><a href="http://www.fbi.fh-darmstadt.de/%7Eh.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/Op_Prec.htm">Vorrangtabelle für Operatoren</a></p>
+
+<p><a href="http://www.fbi.fh-darmstadt.de/%7Eh.p.weber/Lehrveranstaltungen/PG1_Praktikum/Material/Ascii_Table.htm">ASCII-Tabelle</a></p>
+
+<p> </p>
+
+</body></html>
\ No newline at end of file diff --git a/Bachelor/Prog1/Vorlesung_files/style.css b/Bachelor/Prog1/Vorlesung_files/style.css new file mode 100644 index 0000000..6bb3a39 --- /dev/null +++ b/Bachelor/Prog1/Vorlesung_files/style.css @@ -0,0 +1,54 @@ +BODY {
+ FONT-SIZE: 10pt; MARGIN: 0px 10px 10px 20px; FONT-FAMILY: Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #fffff7; TEXT-ALIGN: left
+}
+FONT {
+ FONT-SIZE: 10pt; FONT-FAMILY: Arial, Helvetica, sans-serif
+}
+FONT.INDEX {
+ FONT-SIZE: 10pt; COLOR: #b05000; FONT-FAMILY: Arial, Helvetica, sans-serif
+}
+TD {
+ FONT-SIZE: 10pt; FONT-FAMILY: Arial, Helvetica, sans-serif
+}
+DL {
+ MARGIN-TOP: 0.4em; MARGIN-BOTTOM: 0.4em
+}
+DT {
+ PADDING-BOTTOM: 0.3em; LINE-HEIGHT: 1em
+}
+.Copyright {
+ FONT-SIZE: 7pt
+}
+.Autor {
+ FONT-SIZE: 8pt
+}
+A {
+ FONT-SIZE: 10pt; FONT-STYLE: normal; FONT-FAMILY: Arial, Helvetica, sans-serif; TEXT-DECORATION: none
+}
+A:link {
+ COLOR: maroon
+}
+A:visited {
+ COLOR: maroon
+}
+A:active {
+ COLOR: #000000
+}
+H1 {
+ FONT-SIZE: 16pt; TEXT-ALIGN: left
+}
+H2 {
+ FONT-SIZE: 14pt; TEXT-ALIGN: left
+}
+H3 {
+ FONT-SIZE: 12pt; TEXT-ALIGN: left
+}
+H4 {
+ FONT-SIZE: 10pt; TEXT-ALIGN: left
+}
+BLOCKQUOTE {
+ FONT-SIZE: 8pt
+}
+CITE {
+ FONT-SIZE: 8pt; FONT-STYLE: normal; FONT-FAMILY: Arial, Helvetica, sans-serif
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/chap1_8.zip b/Bachelor/Prog1/chap1_8.zip Binary files differnew file mode 100644 index 0000000..d9a738f --- /dev/null +++ b/Bachelor/Prog1/chap1_8.zip diff --git a/Bachelor/Prog1/ex1_8.zip b/Bachelor/Prog1/ex1_8.zip Binary files differnew file mode 100644 index 0000000..2d911e3 --- /dev/null +++ b/Bachelor/Prog1/ex1_8.zip diff --git a/Bachelor/Prog1/examples/ch01/Fig01_02.cpp b/Bachelor/Prog1/examples/ch01/Fig01_02.cpp new file mode 100644 index 0000000..4d6b3d4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_02.cpp @@ -0,0 +1,30 @@ +// Fig. 1.2: fig01_02.cpp
+// A first program in C++.
+#include <iostream>
+
+// function main begins program execution
+int main()
+{
+ std::cout << "Welcome to C++!\n";
+
+ return 0; // indicate that program ended successfully
+
+} // end function main
+
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch01/Fig01_04.cpp b/Bachelor/Prog1/examples/ch01/Fig01_04.cpp new file mode 100644 index 0000000..aaee89a --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_04.cpp @@ -0,0 +1,30 @@ +// Fig. 1.4: fig01_04.cpp
+// Printing a line with multiple statements.
+#include <iostream>
+
+// function main begins program execution
+int main()
+{
+ std::cout << "Welcome ";
+ std::cout << "to C++!\n";
+
+ return 0; // indicate that program ended successfully
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch01/Fig01_05.cpp b/Bachelor/Prog1/examples/ch01/Fig01_05.cpp new file mode 100644 index 0000000..6a8d719 --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_05.cpp @@ -0,0 +1,29 @@ +// Fig. 1.5: fig01_05.cpp
+// Printing multiple lines with a single statement.
+#include <iostream>
+
+// function main begins program execution
+int main()
+{
+ std::cout << "Welcome\nto\n\nC++!\n";
+
+ return 0; // indicate that program ended successfully
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch01/Fig01_06.cpp b/Bachelor/Prog1/examples/ch01/Fig01_06.cpp new file mode 100644 index 0000000..403121a --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_06.cpp @@ -0,0 +1,41 @@ +// Fig. 1.6: fig01_06.cpp
+// Addition program.
+#include <iostream>
+
+// function main begins program execution
+int main()
+{
+ int integer1; // first number to be input by user
+ int integer2; // second number to be input by user
+ int sum; // variable in which sum will be stored
+
+ std::cout << "Enter first integer\n"; // prompt
+ std::cin >> integer1; // read an integer
+
+ std::cout << "Enter second integer\n"; // prompt
+ std::cin >> integer2; // read an integer
+
+ sum = integer1 + integer2; // assignment result to sum
+
+ std::cout << "Sum is " << sum << std::endl; // print sum
+
+ return 0; // indicate that program ended successfully
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch01/Fig01_14.cpp b/Bachelor/Prog1/examples/ch01/Fig01_14.cpp new file mode 100644 index 0000000..cb623fb --- /dev/null +++ b/Bachelor/Prog1/examples/ch01/Fig01_14.cpp @@ -0,0 +1,58 @@ +// Fig. 1.14: fig01_14.cpp
+// Using if statements, relational
+// operators, and equality operators.
+#include <iostream>
+
+using std::cout; // program uses cout
+using std::cin; // program uses cin
+using std::endl; // program uses endl
+
+// function main begins program execution
+int main()
+{
+ int num1; // first number to be read from user
+ int num2; // second number to be read from user
+
+ cout << "Enter two integers, and I will tell you\n"
+ << "the relationships they satisfy: ";
+ cin >> num1 >> num2; // read two integers
+
+ if ( num1 == num2 )
+ cout << num1 << " is equal to " << num2 << endl;
+
+ if ( num1 != num2 )
+ cout << num1 << " is not equal to " << num2 << endl;
+
+ if ( num1 < num2 )
+ cout << num1 << " is less than " << num2 << endl;
+
+ if ( num1 > num2 )
+ cout << num1 << " is greater than " << num2 << endl;
+
+ if ( num1 <= num2 )
+ cout << num1 << " is less than or equal to "
+ << num2 << endl;
+
+ if ( num1 >= num2 )
+ cout << num1 << " is greater than or equal to "
+ << num2 << endl;
+
+ return 0; // indicate that program ended successfully
+
+} // end function main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Ex02_05.cpp b/Bachelor/Prog1/examples/ch02/Ex02_05.cpp new file mode 100644 index 0000000..1189989 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_05.cpp @@ -0,0 +1,43 @@ +// Ex. 2.5: ex02_05.cpp
+// Calculate the sum of the integers from 1 to 10.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int sum; // stores sum of integers 1 to 10
+ int x; // counter
+
+ x = 1; // count from 1
+ sum = 0; // initialize sum
+
+ while ( x <= 10 ) {
+ sum += x; // add x to sum
+ ++x; // increment x
+
+ } // end while
+
+ cout << "The sum is: " << sum << endl;
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Ex02_08.cpp b/Bachelor/Prog1/examples/ch02/Ex02_08.cpp new file mode 100644 index 0000000..db9685a --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_08.cpp @@ -0,0 +1,55 @@ +// Ex. 2.8: ex02_08.cpp
+// Raise x to the y power.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int x; // base
+ int y; // exponent
+ int i; // counts from 1 to y
+ int power; // used to calculate x raised to power y
+
+ i = 1; // initialize i to begin counting from 1
+ power = 1; // initialize power
+
+ cout << "Enter base as an integer: "; // prompt for base
+ cin >> x; // input base
+
+ // prompt for exponent
+ cout << "Enter exponent as an integer: ";
+ cin >> y; // input exponent
+
+ // count from 1 to y and multiply power by x each time
+ while ( i <= y ) {
+ power *= x;
+ ++i;
+
+ } // end while
+
+ cout << power << endl; // display result
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Ex02_15.cpp b/Bachelor/Prog1/examples/ch02/Ex02_15.cpp new file mode 100644 index 0000000..63e8e14 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_15.cpp @@ -0,0 +1,44 @@ +// Ex. 2.15: ex02_15.cpp
+// What does this program print?
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int y; // declare y
+ int x = 1; // initialize x
+ int total = 0; // initialize total
+
+ while ( x <= 10 ) { // loop 10 times
+ y = x * x; // perform calculation
+ cout << y << endl; // output result
+ total += y; // add y to total
+ ++x; // increment counter x
+
+ } // end while
+
+ cout << "Total is " << total << endl; // display result
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Ex02_24.cpp b/Bachelor/Prog1/examples/ch02/Ex02_24.cpp new file mode 100644 index 0000000..3faf50c --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_24.cpp @@ -0,0 +1,39 @@ +// Ex. 2.24: ex02_24.cpp
+// What does this program print?
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int count = 1; // initialize count
+
+ while ( count <= 10 ) { // loop 10 times
+
+ // output line of text
+ cout << ( count % 2 ? "****" : "++++++++" )
+ << endl;
+ ++count; // increment count
+ }
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Ex02_25.cpp b/Bachelor/Prog1/examples/ch02/Ex02_25.cpp new file mode 100644 index 0000000..6d4a82a --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_25.cpp @@ -0,0 +1,47 @@ +// Ex. 2.25: ex_02_25.cpp
+// What does this program print?
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int row = 10; // initialize row
+ int column; // declare column
+
+ while ( row >= 1 ) { // loop until row < 1
+ column = 1; // set column to 1 as iteration begins
+
+ while ( column <= 10 ) { // loop 10 times
+ cout << ( row % 2 ? "<" : ">" ); // output
+ ++column; // increment column
+
+ } // end inner while
+
+ --row; // decrement row
+ cout << endl; // begin new output line
+
+ } // end outer while
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Ex02_42.cpp b/Bachelor/Prog1/examples/ch02/Ex02_42.cpp new file mode 100644 index 0000000..3c3b514 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Ex02_42.cpp @@ -0,0 +1,47 @@ +// Ex. 2.42: ex02_42.cpp
+// What does this program print?
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int x, // declare x
+ y; // declare y
+
+ // prompt user for input
+ cout << "Enter two integers in the range 1-20: ";
+ cin >> x >> y; // read values for x and y
+
+ for ( int i = 1; i <= y; i++ ) { // count from 1 to y
+
+ for ( int j = 1; j <= x; j++ ) // count from 1 to x
+ cout << '@'; // output @
+
+ cout << endl; // begin new line
+
+ } // end outer for
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_07.cpp b/Bachelor/Prog1/examples/ch02/Fig02_07.cpp new file mode 100644 index 0000000..eac7fce --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_07.cpp @@ -0,0 +1,54 @@ +// Fig. 2.7: fig02_07.cpp
+// Class average program with counter-controlled repetition.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int total; // sum of grades input by user
+ int gradeCounter; // number of grade to be entered next
+ int grade; // grade value
+ int average; // average of grades
+
+ // initialization phase
+ total = 0; // initialize total
+ gradeCounter = 1; // initialize loop counter
+
+ // processing phase
+ while ( gradeCounter <= 10 ) { // loop 10 times
+ cout << "Enter grade: "; // prompt for input
+ cin >> grade; // read grade from user
+ total = total + grade; // add grade to total
+ gradeCounter = gradeCounter + 1; // increment counter
+ }
+
+ // termination phase
+ average = total / 10; // integer division
+
+ // display result
+ cout << "Class average is " << average << endl;
+
+ return 0; // indicate program ended successfully
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_09.cpp b/Bachelor/Prog1/examples/ch02/Fig02_09.cpp new file mode 100644 index 0000000..a0c1065 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_09.cpp @@ -0,0 +1,76 @@ +// Fig. 2.9: fig02_09.cpp
+// Class average program with sentinel-controlled repetition.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+using std::fixed;
+
+#include <iomanip> // parameterized stream manipulators
+
+using std::setprecision; // sets numeric output precision
+
+// function main begins program execution
+int main()
+{
+ int total; // sum of grades
+ int gradeCounter; // number of grades entered
+ int grade; // grade value
+
+ double average; // number with decimal point for average
+
+ // initialization phase
+ total = 0; // initialize total
+ gradeCounter = 0; // initialize loop counter
+
+ // processing phase
+ // get first grade from user
+ cout << "Enter grade, -1 to end: "; // prompt for input
+ cin >> grade; // read grade from user
+
+ // loop until sentinel value read from user
+ while ( grade != -1 ) {
+ total = total + grade; // add grade to total
+ gradeCounter = gradeCounter + 1; // increment counter
+
+ cout << "Enter grade, -1 to end: "; // prompt for input
+ cin >> grade; // read next grade
+
+ } // end while
+
+ // termination phase
+ // if user entered at least one grade ...
+ if ( gradeCounter != 0 ) {
+
+ // calculate average of all grades entered
+ average = static_cast< double >( total ) / gradeCounter;
+
+ // display average with two digits of precision
+ cout << "Class average is " << setprecision( 2 )
+ << fixed << average << endl;
+
+ } // end if part of if/else
+
+ else // if no grades were entered, output appropriate message
+ cout << "No grades were entered" << endl;
+
+ return 0; // indicate program ended successfully
+
+} // end function main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_11.cpp b/Bachelor/Prog1/examples/ch02/Fig02_11.cpp new file mode 100644 index 0000000..5cf6523 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_11.cpp @@ -0,0 +1,64 @@ +// Fig. 2.11: fig02_11.cpp
+// Analysis of examination results.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ // initialize variables in declarations
+ int passes = 0; // number of passes
+ int failures = 0; // number of failures
+ int studentCounter = 1; // student counter
+ int result; // one exam result
+
+ // process 10 students using counter-controlled loop
+ while ( studentCounter <= 10 ) {
+
+ // prompt user for input and obtain value from user
+ cout << "Enter result (1 = pass, 2 = fail): ";
+ cin >> result;
+
+ // if result 1, increment passes; if/else nested in while
+ if ( result == 1 ) // if/else nested in while
+ passes = passes + 1;
+
+ else // if result not 1, increment failures
+ failures = failures + 1;
+
+ // increment studentCounter so loop eventually terminates
+ studentCounter = studentCounter + 1;
+
+ } // end while
+
+ // termination phase; display number of passes and failures
+ cout << "Passed " << passes << endl;
+ cout << "Failed " << failures << endl;
+
+ // if more than eight students passed, print "raise tuition"
+ if ( passes > 8 )
+ cout << "Raise tuition " << endl;
+
+ return 0; // successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_14.cpp b/Bachelor/Prog1/examples/ch02/Fig02_14.cpp new file mode 100644 index 0000000..b56633a --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_14.cpp @@ -0,0 +1,44 @@ +// Fig. 2.14: fig02_14.cpp
+// Preincrementing and postincrementing.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int c; // declare variable
+
+ // demonstrate postincrement
+ c = 5; // assign 5 to c
+ cout << c << endl; // print 5
+ cout << c++ << endl; // print 5 then postincrement
+ cout << c << endl << endl; // print 6
+
+ // demonstrate preincrement
+ c = 5; // assign 5 to c
+ cout << c << endl; // print 5
+ cout << ++c << endl; // preincrement then print 6
+ cout << c << endl; // print 6
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_16.cpp b/Bachelor/Prog1/examples/ch02/Fig02_16.cpp new file mode 100644 index 0000000..a1998b0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_16.cpp @@ -0,0 +1,38 @@ +// Fig. 2.16: fig02_16.cpp
+// Counter-controlled repetition.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int counter = 1; // initialization
+
+ while ( counter <= 10 ) { // repetition condition
+ cout << counter << endl; // display counter
+ ++counter; // increment
+
+ } // end while
+
+ return 0; // successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_17.cpp b/Bachelor/Prog1/examples/ch02/Fig02_17.cpp new file mode 100644 index 0000000..26e9a9f --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_17.cpp @@ -0,0 +1,36 @@ +// Fig. 2.17: fig02_17.cpp
+// Counter-controlled repetition with the for structure.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ // Initialization, repetition condition and incrementing
+ // are all included in the for structure header.
+
+ for ( int counter = 1; counter <= 10; counter++ )
+ cout << counter << endl;
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_20.cpp b/Bachelor/Prog1/examples/ch02/Fig02_20.cpp new file mode 100644 index 0000000..6a8081f --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_20.cpp @@ -0,0 +1,38 @@ +// Fig. 2.20: fig02_20.cpp
+// Summation with for.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int sum = 0; // initialize sum
+
+ // sum even integers from 2 through 100
+ for ( int number = 2; number <= 100; number += 2 )
+ sum += number; // add number to sum
+
+ cout << "Sum is " << sum << endl; // output sum
+ return 0; // successful termination
+
+} // end function main
+
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_21.cpp b/Bachelor/Prog1/examples/ch02/Fig02_21.cpp new file mode 100644 index 0000000..d27d6e8 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_21.cpp @@ -0,0 +1,60 @@ +// Fig. 2.21: fig02_21.cpp
+// Calculating compound interest.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::ios;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setw;
+using std::setprecision;
+
+#include <cmath> // enables program to use function pow
+
+// function main begins program execution
+int main()
+{
+ double amount; // amount on deposit
+ double principal = 1000.0; // starting principal
+ double rate = .05; // interest rate
+
+ // output table column heads
+ cout << "Year" << setw( 21 ) << "Amount on deposit" << endl;
+
+ // set floating-point number format
+ cout << fixed << setprecision( 2 );
+
+ // calculate amount on deposit for each of ten years
+ for ( int year = 1; year <= 10; year++ ) {
+
+ // calculate new amount for specified year
+ amount = principal * pow( 1.0 + rate, year );
+
+ // output one table row
+ cout << setw( 4 ) << year
+ << setw( 21 ) << amount << endl;
+
+ } // end for
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_22.cpp b/Bachelor/Prog1/examples/ch02/Fig02_22.cpp new file mode 100644 index 0000000..025f666 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_22.cpp @@ -0,0 +1,95 @@ +// Fig. 2.22: fig02_22.cpp
+// Counting letter grades.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int grade; // one grade
+ int aCount = 0; // number of As
+ int bCount = 0; // number of Bs
+ int cCount = 0; // number of Cs
+ int dCount = 0; // number of Ds
+ int fCount = 0; // number of Fs
+
+ cout << "Enter the letter grades." << endl
+ << "Enter the EOF character to end input." << endl;
+
+ // loop until user types end-of-file key sequence
+ while ( ( grade = cin.get() ) != EOF ) {
+
+ // determine which grade was input
+ switch ( grade ) { // switch structure nested in while
+
+ case 'A': // grade was uppercase A
+ case 'a': // or lowercase a
+ ++aCount; // increment aCount
+ break; // necessary to exit switch
+
+ case 'B': // grade was uppercase B
+ case 'b': // or lowercase b
+ ++bCount; // increment bCount
+ break; // exit switch
+
+ case 'C': // grade was uppercase C
+ case 'c': // or lowercase c
+ ++cCount; // increment cCount
+ break; // exit switch
+
+ case 'D': // grade was uppercase D
+ case 'd': // or lowercase d
+ ++dCount; // increment dCount
+ break; // exit switch
+
+ case 'F': // grade was uppercase F
+ case 'f': // or lowercase f
+ ++fCount; // increment fCount
+ break; // exit switch
+
+ case '\n': // ignore newlines,
+ case '\t': // tabs,
+ case ' ': // and spaces in input
+ break; // exit switch
+
+ default: // catch all other characters
+ cout << "Incorrect letter grade entered."
+ << " Enter a new grade." << endl;
+ break; // optional; will exit switch anyway
+
+ } // end switch
+
+ } // end while
+
+ // output summary of results
+ cout << "\n\nTotals for each letter grade are:"
+ << "\nA: " << aCount // display number of A grades
+ << "\nB: " << bCount // display number of B grades
+ << "\nC: " << cCount // display number of C grades
+ << "\nD: " << dCount // display number of D grades
+ << "\nF: " << fCount // display number of F grades
+ << endl;
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_24.cpp b/Bachelor/Prog1/examples/ch02/Fig02_24.cpp new file mode 100644 index 0000000..23724b7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_24.cpp @@ -0,0 +1,39 @@ +// Fig. 2.24: fig02_24.cpp
+// Using the do/while repetition structure.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ int counter = 1; // initialize counter
+
+ do {
+ cout << counter << " "; // display counter
+ } while ( ++counter <= 10 ); // end do/while
+
+ cout << endl;
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_26.cpp b/Bachelor/Prog1/examples/ch02/Fig02_26.cpp new file mode 100644 index 0000000..a17fd07 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_26.cpp @@ -0,0 +1,46 @@ +// Fig. 2.26: fig02_26.cpp
+// Using the break statement in a for structure.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+
+ int x; // x declared here so it can be used after the loop
+
+ // loop 10 times
+ for ( x = 1; x <= 10; x++ ) {
+
+ // if x is 5, terminate loop
+ if ( x == 5 )
+ break; // break loop only if x is 5
+
+ cout << x << " "; // display value of x
+
+ } // end for
+
+ cout << "\nBroke out of loop when x became " << x << endl;
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch02/Fig02_27.cpp b/Bachelor/Prog1/examples/ch02/Fig02_27.cpp new file mode 100644 index 0000000..9504968 --- /dev/null +++ b/Bachelor/Prog1/examples/ch02/Fig02_27.cpp @@ -0,0 +1,45 @@ +// Fig. 2.27: fig02_27.cpp
+// Using the continue statement in a for structure.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function main begins program execution
+int main()
+{
+ // loop 10 times
+ for ( int x = 1; x <= 10; x++ ) {
+
+ // if x is 5, continue with next iteration of loop
+ if ( x == 5 )
+ continue; // skip remaining code in loop body
+
+ cout << x << " "; // display value of x
+
+ } // end for structure
+
+ cout << "\nUsed continue to skip printing the value 5"
+ << endl;
+
+ return 0; // indicate successful termination
+
+} // end function main
+
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Ex03_02.cpp b/Bachelor/Prog1/examples/ch03/Ex03_02.cpp new file mode 100644 index 0000000..cb1f501 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_02.cpp @@ -0,0 +1,41 @@ +// Exercise 3.2: ex03_02.cpp
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int cube( int y ); // function prototype
+
+int main()
+{
+ int x;
+
+ // loop 10 times, calculate cube of x and output results
+ for ( x = 1; x <= 10; x++ )
+ cout << cube( x ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// definition of function cube
+int cube( int y )
+{
+ return y * y * y;
+}
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Ex03_03.cpp b/Bachelor/Prog1/examples/ch03/Ex03_03.cpp new file mode 100644 index 0000000..af9b320 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_03.cpp @@ -0,0 +1,67 @@ +// Exercise 3.3: ex03_03.cpp
+// Testing the math library functions.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setprecision;
+
+#include <cmath>
+
+int main()
+{
+ cout << fixed << setprecision( 1 );
+
+ cout << "sqrt(" << 900.0 << ") = " << sqrt( 900.0 )
+ << "\nsqrt(" << 9.0 << ") = " << sqrt( 9.0 );
+ cout << "\nexp(" << 1.0 << ") = " << setprecision( 6 )
+ << exp( 1.0 ) << "\nexp(" << setprecision( 1 ) << 2.0
+ << ") = " << setprecision( 6 ) << exp( 2.0 );
+ cout << "\nlog(" << 2.718282 << ") = " << setprecision( 1 )
+ << log( 2.718282 )
+ << "\nlog(" << setprecision( 6 ) << 7.389056 << ") = "
+ << setprecision( 1 ) << log( 7.389056 );
+ cout << "\nlog10(" << 1.0 << ") = " << log10( 1.0 )
+ << "\nlog10(" << 10.0 << ") = " << log10( 10.0 )
+ << "\nlog10(" << 100.0 << ") = " << log10( 100.0 ) ;
+ cout << "\nfabs(" << 13.5 << ") = " << fabs( 13.5 )
+ << "\nfabs(" << 0.0 << ") = " << fabs( 0.0 )
+ << "\nfabs(" << -13.5 << ") = " << fabs( -13.5 );
+ cout << "\nceil(" << 9.2 << ") = " << ceil( 9.2 )
+ << "\nceil(" << -9.8 << ") = " << ceil( -9.8 );
+ cout << "\nfloor(" << 9.2 << ") = " << floor( 9.2 )
+ << "\nfloor(" << -9.8 << ") = " << floor( -9.8 );
+ cout << "\npow(" << 2.0 << ", " << 7.0 << ") = "
+ << pow( 2.0, 7.0 ) << "\npow(" << 9.0 << ", "
+ << 0.5 << ") = " << pow( 9.0, 0.5 );
+ cout << setprecision(3) << "\nfmod("
+ << 13.675 << ", " << 2.333 << ") = "
+ << fmod( 13.675, 2.333 ) << setprecision( 1 );
+ cout << "\nsin(" << 0.0 << ") = " << sin( 0.0 );
+ cout << "\ncos(" << 0.0 << ") = " << cos( 0.0 );
+ cout << "\ntan(" << 0.0 << ") = " << tan( 0.0 ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Ex03_10.cpp b/Bachelor/Prog1/examples/ch03/Ex03_10.cpp new file mode 100644 index 0000000..466ad86 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_10.cpp @@ -0,0 +1,53 @@ +// Exercise 3.10: ex03_10.cpp
+// Inline function that calculates the volume of a sphere.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include <cmath>
+
+// define global constant PI
+const double PI = 3.14159;
+
+// calculates volume of a sphere
+inline double sphereVolume( const double radius )
+{
+ return 4.0 / 3.0 * PI * pow( radius, 3 );
+
+} // end inline function sphereVolume
+
+int main()
+{
+ double radiusValue;
+
+ // prompt user for radius
+ cout << "Enter the length of the radius of your sphere: ";
+ cin >> radiusValue; // input radius
+
+ // use radiusValue to calculate volume of sphere
+ // and display result
+ cout << "Volume of sphere with radius " << radiusValue
+ << " is " << sphereVolume( radiusValue ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Ex03_49.cpp b/Bachelor/Prog1/examples/ch03/Ex03_49.cpp new file mode 100644 index 0000000..faaf62f --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_49.cpp @@ -0,0 +1,36 @@ +// Exercise 3.49: ex03_49.cpp
+// What is wrong with this program?
+#include <iostream>
+
+using std::cin;
+using std::cout;
+
+int main()
+{
+ int c;
+
+ if ( ( c = cin.get() ) != EOF ) {
+ main();
+ cout << c;
+ }
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Ex03_50.cpp b/Bachelor/Prog1/examples/ch03/Ex03_50.cpp new file mode 100644 index 0000000..c887d3d --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Ex03_50.cpp @@ -0,0 +1,51 @@ +// Exercise 3.50: ex03_50.cpp
+// What does this program do?
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+int mystery( int, int ); // function prototype
+
+int main()
+{
+ int x, y;
+
+ cout << "Enter two integers: ";
+ cin >> x >> y;
+ cout << "The result is " << mystery( x, y ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// Parameter b must be a positive
+// integer to prevent infinite recursion
+int mystery( int a, int b )
+{
+ // base case
+ if ( b == 1 )
+ return a;
+
+ // recursive step
+ else
+ return a + mystery( a, b - 1 );
+
+} // end function mystery
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_03.cpp b/Bachelor/Prog1/examples/ch03/Fig03_03.cpp new file mode 100644 index 0000000..271802e --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_03.cpp @@ -0,0 +1,45 @@ +// Fig. 3.3: fig03_03.cpp
+// Creating and using a programmer-defined function.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int square( int ); // function prototype
+
+int main()
+{
+ // loop 10 times and calculate and output
+ // square of x each time
+ for ( int x = 1; x <= 10; x++ )
+ cout << square( x ) << " "; // function call
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// square function definition returns square of an integer
+int square( int y ) // y is a copy of argument to function
+{
+ return y * y; // returns square of y as an int
+
+} // end function square
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_04.cpp b/Bachelor/Prog1/examples/ch03/Fig03_04.cpp new file mode 100644 index 0000000..d9e27f3 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_04.cpp @@ -0,0 +1,60 @@ +// Fig. 3.4: fig03_04.cpp
+// Finding the maximum of three floating-point numbers.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+double maximum( double, double, double ); // function prototype
+
+int main()
+{
+ double number1;
+ double number2;
+ double number3;
+
+ cout << "Enter three floating-point numbers: ";
+ cin >> number1 >> number2 >> number3;
+
+ // number1, number2 and number3 are arguments to
+ // the maximum function call
+ cout << "Maximum is: "
+ << maximum( number1, number2, number3 ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// function maximum definition;
+// x, y and z are parameters
+double maximum( double x, double y, double z )
+{
+ double max = x; // assume x is largest
+
+ if ( y > max ) // if y is larger,
+ max = y; // assign y to max
+
+ if ( z > max ) // if z is larger,
+ max = z; // assign z to max
+
+ return max; // max is largest value
+
+} // end function maximum
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_07.cpp b/Bachelor/Prog1/examples/ch03/Fig03_07.cpp new file mode 100644 index 0000000..4971cc4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_07.cpp @@ -0,0 +1,46 @@ +// Fig. 3.7: fig03_07.cpp
+// Shifted, scaled integers produced by 1 + rand() % 6.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <cstdlib> // contains function prototype for rand
+
+int main()
+{
+ // loop 20 times
+ for ( int counter = 1; counter <= 20; counter++ ) {
+
+ // pick random number from 1 to 6 and output it
+ cout << setw( 10 ) << ( 1 + rand() % 6 );
+
+ // if counter divisible by 5, begin new line of output
+ if ( counter % 5 == 0 )
+ cout << endl;
+
+ } // end for structure
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch03/Fig03_08.cpp b/Bachelor/Prog1/examples/ch03/Fig03_08.cpp new file mode 100644 index 0000000..8bb489e --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_08.cpp @@ -0,0 +1,89 @@ +// Fig. 3.8: fig03_08.cpp
+// Roll a six-sided die 6000 times.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <cstdlib> // contains function prototype for rand
+
+int main()
+{
+ int frequency1 = 0;
+ int frequency2 = 0;
+ int frequency3 = 0;
+ int frequency4 = 0;
+ int frequency5 = 0;
+ int frequency6 = 0;
+ int face; // represents one roll of the die
+
+ // loop 6000 times and summarize results
+ for ( int roll = 1; roll <= 6000; roll++ ) {
+ face = 1 + rand() % 6; // random number from 1 to 6
+
+ // determine face value and increment appropriate counter
+ switch ( face ) {
+
+ case 1: // rolled 1
+ ++frequency1;
+ break;
+
+ case 2: // rolled 2
+ ++frequency2;
+ break;
+
+ case 3: // rolled 3
+ ++frequency3;
+ break;
+
+ case 4: // rolled 4
+ ++frequency4;
+ break;
+
+ case 5: // rolled 5
+ ++frequency5;
+ break;
+
+ case 6: // rolled 6
+ ++frequency6;
+ break;
+
+ default: // invalid value
+ cout << "Program should never get here!";
+
+ } // end switch
+
+ } // end for
+
+ // display results in tabular format
+ cout << "Face" << setw( 13 ) << "Frequency"
+ << "\n 1" << setw( 13 ) << frequency1
+ << "\n 2" << setw( 13 ) << frequency2
+ << "\n 3" << setw( 13 ) << frequency3
+ << "\n 4" << setw( 13 ) << frequency4
+ << "\n 5" << setw( 13 ) << frequency5
+ << "\n 6" << setw( 13 ) << frequency6 << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_09.cpp b/Bachelor/Prog1/examples/ch03/Fig03_09.cpp new file mode 100644 index 0000000..5ea5fb6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_09.cpp @@ -0,0 +1,54 @@ +// Fig. 3.9: fig03_09.cpp
+// Randomizing die-rolling program.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+// contains prototypes for functions srand and rand
+#include <cstdlib>
+
+int main()
+{
+ unsigned seed;
+
+ cout << "Enter seed: ";
+ cin >> seed;
+ srand( seed ); // seed random number generator
+
+ // loop 10 times
+ for ( int counter = 1; counter <= 10; counter++ ) {
+
+ // pick random number from 1 to 6 and output it
+ cout << setw( 10 ) << ( 1 + rand() % 6 );
+
+ // if counter divisible by 5, begin new line of output
+ if ( counter % 5 == 0 )
+ cout << endl;
+
+ } // end for
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_10.cpp b/Bachelor/Prog1/examples/ch03/Fig03_10.cpp new file mode 100644 index 0000000..5ebbd59 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_10.cpp @@ -0,0 +1,111 @@ +// Fig. 3.10: fig03_10.cpp
+// Craps.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+#include <ctime> // contains prototype for function time
+
+int rollDice( void ); // function prototype
+
+int main()
+{
+ // enumeration constants represent game status
+ enum Status { CONTINUE, WON, LOST };
+
+ int sum;
+ int myPoint;
+
+ Status gameStatus; // can contain CONTINUE, WON or LOST
+
+ // randomize random number generator using current time
+ srand( time( 0 ) );
+
+ sum = rollDice(); // first roll of the dice
+
+ // determine game status and point based on sum of dice
+ switch ( sum ) {
+
+ // win on first roll
+ case 7:
+ case 11:
+ gameStatus = WON;
+ break;
+
+ // lose on first roll
+ case 2:
+ case 3:
+ case 12:
+ gameStatus = LOST;
+ break;
+
+ // remember point
+ default:
+ gameStatus = CONTINUE;
+ myPoint = sum;
+ cout << "Point is " << myPoint << endl;
+ break; // optional
+
+ } // end switch
+
+ // while game not complete ...
+ while ( gameStatus == CONTINUE ) {
+ sum = rollDice(); // roll dice again
+
+ // determine game status
+ if ( sum == myPoint ) // win by making point
+ gameStatus = WON;
+ else
+ if ( sum == 7 ) // lose by rolling 7
+ gameStatus = LOST;
+
+ } // end while
+
+ // display won or lost message
+ if ( gameStatus == WON )
+ cout << "Player wins" << endl;
+ else
+ cout << "Player loses" << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// roll dice, calculate sum and display results
+int rollDice( void )
+{
+ int die1;
+ int die2;
+ int workSum;
+
+ die1 = 1 + rand() % 6; // pick random die1 value
+ die2 = 1 + rand() % 6; // pick random die2 value
+ workSum = die1 + die2; // sum die1 and die2
+
+ // display results of this roll
+ cout << "Player rolled " << die1 << " + " << die2
+ << " = " << workSum << endl;
+
+ return workSum; // return sum of dice
+
+} // end function rollDice
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_12.cpp b/Bachelor/Prog1/examples/ch03/Fig03_12.cpp new file mode 100644 index 0000000..593c27a --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_12.cpp @@ -0,0 +1,96 @@ +// Fig. 3.12: fig03_12.cpp
+// A scoping example.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void useLocal( void ); // function prototype
+void useStaticLocal( void ); // function prototype
+void useGlobal( void ); // function prototype
+
+int x = 1; // global variable
+
+int main()
+{
+ int x = 5; // local variable to main
+
+ cout << "local x in main's outer scope is " << x << endl;
+
+ { // start new scope
+
+ int x = 7;
+
+ cout << "local x in main's inner scope is " << x << endl;
+
+ } // end new scope
+
+ cout << "local x in main's outer scope is " << x << endl;
+
+ useLocal(); // useLocal has local x
+ useStaticLocal(); // useStaticLocal has static local x
+ useGlobal(); // useGlobal uses global x
+ useLocal(); // useLocal reinitializes its local x
+ useStaticLocal(); // static local x retains its prior value
+ useGlobal(); // global x also retains its value
+
+ cout << "\nlocal x in main is " << x << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// useLocal reinitializes local variable x during each call
+void useLocal( void )
+{
+ int x = 25; // initialized each time useLocal is called
+
+ cout << endl << "local x is " << x
+ << " on entering useLocal" << endl;
+ ++x;
+ cout << "local x is " << x
+ << " on exiting useLocal" << endl;
+
+} // end function useLocal
+
+// useStaticLocal initializes static local variable x only the
+// first time the function is called; value of x is saved
+// between calls to this function
+void useStaticLocal( void )
+{
+ // initialized first time useStaticLocal is called.
+ static int x = 50;
+
+ cout << endl << "local static x is " << x
+ << " on entering useStaticLocal" << endl;
+ ++x;
+ cout << "local static x is " << x
+ << " on exiting useStaticLocal" << endl;
+
+} // end function useStaticLocal
+
+// useGlobal modifies global variable x during each call
+void useGlobal( void )
+{
+ cout << endl << "global x is " << x
+ << " on entering useGlobal" << endl;
+ x *= 10;
+ cout << "global x is " << x
+ << " on exiting useGlobal" << endl;
+
+} // end function useGlobal
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_14.cpp b/Bachelor/Prog1/examples/ch03/Fig03_14.cpp new file mode 100644 index 0000000..ca4f128 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_14.cpp @@ -0,0 +1,52 @@ +// Fig. 3.14: fig03_14.cpp
+// Recursive factorial function.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+unsigned long factorial( unsigned long ); // function prototype
+
+int main()
+{
+ // Loop 10 times. During each iteration, calculate
+ // factorial( i ) and display result.
+ for ( int i = 0; i <= 10; i++ )
+ cout << setw( 2 ) << i << "! = "
+ << factorial( i ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// recursive definition of function factorial
+unsigned long factorial( unsigned long number )
+{
+ // base case
+ if ( number <= 1 )
+ return 1;
+
+ // recursive step
+ else
+ return number * factorial( number - 1 );
+
+} // end function factorial
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_15.cpp b/Bachelor/Prog1/examples/ch03/Fig03_15.cpp new file mode 100644 index 0000000..3882d55 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_15.cpp @@ -0,0 +1,56 @@ +// Fig. 3.15: fig03_15.cpp
+// Recursive fibonacci function.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+unsigned long fibonacci( unsigned long ); // function prototype
+
+int main()
+{
+ unsigned long result, number;
+
+ // obtain integer from user
+ cout << "Enter an integer: ";
+ cin >> number;
+
+ // calculate fibonacci value for number input by user
+ result = fibonacci( number );
+
+ // display result
+ cout << "Fibonacci(" << number << ") = " << result << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// recursive definition of function fibonacci
+unsigned long fibonacci( unsigned long n )
+{
+ // base case
+ if ( n == 0 || n == 1 )
+ return n;
+
+ // recursive step
+ else
+ return fibonacci( n - 1 ) + fibonacci( n - 2 );
+
+} // end function fibonacci
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_18.cpp b/Bachelor/Prog1/examples/ch03/Fig03_18.cpp new file mode 100644 index 0000000..9e5781c --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_18.cpp @@ -0,0 +1,50 @@ +// Fig. 3.18: fig03_18.cpp
+// Functions that take no arguments.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void function1(); // function prototype
+void function2( void ); // function prototype
+
+int main()
+{
+ function1(); // call function1 with no arguments
+ function2(); // call function2 with no arguments
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// function1 uses an empty parameter list to specify that
+// the function receives no arguments
+void function1()
+{
+ cout << "function1 takes no arguments" << endl;
+
+} // end function1
+
+// function2 uses a void parameter list to specify that
+// the function receives no arguments
+void function2( void )
+{
+ cout << "function2 also takes no arguments" << endl;
+
+} // end function2
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_19.cpp b/Bachelor/Prog1/examples/ch03/Fig03_19.cpp new file mode 100644 index 0000000..e785534 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_19.cpp @@ -0,0 +1,50 @@ +// Fig. 3.19: fig03_19.cpp
+// Using an inline function to calculate.
+// the volume of a cube.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// Definition of inline function cube. Definition of function
+// appears before function is called, so a function prototype
+// is not required. First line of function definition acts as
+// the prototype.
+inline double cube( const double side )
+{
+ return side * side * side; // calculate cube
+
+} // end function cube
+
+int main()
+{
+ cout << "Enter the side length of your cube: ";
+
+ double sideValue;
+
+ cin >> sideValue;
+
+ // calculate cube of sideValue and display result
+ cout << "Volume of cube with side "
+ << sideValue << " is " << cube( sideValue ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_20.cpp b/Bachelor/Prog1/examples/ch03/Fig03_20.cpp new file mode 100644 index 0000000..e94ca30 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_20.cpp @@ -0,0 +1,61 @@ +// Fig. 3.20: fig03_20.cpp
+// Comparing pass-by-value and pass-by-reference
+// with references.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int squareByValue( int ); // function prototype
+void squareByReference( int & ); // function prototype
+
+int main()
+{
+ int x = 2;
+ int z = 4;
+
+ // demonstrate squareByValue
+ cout << "x = " << x << " before squareByValue\n";
+ cout << "Value returned by squareByValue: "
+ << squareByValue( x ) << endl;
+ cout << "x = " << x << " after squareByValue\n" << endl;
+
+ // demonstrate squareByReference
+ cout << "z = " << z << " before squareByReference" << endl;
+ squareByReference( z );
+ cout << "z = " << z << " after squareByReference" << endl;
+
+ return 0; // indicates successful termination
+} // end main
+
+// squareByValue multiplies number by itself, stores the
+// result in number and returns the new value of number
+int squareByValue( int number )
+{
+ return number *= number; // caller's argument not modified
+
+} // end function squareByValue
+
+// squareByReference multiplies numberRef by itself and
+// stores the result in the variable to which numberRef
+// refers in function main
+void squareByReference( int &numberRef )
+{
+ numberRef *= numberRef; // caller's argument modified
+
+} // end function squareByReference
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_21.cpp b/Bachelor/Prog1/examples/ch03/Fig03_21.cpp new file mode 100644 index 0000000..4e1af15 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_21.cpp @@ -0,0 +1,37 @@ +// Fig. 3.21: fig03_21.cpp
+// References must be initialized.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int x = 3;
+
+ // y refers to (is an alias for) x
+ int &y = x;
+
+ cout << "x = " << x << endl << "y = " << y << endl;
+ y = 7;
+ cout << "x = " << x << endl << "y = " << y << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_22.cpp b/Bachelor/Prog1/examples/ch03/Fig03_22.cpp new file mode 100644 index 0000000..90ab6a9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_22.cpp @@ -0,0 +1,35 @@ +// Fig. 3.22: fig03_22.cpp
+// References must be initialized.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int x = 3;
+ int &y; // Error: y must be initialized
+
+ cout << "x = " << x << endl << "y = " << y << endl;
+ y = 7;
+ cout << "x = " << x << endl << "y = " << y << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_23.cpp b/Bachelor/Prog1/examples/ch03/Fig03_23.cpp new file mode 100644 index 0000000..b3cffc5 --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_23.cpp @@ -0,0 +1,54 @@ +// Fig. 3.23: fig03_23.cpp
+// Using default arguments.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function prototype that specifies default arguments
+int boxVolume( int length = 1, int width = 1, int height = 1 );
+
+int main()
+{
+ // no arguments--use default values for all dimensions
+ cout << "The default box volume is: " << boxVolume();
+
+ // specify length; default width and height
+ cout << "\n\nThe volume of a box with length 10,\n"
+ << "width 1 and height 1 is: " << boxVolume( 10 );
+
+ // specify length and width; default height
+ cout << "\n\nThe volume of a box with length 10,\n"
+ << "width 5 and height 1 is: " << boxVolume( 10, 5 );
+
+ // specify all arguments
+ cout << "\n\nThe volume of a box with length 10,\n"
+ << "width 5 and height 2 is: " << boxVolume( 10, 5, 2 )
+ << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// function boxVolume calculates the volume of a box
+int boxVolume( int length, int width, int height )
+{
+ return length * width * height;
+
+} // end function boxVolume
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_24.cpp b/Bachelor/Prog1/examples/ch03/Fig03_24.cpp new file mode 100644 index 0000000..b1fa28b --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_24.cpp @@ -0,0 +1,44 @@ +// Fig. 3.24: fig03_24.cpp
+// Using the unary scope resolution operator.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setprecision;
+
+// define global constant PI
+const double PI = 3.14159265358979;
+
+int main()
+{
+ // define local constant PI
+ const float PI = static_cast< float >( ::PI );
+
+ // display values of local and global PI constants
+ cout << setprecision( 20 )
+ << " Local float value of PI = " << PI
+ << "\nGlobal double value of PI = " << ::PI << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_25.cpp b/Bachelor/Prog1/examples/ch03/Fig03_25.cpp new file mode 100644 index 0000000..2539aee --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_25.cpp @@ -0,0 +1,50 @@ +// Fig. 3.25: fig03_25.cpp
+// Using overloaded functions.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// function square for int values
+int square( int x )
+{
+ cout << "Called square with int argument: " << x << endl;
+ return x * x;
+
+} // end int version of function square
+
+// function square for double values
+double square( double y )
+{
+ cout << "Called square with double argument: " << y << endl;
+ return y * y;
+
+} // end double version of function square
+
+int main()
+{
+ int intResult = square( 7 ); // calls int version
+ double doubleResult = square( 7.5 ); // calls double version
+
+ cout << "\nThe square of integer 7 is " << intResult
+ << "\nThe square of double 7.5 is " << doubleResult
+ << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_26.cpp b/Bachelor/Prog1/examples/ch03/Fig03_26.cpp new file mode 100644 index 0000000..5b2fdec --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_26.cpp @@ -0,0 +1,50 @@ +// Fig. 3.26: fig03_26.cpp
+// Name mangling.
+
+// function square for int values
+int square( int x )
+{
+ return x * x;
+}
+
+// function square for double values
+double square( double y )
+{
+ return y * y;
+}
+
+// function that receives arguments of types
+// int, float, char and int *
+void nothing1( int a, float b, char c, int *d )
+{
+ // empty function body
+}
+
+// function that receives arguments of types
+// char, int, float * and double *
+char *nothing2( char a, int b, float *c, double *d )
+{
+ return 0;
+}
+
+int main()
+{
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch03/Fig03_27.cpp b/Bachelor/Prog1/examples/ch03/Fig03_27.cpp new file mode 100644 index 0000000..13a671f --- /dev/null +++ b/Bachelor/Prog1/examples/ch03/Fig03_27.cpp @@ -0,0 +1,76 @@ +// Fig. 3.27: fig03_27.cpp
+// Using a function template.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// definition of function template maximum
+template < class T > // or template< typename T >
+T maximum( T value1, T value2, T value3 )
+{
+ T max = value1;
+
+ if ( value2 > max )
+ max = value2;
+
+ if ( value3 > max )
+ max = value3;
+
+ return max;
+
+} // end function template maximum
+
+int main()
+{
+ // demonstrate maximum with int values
+ int int1, int2, int3;
+
+ cout << "Input three integer values: ";
+ cin >> int1 >> int2 >> int3;
+
+ // invoke int version of maximum
+ cout << "The maximum integer value is: "
+ << maximum( int1, int2, int3 );
+
+ // demonstrate maximum with double values
+ double double1, double2, double3;
+
+ cout << "\n\nInput three double values: ";
+ cin >> double1 >> double2 >> double3;
+
+ // invoke double version of maximum
+ cout << "The maximum double value is: "
+ << maximum( double1, double2, double3 );
+
+ // demonstrate maximum with char values
+ char char1, char2, char3;
+
+ cout << "\n\nInput three characters: ";
+ cin >> char1 >> char2 >> char3;
+
+ // invoke char version of maximum
+ cout << "The maximum character value is: "
+ << maximum( char1, char2, char3 )
+ << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Ex04_18.cpp b/Bachelor/Prog1/examples/ch04/Ex04_18.cpp new file mode 100644 index 0000000..9ccbc6e --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Ex04_18.cpp @@ -0,0 +1,49 @@ +// Ex. 4.18: ex04_18.cpp
+// What does this program do?
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int whatIsThis( int [], int ); // function prototype
+
+int main()
+{
+ const int arraySize = 10;
+ int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+
+ int result = whatIsThis( a, arraySize );
+
+ cout << "Result is " << result << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// What does this function do?
+int whatIsThis( int b[], int size )
+{
+ // base case
+ if ( size == 1 )
+ return b[ 0 ];
+
+ // recursive step
+ else
+ return b[ size - 1 ] + whatIsThis( b, size - 1 );
+
+} // end function whatIsThis
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Ex04_21.cpp b/Bachelor/Prog1/examples/ch04/Ex04_21.cpp new file mode 100644 index 0000000..06c3e49 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Ex04_21.cpp @@ -0,0 +1,47 @@ +// Ex. 4.21: ex04_21.cpp
+// What does this program do?
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void someFunction( int [], int, int ); // function prototype
+
+int main()
+{
+ const int arraySize = 10;
+ int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+
+ cout << "The values in the array are:" << endl;
+ someFunction( a, 0, arraySize );
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// What does this function do?
+void someFunction( int b[], int current, int size )
+{
+ if ( current < size ) {
+ someFunction( b, current + 1, size );
+ cout << b[ current ] << " ";
+ }
+
+} // end function someFunction
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_03.cpp b/Bachelor/Prog1/examples/ch04/Fig04_03.cpp new file mode 100644 index 0000000..9dffb95 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_03.cpp @@ -0,0 +1,44 @@ +// Fig. 4.3: fig04_03.cpp
+// Initializing an array.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+int main()
+{
+ int n[ 10 ]; // n is an array of 10 integers
+
+ // initialize elements of array n to 0
+ for ( int i = 0; i < 10; i++ )
+ n[ i ] = 0; // set element at location i to 0
+
+ cout << "Element" << setw( 13 ) << "Value" << endl;
+
+ // output contents of array n in tabular format
+ for ( int j = 0; j < 10; j++ )
+ cout << setw( 7 ) << j << setw( 13 ) << n[ j ] << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_04.cpp b/Bachelor/Prog1/examples/ch04/Fig04_04.cpp new file mode 100644 index 0000000..6f6efb0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_04.cpp @@ -0,0 +1,42 @@ +// Fig. 4.4: fig04_04.cpp
+// Initializing an array with a declaration.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+int main()
+{
+ // use initializer list to initialize array n
+ int n[ 10 ] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
+
+ cout << "Element" << setw( 13 ) << "Value" << endl;
+
+ // output contents of array n in tabular format
+ for ( int i = 0; i < 10; i++ )
+ cout << setw( 7 ) << i << setw( 13 ) << n[ i ] << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_05.cpp b/Bachelor/Prog1/examples/ch04/Fig04_05.cpp new file mode 100644 index 0000000..4905155 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_05.cpp @@ -0,0 +1,46 @@ +// Fig. 4.5: fig04_05.cpp
+// Initialize array s to the even integers from 2 to 20.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+int main()
+{
+ // constant variable can be used to specify array size
+ const int arraySize = 10;
+
+ int s[ arraySize ]; // array s has 10 elements
+
+ for ( int i = 0; i < arraySize; i++ ) // set the values
+ s[ i ] = 2 + 2 * i;
+
+ cout << "Element" << setw( 13 ) << "Value" << endl;
+
+ // output contents of array s in tabular format
+ for ( int j = 0; j < arraySize; j++ )
+ cout << setw( 7 ) << j << setw( 13 ) << s[ j ] << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_06.cpp b/Bachelor/Prog1/examples/ch04/Fig04_06.cpp new file mode 100644 index 0000000..f62da85 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_06.cpp @@ -0,0 +1,35 @@ +// Fig. 4.6: fig04_06.cpp
+// Using a properly initialized constant variable.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ const int x = 7; // initialized constant variable
+
+ cout << "The value of constant variable x is: "
+ << x << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_07.cpp b/Bachelor/Prog1/examples/ch04/Fig04_07.cpp new file mode 100644 index 0000000..bc1cc0c --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_07.cpp @@ -0,0 +1,29 @@ +// Fig. 4.7: fig04_07.cpp
+// A const object must be initialized.
+
+int main()
+{
+ const int x; // Error: x must be initialized
+
+ x = 7; // Error: cannot modify a const variable
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_08.cpp b/Bachelor/Prog1/examples/ch04/Fig04_08.cpp new file mode 100644 index 0000000..bda7cc0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_08.cpp @@ -0,0 +1,41 @@ +// Fig. 4.8: fig04_08.cpp
+// Compute the sum of the elements of the array.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ const int arraySize = 10;
+
+ int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+
+ int total = 0;
+
+ // sum contents of array a
+ for ( int i = 0; i < arraySize; i++ )
+ total += a[ i ];
+
+ cout << "Total of array element values is " << total << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_09.cpp b/Bachelor/Prog1/examples/ch04/Fig04_09.cpp new file mode 100644 index 0000000..1b722e9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_09.cpp @@ -0,0 +1,49 @@ +// Fig. 4.9: fig04_09.cpp
+// Histogram printing program.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+int main()
+{
+ const int arraySize = 10;
+ int n[ arraySize ] = { 19, 3, 15, 7, 11, 9, 13, 5, 17, 1 };
+
+ cout << "Element" << setw( 13 ) << "Value"
+ << setw( 17 ) << "Histogram" << endl;
+
+ // for each element of array n, output a bar in histogram
+ for ( int i = 0; i < arraySize; i++ ) {
+ cout << setw( 7 ) << i << setw( 13 )
+ << n[ i ] << setw( 9 );
+
+ for ( int j = 0; j < n[ i ]; j++ ) // print one bar
+ cout << '*';
+
+ cout << endl; // start next line of output
+
+ } // end outer for structure
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_10.cpp b/Bachelor/Prog1/examples/ch04/Fig04_10.cpp new file mode 100644 index 0000000..9984df6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_10.cpp @@ -0,0 +1,53 @@ +// Fig. 4.10: fig04_10.cpp
+// Roll a six-sided die 6000 times.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <cstdlib>
+#include <ctime>
+
+int main()
+{
+ const int arraySize = 7;
+ int frequency[ arraySize ] = { 0 };
+
+ srand( time( 0 ) ); // seed random-number generator
+
+ // roll die 6000 times
+ for ( int roll = 1; roll <= 6000; roll++ )
+ ++frequency[ 1 + rand() % 6 ]; // replaces 20-line switch
+ // of Fig. 3.8
+
+ cout << "Face" << setw( 13 ) << "Frequency" << endl;
+
+ // output frequency elements 1-6 in tabular format
+ for ( int face = 1; face < arraySize; face++ )
+ cout << setw( 4 ) << face
+ << setw( 13 ) << frequency[ face ] << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_11.cpp b/Bachelor/Prog1/examples/ch04/Fig04_11.cpp new file mode 100644 index 0000000..86eba62 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_11.cpp @@ -0,0 +1,58 @@ +// Fig. 4.11: fig04_11.cpp
+// Student poll program.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+int main()
+{
+ // define array sizes
+ const int responseSize = 40; // size of array responses
+ const int frequencySize = 11; // size of array frequency
+
+ // place survey responses in array responses
+ int responses[ responseSize ] = { 1, 2, 6, 4, 8, 5, 9, 7, 8,
+ 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7,
+ 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10 };
+
+ // initialize frequency counters to 0
+ int frequency[ frequencySize ] = { 0 };
+
+ // for each answer, select value of an element of array
+ // responses and use that value as subscript in array
+ // frequency to determine element to increment
+ for ( int answer = 0; answer < responseSize; answer++ )
+ ++frequency[ responses[answer] ];
+
+ // display results
+ cout << "Rating" << setw( 17 ) << "Frequency" << endl;
+
+ // output frequencies in tabular format
+ for ( int rating = 1; rating < frequencySize; rating++ )
+ cout << setw( 6 ) << rating
+ << setw( 17 ) << frequency[ rating ] << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_12.cpp b/Bachelor/Prog1/examples/ch04/Fig04_12.cpp new file mode 100644 index 0000000..115d033 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_12.cpp @@ -0,0 +1,49 @@ +// Fig. 4_12: fig04_12.cpp
+// Treating character arrays as strings.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+int main()
+{
+ char string1[ 20 ]; // reserves 20 characters
+ char string2[] = "string literal"; // reserves 15 characters
+
+ // read string from user into array string2
+ cout << "Enter the string \"hello there\": ";
+ cin >> string1; // reads "hello" [space terminates input]
+
+ // output strings
+ cout << "string1 is: " << string1
+ << "\nstring2 is: " << string2;
+
+ cout << "\nstring1 with spaces between characters is:\n";
+
+ // output characters until null character is reached
+ for ( int i = 0; string1[ i ] != '\0'; i++ )
+ cout << string1[ i ] << ' ';
+
+ cin >> string1; // reads "there"
+ cout << "\nstring1 is: " << string1 << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_13.cpp b/Bachelor/Prog1/examples/ch04/Fig04_13.cpp new file mode 100644 index 0000000..ed21456 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_13.cpp @@ -0,0 +1,82 @@ +// Fig. 4.13: fig04_13.cpp
+// Static arrays are initialized to zero.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void staticArrayInit( void ); // function prototype
+void automaticArrayInit( void ); // function prototype
+
+int main()
+{
+ cout << "First call to each function:\n";
+ staticArrayInit();
+ automaticArrayInit();
+
+ cout << "\n\nSecond call to each function:\n";
+ staticArrayInit();
+ automaticArrayInit();
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// function to demonstrate a static local array
+void staticArrayInit( void )
+{
+ // initializes elements to 0 first time function is called
+ static int array1[ 3 ];
+
+ cout << "\nValues on entering staticArrayInit:\n";
+
+ // output contents of array1
+ for ( int i = 0; i < 3; i++ )
+ cout << "array1[" << i << "] = " << array1[ i ] << " ";
+
+ cout << "\nValues on exiting staticArrayInit:\n";
+
+ // modify and output contents of array1
+ for ( int j = 0; j < 3; j++ )
+ cout << "array1[" << j << "] = "
+ << ( array1[ j ] += 5 ) << " ";
+
+} // end function staticArrayInit
+
+// function to demonstrate an automatic local array
+void automaticArrayInit( void )
+{
+ // initializes elements each time function is called
+ int array2[ 3 ] = { 1, 2, 3 };
+
+ cout << "\n\nValues on entering automaticArrayInit:\n";
+
+ // output contents of array2
+ for ( int i = 0; i < 3; i++ )
+ cout << "array2[" << i << "] = " << array2[ i ] << " ";
+
+ cout << "\nValues on exiting automaticArrayInit:\n";
+
+ // modify and output contents of array2
+ for ( int j = 0; j < 3; j++ )
+ cout << "array2[" << j << "] = "
+ << ( array2[ j ] += 5 ) << " ";
+
+} // end function automaticArrayInit
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_14.cpp b/Bachelor/Prog1/examples/ch04/Fig04_14.cpp new file mode 100644 index 0000000..a1db3ea --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_14.cpp @@ -0,0 +1,87 @@ +// Fig. 4.14: fig04_14.cpp
+// Passing arrays and individual array elements to functions.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+void modifyArray( int [], int ); // appears strange
+void modifyElement( int );
+
+int main()
+{
+ const int arraySize = 5; // size of array a
+ int a[ arraySize ] = { 0, 1, 2, 3, 4 }; // initialize a
+
+ cout << "Effects of passing entire array by reference:"
+ << "\n\nThe values of the original array are:\n";
+
+ // output original array
+ for ( int i = 0; i < arraySize; i++ )
+ cout << setw( 3 ) << a[ i ];
+
+ cout << endl;
+
+ // pass array a to modifyArray by reference
+ modifyArray( a, arraySize );
+
+ cout << "The values of the modified array are:\n";
+
+ // output modified array
+ for ( int j = 0; j < arraySize; j++ )
+ cout << setw( 3 ) << a[ j ];
+
+ // output value of a[ 3 ]
+ cout << "\n\n\n"
+ << "Effects of passing array element by value:"
+ << "\n\nThe value of a[3] is " << a[ 3 ] << '\n';
+
+ // pass array element a[ 3 ] by value
+ modifyElement( a[ 3 ] );
+
+ // output value of a[ 3 ]
+ cout << "The value of a[3] is " << a[ 3 ] << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// in function modifyArray, "b" points to
+// the original array "a" in memory
+void modifyArray( int b[], int sizeOfArray )
+{
+ // multiply each array element by 2
+ for ( int k = 0; k < sizeOfArray; k++ )
+ b[ k ] *= 2;
+
+} // end function modifyArray
+
+// in function modifyElement, "e" is a local copy of
+// array element a[ 3 ] passed from main
+void modifyElement( int e )
+{
+ // multiply parameter by 2
+ cout << "Value in modifyElement is "
+ << ( e *= 2 ) << endl;
+
+} // end function modifyElement
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_15.cpp b/Bachelor/Prog1/examples/ch04/Fig04_15.cpp new file mode 100644 index 0000000..5d35b9d --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_15.cpp @@ -0,0 +1,46 @@ +// Fig. 4.15: fig04_15.cpp
+// Demonstrating the const type qualifier.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void tryToModifyArray( const int [] ); // function prototype
+
+int main()
+{
+ int a[] = { 10, 20, 30 };
+
+ tryToModifyArray( a );
+
+ cout << a[ 0 ] << ' ' << a[ 1 ] << ' ' << a[ 2 ] << '\n';
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// In function tryToModifyArray, "b" cannot be used
+// to modify the original array "a" in main.
+void tryToModifyArray( const int b[] )
+{
+ b[ 0 ] /= 2; // error
+ b[ 1 ] /= 2; // error
+ b[ 2 ] /= 2; // error
+
+} // end function tryToModifyArray
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_16.cpp b/Bachelor/Prog1/examples/ch04/Fig04_16.cpp new file mode 100644 index 0000000..e009daf --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_16.cpp @@ -0,0 +1,65 @@ +// Fig. 4.16: fig04_16.cpp
+// This program sorts an array's values into ascending order.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+int main()
+{
+ const int arraySize = 10; // size of array a
+ int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
+ int hold; // temporary location used to swap array elements
+
+ cout << "Data items in original order\n";
+
+ // output original array
+ for ( int i = 0; i < arraySize; i++ )
+ cout << setw( 4 ) << a[ i ];
+
+ // bubble sort
+ // loop to control number of passes
+ for ( int pass = 0; pass < arraySize - 1; pass++ )
+
+ // loop to control number of comparisons per pass
+ for ( int j = 0; j < arraySize - 1; j++ )
+
+ // compare side-by-side elements and swap them if
+ // first element is greater than second element
+ if ( a[ j ] > a[ j + 1 ] ) {
+ hold = a[ j ];
+ a[ j ] = a[ j + 1 ];
+ a[ j + 1 ] = hold;
+
+ } // end if
+
+ cout << "\nData items in ascending order\n";
+
+ // output sorted array
+ for ( int k = 0; k < arraySize; k++ )
+ cout << setw( 4 ) << a[ k ];
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_17.cpp b/Bachelor/Prog1/examples/ch04/Fig04_17.cpp new file mode 100644 index 0000000..c6442c1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_17.cpp @@ -0,0 +1,193 @@ +// Fig. 4.17: fig04_17.cpp
+// This program introduces the topic of survey data analysis.
+// It computes the mean, median, and mode of the data.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setw;
+using std::setprecision;
+
+void mean( const int [], int );
+void median( int [], int );
+void mode( int [], int [], int );
+void bubbleSort( int[], int );
+void printArray( const int[], int );
+
+int main()
+{
+ const int responseSize = 99; // size of array responses
+
+ int frequency[ 10 ] = { 0 }; // initialize array frequency
+
+ // initialize array responses
+ int response[ responseSize ] =
+ { 6, 7, 8, 9, 8, 7, 8, 9, 8, 9,
+ 7, 8, 9, 5, 9, 8, 7, 8, 7, 8,
+ 6, 7, 8, 9, 3, 9, 8, 7, 8, 7,
+ 7, 8, 9, 8, 9, 8, 9, 7, 8, 9,
+ 6, 7, 8, 7, 8, 7, 9, 8, 9, 2,
+ 7, 8, 9, 8, 9, 8, 9, 7, 5, 3,
+ 5, 6, 7, 2, 5, 3, 9, 4, 6, 4,
+ 7, 8, 9, 6, 8, 7, 8, 9, 7, 8,
+ 7, 4, 4, 2, 5, 3, 8, 7, 5, 6,
+ 4, 5, 6, 1, 6, 5, 7, 8, 7 };
+
+ // process responses
+ mean( response, responseSize );
+ median( response, responseSize );
+ mode( frequency, response, responseSize );
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// calculate average of all response values
+void mean( const int answer[], int arraySize )
+{
+ int total = 0;
+
+ cout << "********\n Mean\n********\n";
+
+ // total response values
+ for ( int i = 0; i < arraySize; i++ )
+ total += answer[ i ];
+
+ // format and output results
+ cout << fixed << setprecision( 4 );
+
+ cout << "The mean is the average value of the data\n"
+ << "items. The mean is equal to the total of\n"
+ << "all the data items divided by the number\n"
+ << "of data items (" << arraySize
+ << "). The mean value for\nthis run is: "
+ << total << " / " << arraySize << " = "
+ << static_cast< double >( total ) / arraySize
+ << "\n\n";
+
+} // end function mean
+
+// sort array and determine median element's value
+void median( int answer[], int size )
+{
+ cout << "\n********\n Median\n********\n"
+ << "The unsorted array of responses is";
+
+ printArray( answer, size ); // output unsorted array
+
+ bubbleSort( answer, size ); // sort array
+
+ cout << "\n\nThe sorted array is";
+ printArray( answer, size ); // output sorted array
+
+ // display median element
+ cout << "\n\nThe median is element " << size / 2
+ << " of\nthe sorted " << size
+ << " element array.\nFor this run the median is "
+ << answer[ size / 2 ] << "\n\n";
+
+} // end function median
+
+// determine most frequent response
+void mode( int freq[], int answer[], int size )
+{
+ int largest = 0; // represents largest frequency
+ int modeValue = 0; // represents most frequent response
+
+ cout << "\n********\n Mode\n********\n";
+
+ // initialize frequencies to 0
+ for ( int i = 1; i <= 9; i++ )
+ freq[ i ] = 0;
+
+ // summarize frequencies
+ for ( int j = 0; j < size; j++ )
+ ++freq[ answer[ j ] ];
+
+ // output headers for result columns
+ cout << "Response" << setw( 11 ) << "Frequency"
+ << setw( 19 ) << "Histogram\n\n" << setw( 55 )
+ << "1 1 2 2\n" << setw( 56 )
+ << "5 0 5 0 5\n\n";
+
+ // output results
+ for ( int rating = 1; rating <= 9; rating++ ) {
+ cout << setw( 8 ) << rating << setw( 11 )
+ << freq[ rating ] << " ";
+
+ // keep track of mode value and largest fequency value
+ if ( freq[ rating ] > largest ) {
+ largest = freq[ rating ];
+ modeValue = rating;
+
+ } // end if
+
+ // output histogram bar representing frequency value
+ for ( int k = 1; k <= freq[ rating ]; k++ )
+ cout << '*';
+
+ cout << '\n'; // begin new line of output
+
+ } // end outer for
+
+ // display the mode value
+ cout << "The mode is the most frequent value.\n"
+ << "For this run the mode is " << modeValue
+ << " which occurred " << largest << " times." << endl;
+
+} // end function mode
+
+// function that sorts an array with bubble sort algorithm
+void bubbleSort( int a[], int size )
+{
+ int hold; // temporary location used to swap elements
+
+ // loop to control number of passes
+ for ( int pass = 1; pass < size; pass++ )
+
+ // loop to control number of comparisons per pass
+ for ( int j = 0; j < size - 1; j++ )
+
+ // swap elements if out of order
+ if ( a[ j ] > a[ j + 1 ] ) {
+ hold = a[ j ];
+ a[ j ] = a[ j + 1 ];
+ a[ j + 1 ] = hold;
+
+ } // end if
+
+} // end function bubbleSort
+
+// output array contents (20 values per row)
+void printArray( const int a[], int size )
+{
+ for ( int i = 0; i < size; i++ ) {
+
+ if ( i % 20 == 0 ) // begin new line every 20 values
+ cout << endl;
+
+ cout << setw( 2 ) << a[ i ];
+
+ } // end for
+
+} // end function printArray
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_19.cpp b/Bachelor/Prog1/examples/ch04/Fig04_19.cpp new file mode 100644 index 0000000..0be6aa3 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_19.cpp @@ -0,0 +1,63 @@ +// Fig. 4.19: fig04_19.cpp
+// Linear search of an array.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+int linearSearch( const int [], int, int ); // prototype
+
+int main()
+{
+ const int arraySize = 100; // size of array a
+ int a[ arraySize ]; // create array a
+ int searchKey; // value to locate in a
+
+ for ( int i = 0; i < arraySize; i++ ) // create some data
+ a[ i ] = 2 * i;
+
+ cout << "Enter integer search key: ";
+ cin >> searchKey;
+
+ // attempt to locate searchKey in array a
+ int element = linearSearch( a, searchKey, arraySize );
+
+ // display results
+ if ( element != -1 )
+ cout << "Found value in element " << element << endl;
+ else
+ cout << "Value not found" << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// compare key to every element of array until location is
+// found or until end of array is reached; return subscript of
+// element if key or -1 if key not found
+int linearSearch( const int array[], int key, int sizeOfArray )
+{
+ for ( int j = 0; j < sizeOfArray; j++ )
+
+ if ( array[ j ] == key ) // if found,
+ return j; // return location of key
+
+ return -1; // key not found
+
+} // end function linearSearch
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_20.cpp b/Bachelor/Prog1/examples/ch04/Fig04_20.cpp new file mode 100644 index 0000000..241c800 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_20.cpp @@ -0,0 +1,142 @@ +// Fig. 4.20: fig04_20.cpp
+// Binary search of an array.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+// function prototypes
+int binarySearch( const int [], int, int, int, int );
+void printHeader( int );
+void printRow( const int [], int, int, int, int );
+
+int main()
+{
+ const int arraySize = 15; // size of array a
+ int a[ arraySize ]; // create array a
+ int key; // value to locate in a
+
+ for ( int i = 0; i < arraySize; i++ ) // create some data
+ a[ i ] = 2 * i;
+
+ cout << "Enter a number between 0 and 28: ";
+ cin >> key;
+
+ printHeader( arraySize );
+
+ // search for key in array a
+ int result =
+ binarySearch( a, key, 0, arraySize - 1, arraySize );
+
+ // display results
+ if ( result != -1 )
+ cout << '\n' << key << " found in array element "
+ << result << endl;
+ else
+ cout << '\n' << key << " not found" << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// function to perform binary search of an array
+int binarySearch( const int b[], int searchKey, int low,
+ int high, int size )
+{
+ int middle;
+
+ // loop until low subscript is greater than high subscript
+ while ( low <= high ) {
+
+ // determine middle element of subarray being searched
+ middle = ( low + high ) / 2;
+
+ // display subarray used in this loop iteration
+ printRow( b, low, middle, high, size );
+
+ // if searchKey matches middle element, return middle
+ if ( searchKey == b[ middle ] ) // match
+ return middle;
+
+ else
+
+ // if searchKey less than middle element,
+ // set new high element
+ if ( searchKey < b[ middle ] )
+ high = middle - 1; // search low end of array
+
+ // if searchKey greater than middle element,
+ // set new low element
+ else
+ low = middle + 1; // search high end of array
+ }
+
+ return -1; // searchKey not found
+
+} // end function binarySearch
+
+// print header for output
+void printHeader( int size )
+{
+ cout << "\nSubscripts:\n";
+
+ // output column heads
+ for ( int j = 0; j < size; j++ )
+ cout << setw( 3 ) << j << ' ';
+
+ cout << '\n'; // start new line of output
+
+ // output line of - characters
+ for ( int k = 1; k <= 4 * size; k++ )
+ cout << '-';
+
+ cout << endl; // start new line of output
+
+} // end function printHeader
+
+// print one row of output showing the current
+// part of the array being processed
+void printRow( const int b[], int low, int mid,
+ int high, int size )
+{
+ // loop through entire array
+ for ( int m = 0; m < size; m++ )
+
+ // display spaces if outside current subarray range
+ if ( m < low || m > high )
+ cout << " ";
+
+ // display middle element marked with a *
+ else
+
+ if ( m == mid ) // mark middle value
+ cout << setw( 3 ) << b[ m ] << '*';
+
+ // display other elements in subarray
+ else
+ cout << setw( 3 ) << b[ m ] << ' ';
+
+ cout << endl; // start new line of output
+
+} // end function printRow
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_22.cpp b/Bachelor/Prog1/examples/ch04/Fig04_22.cpp new file mode 100644 index 0000000..44c17da --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_22.cpp @@ -0,0 +1,57 @@ +// Fig. 4.22: fig04_22.cpp
+// Initializing multidimensional arrays.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void printArray( int [][ 3 ] );
+
+int main()
+{
+ int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } };
+ int array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 };
+ int array3[ 2 ][ 3 ] = { { 1, 2 }, { 4 } };
+
+ cout << "Values in array1 by row are:" << endl;
+ printArray( array1 );
+
+ cout << "Values in array2 by row are:" << endl;
+ printArray( array2 );
+
+ cout << "Values in array3 by row are:" << endl;
+ printArray( array3 );
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// function to output array with two rows and three columns
+void printArray( int a[][ 3 ] )
+{
+ for ( int i = 0; i < 2; i++ ) { // for each row
+
+ for ( int j = 0; j < 3; j++ ) // output column values
+ cout << a[ i ][ j ] << ' ';
+
+ cout << endl; // start new line of output
+
+ } // end outer for structure
+
+} // end function printArray
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch04/Fig04_23.cpp b/Bachelor/Prog1/examples/ch04/Fig04_23.cpp new file mode 100644 index 0000000..7957c1e --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_23.cpp @@ -0,0 +1,134 @@ +// Fig. 4.23: fig04_23.cpp
+// Double-subscripted array example.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::fixed;
+using std::left;
+
+#include <iomanip>
+
+using std::setw;
+using std::setprecision;
+
+const int students = 3; // number of students
+const int exams = 4; // number of exams
+
+// function prototypes
+int minimum( int [][ exams ], int, int );
+int maximum( int [][ exams ], int, int );
+double average( int [], int );
+void printArray( int [][ exams ], int, int );
+
+int main()
+{
+ // initialize student grades for three students (rows)
+ int studentGrades[ students ][ exams ] =
+ { { 77, 68, 86, 73 },
+ { 96, 87, 89, 78 },
+ { 70, 90, 86, 81 } };
+
+ // output array studentGrades
+ cout << "The array is:\n";
+ printArray( studentGrades, students, exams );
+
+ // determine smallest and largest grade values
+ cout << "\n\nLowest grade: "
+ << minimum( studentGrades, students, exams )
+ << "\nHighest grade: "
+ << maximum( studentGrades, students, exams ) << '\n';
+
+ cout << fixed << setprecision( 2 );
+
+ // calculate average grade for each student
+ for ( int person = 0; person < students; person++ )
+ cout << "The average grade for student " << person
+ << " is "
+ << average( studentGrades[ person ], exams )
+ << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// find minimum grade
+int minimum( int grades[][ exams ], int pupils, int tests )
+{
+ int lowGrade = 100; // initialize to highest possible grade
+
+ for ( int i = 0; i < pupils; i++ )
+
+ for ( int j = 0; j < tests; j++ )
+
+ if ( grades[ i ][ j ] < lowGrade )
+ lowGrade = grades[ i ][ j ];
+
+ return lowGrade;
+
+} // end function minimum
+
+// find maximum grade
+int maximum( int grades[][ exams ], int pupils, int tests )
+{
+ int highGrade = 0; // initialize to lowest possible grade
+
+ for ( int i = 0; i < pupils; i++ )
+
+ for ( int j = 0; j < tests; j++ )
+
+ if ( grades[ i ][ j ] > highGrade )
+ highGrade = grades[ i ][ j ];
+
+ return highGrade;
+
+} // end function maximum
+
+// determine average grade for particular student
+double average( int setOfGrades[], int tests )
+{
+ int total = 0;
+
+ // total all grades for one student
+ for ( int i = 0; i < tests; i++ )
+ total += setOfGrades[ i ];
+
+ return static_cast< double >( total ) / tests; // average
+
+} // end function maximum
+
+// Print the array
+void printArray( int grades[][ exams ], int pupils, int tests )
+{
+ // set left justification and output column heads
+ cout << left << " [0] [1] [2] [3]";
+
+ // output grades in tabular format
+ for ( int i = 0; i < pupils; i++ ) {
+
+ // output label for row
+ cout << "\nstudentGrades[" << i << "] ";
+
+ // output one grades for one student
+ for ( int j = 0; j < tests; j++ )
+ cout << setw( 5 ) << grades[ i ][ j ];
+
+ } // end outer for
+
+} // end function printArray
+
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Ex05_21.cpp b/Bachelor/Prog1/examples/ch05/Ex05_21.cpp new file mode 100644 index 0000000..1fd9111 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_21.cpp @@ -0,0 +1,49 @@ +// Ex. 5.21: ex05_21.cpp
+// What does this program do?
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+void mystery1( char *, const char * ); // prototype
+
+int main()
+{
+ char string1[ 80 ];
+ char string2[ 80 ];
+
+ cout << "Enter two strings: ";
+ cin >> string1 >> string2;
+ mystery1( string1, string2 );
+ cout << string1 << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// What does this function do?
+void mystery1( char *s1, const char *s2 )
+{
+ while ( *s1 != '\0' )
+ ++s1;
+
+ for ( ; *s1 = *s2; s1++, s2++ )
+ ; // empty statement
+
+} // end function mystery1
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Ex05_22.cpp b/Bachelor/Prog1/examples/ch05/Ex05_22.cpp new file mode 100644 index 0000000..9299669 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_22.cpp @@ -0,0 +1,48 @@ +// Ex. 5.22: ex05_22.cpp
+// What does this program do?
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+int mystery2( const char * ); // prototype
+
+int main()
+{
+ char string1[ 80 ];
+
+ cout << "Enter a string: ";
+ cin >> string1;
+ cout << mystery2( string1 ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// What does this function do?
+int mystery2( const char *s )
+{
+ int x;
+
+ for ( x = 0; *s != '\0'; s++ )
+ ++x;
+
+ return x;
+
+} // end function mystery2
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Ex05_30.cpp b/Bachelor/Prog1/examples/ch05/Ex05_30.cpp new file mode 100644 index 0000000..88ede48 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_30.cpp @@ -0,0 +1,49 @@ +// Ex. 5.30: ex05_30.cpp
+// What does this program do?
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+bool mystery3( const char *, const char * ); // prototype
+
+int main()
+{
+ char string1[ 80 ], string2[ 80 ];
+
+ cout << "Enter two strings: ";
+ cin >> string1 >> string2;
+ cout << "The result is "
+ << mystery3( string1, string2 ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// What does this function do?
+bool mystery3( const char *s1, const char *s2 )
+{
+ for ( ; *s1 != '\0' && *s2 != '\0'; s1++, s2++ )
+
+ if ( *s1 != *s2 )
+ return false;
+
+ return true;
+
+} // end function mystery3
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_04.cpp b/Bachelor/Prog1/examples/ch05/Fig05_04.cpp new file mode 100644 index 0000000..bcf52ff --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_04.cpp @@ -0,0 +1,43 @@ +// Fig. 5.4: fig05_04.cpp
+// Using the & and * operators.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int a; // a is an integer
+ int *aPtr; // aPtr is a pointer to an integer
+
+ a = 7;
+ aPtr = &a; // aPtr assigned address of a
+
+ cout << "The address of a is " << &a
+ << "\nThe value of aPtr is " << aPtr;
+
+ cout << "\n\nThe value of a is " << a
+ << "\nThe value of *aPtr is " << *aPtr;
+
+ cout << "\n\nShowing that * and & are inverses of "
+ << "each other.\n&*aPtr = " << &*aPtr
+ << "\n*&aPtr = " << *&aPtr << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_06.cpp b/Bachelor/Prog1/examples/ch05/Fig05_06.cpp new file mode 100644 index 0000000..5aad3b7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_06.cpp @@ -0,0 +1,45 @@ +// Fig. 5.6: fig05_06.cpp
+// Cube a variable using pass-by-value.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int cubeByValue( int ); // prototype
+
+int main()
+{
+ int number = 5;
+
+ cout << "The original value of number is " << number;
+
+ // pass number by value to cubeByValue
+ number = cubeByValue( number );
+
+ cout << "\nThe new value of number is " << number << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// calculate and return cube of integer argument
+int cubeByValue( int n )
+{
+ return n * n * n; // cube local variable n and return result
+
+} // end function cubeByValue
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_07.cpp b/Bachelor/Prog1/examples/ch05/Fig05_07.cpp new file mode 100644 index 0000000..b4da523 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_07.cpp @@ -0,0 +1,46 @@ +// Fig. 5.7: fig05_07.cpp
+// Cube a variable using pass-by-reference
+// with a pointer argument.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void cubeByReference( int * ); // prototype
+
+int main()
+{
+ int number = 5;
+
+ cout << "The original value of number is " << number;
+
+ // pass address of number to cubeByReference
+ cubeByReference( &number );
+
+ cout << "\nThe new value of number is " << number << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// calculate cube of *nPtr; modifies variable number in main
+void cubeByReference( int *nPtr )
+{
+ *nPtr = *nPtr * *nPtr * *nPtr; // cube *nPtr
+
+} // end function cubeByReference
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_10.cpp b/Bachelor/Prog1/examples/ch05/Fig05_10.cpp new file mode 100644 index 0000000..cfd0fce --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_10.cpp @@ -0,0 +1,53 @@ +// Fig. 5.10: fig05_10.cpp
+// Converting lowercase letters to uppercase letters
+// using a non-constant pointer to non-constant data.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <cctype> // prototypes for islower and toupper
+
+void convertToUppercase( char * );
+
+int main()
+{
+ char phrase[] = "characters and $32.98";
+
+ cout << "The phrase before conversion is: " << phrase;
+ convertToUppercase( phrase );
+ cout << "\nThe phrase after conversion is: "
+ << phrase << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// convert string to uppercase letters
+void convertToUppercase( char *sPtr )
+{
+ while ( *sPtr != '\0' ) { // current character is not '\0'
+
+ if ( islower( *sPtr ) ) // if character is lowercase,
+ *sPtr = toupper( *sPtr ); // convert to uppercase
+
+ ++sPtr; // move sPtr to next character in string
+
+ } // end while
+
+} // end function convertToUppercase
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_11.cpp b/Bachelor/Prog1/examples/ch05/Fig05_11.cpp new file mode 100644 index 0000000..6d92cef --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_11.cpp @@ -0,0 +1,45 @@ +// Fig. 5.11: fig05_11.cpp
+// Printing a string one character at a time using
+// a non-constant pointer to constant data.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void printCharacters( const char * );
+
+int main()
+{
+ char phrase[] = "print characters of a string";
+
+ cout << "The string is:\n";
+ printCharacters( phrase );
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// sPtr cannot modify the character to which it points,
+// i.e., sPtr is a "read-only" pointer
+void printCharacters( const char *sPtr )
+{
+ for ( ; *sPtr != '\0'; sPtr++ ) // no initialization
+ cout << *sPtr;
+
+} // end function printCharacters
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_12.cpp b/Bachelor/Prog1/examples/ch05/Fig05_12.cpp new file mode 100644 index 0000000..c9f089a --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_12.cpp @@ -0,0 +1,38 @@ +// Fig. 5.12: fig05_12.cpp
+// Attempting to modify data through a
+// non-constant pointer to constant data.
+
+void f( const int * ); // prototype
+
+int main()
+{
+ int y;
+
+ f( &y ); // f attempts illegal modification
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// xPtr cannot modify the value of the variable
+// to which it points
+void f( const int *xPtr )
+{
+ *xPtr = 100; // error: cannot modify a const object
+
+} // end function f
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_13.cpp b/Bachelor/Prog1/examples/ch05/Fig05_13.cpp new file mode 100644 index 0000000..ac697ba --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_13.cpp @@ -0,0 +1,34 @@ +// Fig. 5.13: fig05_13.cpp
+// Attempting to modify a constant pointer to
+// non-constant data.
+
+int main()
+{
+ int x, y;
+
+ // ptr is a constant pointer to an integer that can
+ // be modified through ptr, but ptr always points to the
+ // same memory location.
+ int * const ptr = &x;
+
+ *ptr = 7; // allowed: *ptr is not const
+ ptr = &y; // error: ptr is const; cannot assign new address
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_14.cpp b/Bachelor/Prog1/examples/ch05/Fig05_14.cpp new file mode 100644 index 0000000..8193ad1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_14.cpp @@ -0,0 +1,39 @@ +// Fig. 5.14: fig05_14.cpp
+// Attempting to modify a constant pointer to constant data.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int x = 5, y;
+
+ // ptr is a constant pointer to a constant integer.
+ // ptr always points to the same location; the integer
+ // at that location cannot be modified.
+ const int *const ptr = &x;
+
+ cout << *ptr << endl;
+
+ *ptr = 7; // error: *ptr is const; cannot assign new value
+ ptr = &y; // error: ptr is const; cannot assign new address
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_15.cpp b/Bachelor/Prog1/examples/ch05/Fig05_15.cpp new file mode 100644 index 0000000..bcdd13a --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_15.cpp @@ -0,0 +1,77 @@ +// Fig. 5.15: fig05_15.cpp
+// This program puts values into an array, sorts the values into
+// ascending order, and prints the resulting array.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+void bubbleSort( int *, const int ); // prototype
+void swap( int * const, int * const ); // prototype
+
+int main()
+{
+ const int arraySize = 10;
+ int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
+
+ cout << "Data items in original order\n";
+
+ for ( int i = 0; i < arraySize; i++ )
+ cout << setw( 4 ) << a[ i ];
+
+ bubbleSort( a, arraySize ); // sort the array
+
+ cout << "\nData items in ascending order\n";
+
+ for ( int j = 0; j < arraySize; j++ )
+ cout << setw( 4 ) << a[ j ];
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// sort an array of integers using bubble sort algorithm
+void bubbleSort( int *array, const int size )
+{
+ // loop to control passes
+ for ( int pass = 0; pass < size - 1; pass++ )
+
+ // loop to control comparisons during each pass
+ for ( int k = 0; k < size - 1; k++ )
+
+ // swap adjacent elements if they are out of order
+ if ( array[ k ] > array[ k + 1 ] )
+ swap( &array[ k ], &array[ k + 1 ] );
+
+} // end function bubbleSort
+
+// swap values at memory locations to which
+// element1Ptr and element2Ptr point
+void swap( int * const element1Ptr, int * const element2Ptr )
+{
+ int hold = *element1Ptr;
+ *element1Ptr = *element2Ptr;
+ *element2Ptr = hold;
+
+} // end function swap
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_16.cpp b/Bachelor/Prog1/examples/ch05/Fig05_16.cpp new file mode 100644 index 0000000..921e8dd --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_16.cpp @@ -0,0 +1,45 @@ +// Fig. 5.16: fig05_16.cpp
+// Sizeof operator when used on an array name
+// returns the number of bytes in the array.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+size_t getSize( double * ); // prototype
+
+int main()
+{
+ double array[ 20 ];
+
+ cout << "The number of bytes in the array is "
+ << sizeof( array );
+
+ cout << "\nThe number of bytes returned by getSize is "
+ << getSize( array ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// return size of ptr
+size_t getSize( double *ptr )
+{
+ return sizeof( ptr );
+
+} // end function getSize
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_17.cpp b/Bachelor/Prog1/examples/ch05/Fig05_17.cpp new file mode 100644 index 0000000..7091880 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_17.cpp @@ -0,0 +1,55 @@ +// Fig. 5.17: fig05_17.cpp
+// Demonstrating the sizeof operator.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ char c;
+ short s;
+ int i;
+ long l;
+ float f;
+ double d;
+ long double ld;
+ int array[ 20 ];
+ int *ptr = array;
+
+ cout << "sizeof c = " << sizeof c
+ << "\tsizeof(char) = " << sizeof( char )
+ << "\nsizeof s = " << sizeof s
+ << "\tsizeof(short) = " << sizeof( short )
+ << "\nsizeof i = " << sizeof i
+ << "\tsizeof(int) = " << sizeof( int )
+ << "\nsizeof l = " << sizeof l
+ << "\tsizeof(long) = " << sizeof( long )
+ << "\nsizeof f = " << sizeof f
+ << "\tsizeof(float) = " << sizeof( float )
+ << "\nsizeof d = " << sizeof d
+ << "\tsizeof(double) = " << sizeof( double )
+ << "\nsizeof ld = " << sizeof ld
+ << "\tsizeof(long double) = " << sizeof( long double )
+ << "\nsizeof array = " << sizeof array
+ << "\nsizeof ptr = " << sizeof ptr
+ << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_20.cpp b/Bachelor/Prog1/examples/ch05/Fig05_20.cpp new file mode 100644 index 0000000..63bc2f7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_20.cpp @@ -0,0 +1,60 @@ +// Fig. 5.20: fig05_20.cpp
+// Using subscripting and pointer notations with arrays.
+
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+int main()
+{
+ int b[] = { 10, 20, 30, 40 };
+ int *bPtr = b; // set bPtr to point to array b
+
+ // output array b using array subscript notation
+ cout << "Array b printed with:\n\n"
+ << "Array subscript notation\n";
+
+ for ( int i = 0; i < 4; i++ )
+ cout << "b[" << i << "] = " << b[ i ] << '\n';
+
+ // output array b using the array name and
+ // pointer/offset notation
+ cout << "\nPointer/offset notation where "
+ << "the pointer is the array name\n";
+
+ for ( int offset1 = 0; offset1 < 4; offset1++ )
+ cout << "*(b + " << offset1 << ") = "
+ << *( b + offset1 ) << '\n';
+
+ // output array b using bPtr and array subscript notation
+ cout << "\nPointer subscript notation\n";
+
+ for ( int j = 0; j < 4; j++ )
+ cout << "bPtr[" << j << "] = " << bPtr[ j ] << '\n';
+
+ cout << "\nPointer/offset notation\n";
+
+ // output array b using bPtr and pointer/offset notation
+ for ( int offset2 = 0; offset2 < 4; offset2++ )
+ cout << "*(bPtr + " << offset2 << ") = "
+ << *( bPtr + offset2 ) << '\n';
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_21.cpp b/Bachelor/Prog1/examples/ch05/Fig05_21.cpp new file mode 100644 index 0000000..e045aba --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_21.cpp @@ -0,0 +1,58 @@ +// Fig. 5.21: fig05_21.cpp
+// Copying a string using array notation
+// and pointer notation.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+void copy1( char *, const char * ); // prototype
+void copy2( char *, const char * ); // prototype
+
+int main()
+{
+ char string1[ 10 ];
+ char *string2 = "Hello";
+ char string3[ 10 ];
+ char string4[] = "Good Bye";
+
+ copy1( string1, string2 );
+ cout << "string1 = " << string1 << endl;
+
+ copy2( string3, string4 );
+ cout << "string3 = " << string3 << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// copy s2 to s1 using array notation
+void copy1( char *s1, const char *s2 )
+{
+ for ( int i = 0; ( s1[ i ] = s2[ i ] ) != '\0'; i++ )
+ ; // do nothing in body
+
+} // end function copy1
+
+// copy s2 to s1 using pointer notation
+void copy2( char *s1, const char *s2 )
+{
+ for ( ; ( *s1 = *s2 ) != '\0'; s1++, s2++ )
+ ; // do nothing in body
+
+} // end function copy2
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_24.cpp b/Bachelor/Prog1/examples/ch05/Fig05_24.cpp new file mode 100644 index 0000000..746fd13 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_24.cpp @@ -0,0 +1,103 @@ +// Fig. 5.24: fig05_24.cpp
+// Card shuffling dealing program.
+#include <iostream>
+
+using std::cout;
+using std::left;
+using std::right;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <cstdlib> // prototypes for rand and srand
+#include <ctime> // prototype for time
+
+// prototypes
+void shuffle( int [][ 13 ] );
+void deal( const int [][ 13 ], const char *[], const char *[] );
+
+int main()
+{
+ // initialize suit array
+ const char *suit[ 4 ] =
+ { "Hearts", "Diamonds", "Clubs", "Spades" };
+
+ // initialize face array
+ const char *face[ 13 ] =
+ { "Ace", "Deuce", "Three", "Four",
+ "Five", "Six", "Seven", "Eight",
+ "Nine", "Ten", "Jack", "Queen", "King" };
+
+ // initialize deck array
+ int deck[ 4 ][ 13 ] = { 0 };
+
+ srand( time( 0 ) ); // seed random number generator
+
+ shuffle( deck );
+ deal( deck, face, suit );
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// shuffle cards in deck
+void shuffle( int wDeck[][ 13 ] )
+{
+ int row;
+ int column;
+
+ // for each of the 52 cards, choose slot of deck randomly
+ for ( int card = 1; card <= 52; card++ ) {
+
+ // choose new random location until unoccupied slot found
+ do {
+ row = rand() % 4;
+ column = rand() % 13;
+ } while( wDeck[ row ][ column ] != 0 ); // end do/while
+
+ // place card number in chosen slot of deck
+ wDeck[ row ][ column ] = card;
+
+ } // end for
+
+} // end function shuffle
+
+// deal cards in deck
+void deal( const int wDeck[][ 13 ], const char *wFace[],
+ const char *wSuit[] )
+{
+ // for each of the 52 cards
+ for ( int card = 1; card <= 52; card++ )
+
+ // loop through rows of wDeck
+ for ( int row = 0; row <= 3; row++ )
+
+ // loop through columns of wDeck for current row
+ for ( int column = 0; column <= 12; column++ )
+
+ // if slot contains current card, display card
+ if ( wDeck[ row ][ column ] == card ) {
+ cout << setw( 5 ) << right << wFace[ column ]
+ << " of " << setw( 8 ) << left
+ << wSuit[ row ]
+ << ( card % 2 == 0 ? '\n' : '\t' );
+
+ } // end if
+
+} // end function deal
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_25.cpp b/Bachelor/Prog1/examples/ch05/Fig05_25.cpp new file mode 100644 index 0000000..8073108 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_25.cpp @@ -0,0 +1,115 @@ +// Fig. 5.25: fig05_25.cpp
+// Multipurpose sorting program using function pointers.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+// prototypes
+void bubble( int [], const int, bool (*)( int, int ) );
+void swap( int * const, int * const );
+bool ascending( int, int );
+bool descending( int, int );
+
+int main()
+{
+ const int arraySize = 10;
+ int order;
+ int counter;
+ int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
+
+ cout << "Enter 1 to sort in ascending order,\n"
+ << "Enter 2 to sort in descending order: ";
+ cin >> order;
+ cout << "\nData items in original order\n";
+
+ // output original array
+ for ( counter = 0; counter < arraySize; counter++ )
+ cout << setw( 4 ) << a[ counter ];
+
+ // sort array in ascending order; pass function ascending
+ // as an argument to specify ascending sorting order
+ if ( order == 1 ) {
+ bubble( a, arraySize, ascending );
+ cout << "\nData items in ascending order\n";
+ }
+
+ // sort array in descending order; pass function descending
+ // as an argument to specify descending sorting order
+ else {
+ bubble( a, arraySize, descending );
+ cout << "\nData items in descending order\n";
+ }
+
+ // output sorted array
+ for ( counter = 0; counter < arraySize; counter++ )
+ cout << setw( 4 ) << a[ counter ];
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+// multipurpose bubble sort; parameter compare is a pointer to
+// the comparison function that determines sorting order
+void bubble( int work[], const int size,
+ bool (*compare)( int, int ) )
+{
+ // loop to control passes
+ for ( int pass = 1; pass < size; pass++ )
+
+ // loop to control number of comparisons per pass
+ for ( int count = 0; count < size - 1; count++ )
+
+ // if adjacent elements are out of order, swap them
+ if ( (*compare)( work[ count ], work[ count + 1 ] ) )
+ swap( &work[ count ], &work[ count + 1 ] );
+
+} // end function bubble
+
+// swap values at memory locations to which
+// element1Ptr and element2Ptr point
+void swap( int * const element1Ptr, int * const element2Ptr )
+{
+ int hold = *element1Ptr;
+ *element1Ptr = *element2Ptr;
+ *element2Ptr = hold;
+
+} // end function swap
+
+// determine whether elements are out of order
+// for an ascending order sort
+bool ascending( int a, int b )
+{
+ return b < a; // swap if b is less than a
+
+} // end function ascending
+
+// determine whether elements are out of order
+// for a descending order sort
+bool descending( int a, int b )
+{
+ return b > a; // swap if b is greater than a
+
+} // end function descending
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_26.cpp b/Bachelor/Prog1/examples/ch05/Fig05_26.cpp new file mode 100644 index 0000000..916dbb9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_26.cpp @@ -0,0 +1,76 @@ +// Fig. 5.26: fig05_26.cpp
+// Demonstrating an array of pointers to functions.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+// function prototypes
+void function1( int );
+void function2( int );
+void function3( int );
+
+int main()
+{
+ // initialize array of 3 pointers to functions that each
+ // take an int argument and return void
+ void (*f[ 3 ])( int ) = { function1, function2, function3 };
+
+ int choice;
+
+ cout << "Enter a number between 0 and 2, 3 to end: ";
+ cin >> choice;
+
+ // process user's choice
+ while ( choice >= 0 && choice < 3 ) {
+
+ // invoke function at location choice in array f
+ // and pass choice as an argument
+ (*f[ choice ])( choice );
+
+ cout << "Enter a number between 0 and 2, 3 to end: ";
+ cin >> choice;
+ }
+
+ cout << "Program execution completed." << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+void function1( int a )
+{
+ cout << "You entered " << a
+ << " so function1 was called\n\n";
+
+} // end function1
+
+void function2( int b )
+{
+ cout << "You entered " << b
+ << " so function2 was called\n\n";
+
+} // end function2
+
+void function3( int c )
+{
+ cout << "You entered " << c
+ << " so function3 was called\n\n";
+
+} // end function3
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_28.cpp b/Bachelor/Prog1/examples/ch05/Fig05_28.cpp new file mode 100644 index 0000000..d973c37 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_28.cpp @@ -0,0 +1,44 @@ +// Fig. 5.28: fig05_28.cpp
+// Using strcpy and strncpy.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <cstring> // prototypes for strcpy and strncpy
+
+int main()
+{
+ char x[] = "Happy Birthday to You";
+ char y[ 25 ];
+ char z[ 15 ];
+
+ strcpy( y, x ); // copy contents of x into y
+
+ cout << "The string in array x is: " << x
+ << "\nThe string in array y is: " << y << '\n';
+
+ // copy first 14 characters of x into z
+ strncpy( z, x, 14 ); // does not copy null character
+ z[ 14 ] = '\0'; // append '\0' to z's contents
+
+ cout << "The string in array z is: " << z << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_29.cpp b/Bachelor/Prog1/examples/ch05/Fig05_29.cpp new file mode 100644 index 0000000..daa58f6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_29.cpp @@ -0,0 +1,50 @@ +// Fig. 5.29: fig05_29.cpp
+// Using strcat and strncat.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <cstring> // prototypes for strcat and strncat
+
+int main()
+{
+ char s1[ 20 ] = "Happy ";
+ char s2[] = "New Year ";
+ char s3[ 40 ] = "";
+
+ cout << "s1 = " << s1 << "\ns2 = " << s2;
+
+ strcat( s1, s2 ); // concatenate s2 to s1
+
+ cout << "\n\nAfter strcat(s1, s2):\ns1 = " << s1
+ << "\ns2 = " << s2;
+
+ // concatenate first 6 characters of s1 to s3
+ strncat( s3, s1, 6 ); // places '\0' after last character
+
+ cout << "\n\nAfter strncat(s3, s1, 6):\ns1 = " << s1
+ << "\ns3 = " << s3;
+
+ strcat( s3, s1 ); // concatenate s1 to s3
+ cout << "\n\nAfter strcat(s3, s1):\ns1 = " << s1
+ << "\ns3 = " << s3 << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_30.cpp b/Bachelor/Prog1/examples/ch05/Fig05_30.cpp new file mode 100644 index 0000000..1f55555 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_30.cpp @@ -0,0 +1,50 @@ +// Fig. 5.30: fig05_30.cpp
+// Using strcmp and strncmp.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <cstring> // prototypes for strcmp and strncmp
+
+int main()
+{
+ char *s1 = "Happy New Year";
+ char *s2 = "Happy New Year";
+ char *s3 = "Happy Holidays";
+
+ cout << "s1 = " << s1 << "\ns2 = " << s2
+ << "\ns3 = " << s3 << "\n\nstrcmp(s1, s2) = "
+ << setw( 2 ) << strcmp( s1, s2 )
+ << "\nstrcmp(s1, s3) = " << setw( 2 )
+ << strcmp( s1, s3 ) << "\nstrcmp(s3, s1) = "
+ << setw( 2 ) << strcmp( s3, s1 );
+
+ cout << "\n\nstrncmp(s1, s3, 6) = " << setw( 2 )
+ << strncmp( s1, s3, 6 ) << "\nstrncmp(s1, s3, 7) = "
+ << setw( 2 ) << strncmp( s1, s3, 7 )
+ << "\nstrncmp(s3, s1, 7) = "
+ << setw( 2 ) << strncmp( s3, s1, 7 ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_31.cpp b/Bachelor/Prog1/examples/ch05/Fig05_31.cpp new file mode 100644 index 0000000..280bddc --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_31.cpp @@ -0,0 +1,47 @@ +// Fig. 5.31: fig05_31.cpp
+// Using strtok.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <cstring> // prototype for strtok
+
+int main()
+{
+ char sentence[] = "This is a sentence with 7 tokens";
+ char *tokenPtr;
+
+ cout << "The string to be tokenized is:\n" << sentence
+ << "\n\nThe tokens are:\n\n";
+
+ // begin tokenization of sentence
+ tokenPtr = strtok( sentence, " " );
+
+ // continue tokenizing sentence until tokenPtr becomes NULL
+ while ( tokenPtr != NULL ) {
+ cout << tokenPtr << '\n';
+ tokenPtr = strtok( NULL, " " ); // get next token
+
+ } // end while
+
+ cout << "\nAfter strtok, sentence = " << sentence << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch05/Fig05_32.cpp b/Bachelor/Prog1/examples/ch05/Fig05_32.cpp new file mode 100644 index 0000000..ae612dd --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_32.cpp @@ -0,0 +1,40 @@ +// Fig. 5.32: fig05_32.cpp
+// Using strlen.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <cstring> // prototype for strlen
+
+int main()
+{
+ char *string1 = "abcdefghijklmnopqrstuvwxyz";
+ char *string2 = "four";
+ char *string3 = "Boston";
+
+ cout << "The length of \"" << string1
+ << "\" is " << strlen( string1 )
+ << "\nThe length of \"" << string2
+ << "\" is " << strlen( string2 )
+ << "\nThe length of \"" << string3
+ << "\" is " << strlen( string3 ) << endl;
+
+ return 0; // indicates successful termination
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp b/Bachelor/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp new file mode 100644 index 0000000..0126a02 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_01/Fig06_01.cpp @@ -0,0 +1,82 @@ +// Fig. 6.1: fig06_01.cpp
+// Create a structure, set its members, and print it.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+// structure definition
+struct Time {
+ int hour; // 0-23 (24-hour clock format)
+ int minute; // 0-59
+ int second; // 0-59
+
+}; // end struct Time
+
+void printUniversal( const Time & ); // prototype
+void printStandard( const Time & ); // prototype
+
+int main()
+{
+ Time dinnerTime; // variable of new type Time
+
+ dinnerTime.hour = 18; // set hour member of dinnerTime
+ dinnerTime.minute = 30; // set minute member of dinnerTime
+ dinnerTime.second = 0; // set second member of dinnerTime
+
+ cout << "Dinner will be held at ";
+ printUniversal( dinnerTime );
+ cout << " universal time,\nwhich is ";
+ printStandard( dinnerTime );
+ cout << " standard time.\n";
+
+ dinnerTime.hour = 29; // set hour to invalid value
+ dinnerTime.minute = 73; // set minute to invalid value
+
+ cout << "\nTime with invalid values: ";
+ printUniversal( dinnerTime );
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+// print time in universal-time format
+void printUniversal( const Time &t )
+{
+ cout << setfill( '0' ) << setw( 2 ) << t.hour << ":"
+ << setw( 2 ) << t.minute << ":"
+ << setw( 2 ) << t.second;
+
+} // end function printUniversal
+
+// print time in standard-time format
+void printStandard( const Time &t )
+{
+ cout << ( ( t.hour == 0 || t.hour == 12 ) ?
+ 12 : t.hour % 12 ) << ":" << setfill( '0' )
+ << setw( 2 ) << t.minute << ":"
+ << setw( 2 ) << t.second
+ << ( t.hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp b/Bachelor/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp new file mode 100644 index 0000000..3bb7a28 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_03/Fig06_03.cpp @@ -0,0 +1,114 @@ +// Fig. 6.3: fig06_03.cpp
+// Time class.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+// Time abstract data type (ADT) definition
+class Time {
+
+public:
+ Time(); // constructor
+ void setTime( int, int, int ); // set hour, minute, second
+ void printUniversal(); // print universal-time format
+ void printStandard(); // print standard-time format
+
+private:
+ int hour; // 0 - 23 (24-hour clock format)
+ int minute; // 0 - 59
+ int second; // 0 - 59
+
+}; // end class Time
+
+// Time constructor initializes each data member to zero and
+// ensures all Time objects start in a consistent state
+Time::Time()
+{
+ hour = minute = second = 0;
+
+} // end constructor Time
+
+// set new Time value using universal time, perform validity
+// checks on the data values and set invalid values to zero
+void Time::setTime( int h, int m, int s )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+} // end function setTime
+
+// print Time in universal format
+void Time::printUniversal()
+{
+ cout << setfill( '0' ) << setw( 2 ) << hour << ":"
+ << setw( 2 ) << minute << ":"
+ << setw( 2 ) << second;
+
+} // end function printUniversal
+
+// print Time in standard format
+void Time::printStandard()
+{
+ cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
+ << ":" << setfill( '0' ) << setw( 2 ) << minute
+ << ":" << setw( 2 ) << second
+ << ( hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+int main()
+{
+ Time t; // instantiate object t of class Time
+
+ // output Time object t's initial values
+ cout << "The initial universal time is ";
+ t.printUniversal(); // 00:00:00
+
+ cout << "\nThe initial standard time is ";
+ t.printStandard(); // 12:00:00 AM
+
+ t.setTime( 13, 27, 6 ); // change time
+
+ // output Time object t's new values
+ cout << "\n\nUniversal time after setTime is ";
+ t.printUniversal(); // 13:27:06
+
+ cout << "\nStandard time after setTime is ";
+ t.printStandard(); // 1:27:06 PM
+
+ t.setTime( 99, 99, 99 ); // attempt invalid settings
+
+ // output t's values after specifying invalid values
+ cout << "\n\nAfter attempting invalid settings:"
+ << "\nUniversal time: ";
+ t.printUniversal(); // 00:00:00
+
+ cout << "\nStandard time: ";
+ t.printStandard(); // 12:00:00 AM
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp b/Bachelor/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp new file mode 100644 index 0000000..68c1be3 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_04/Fig06_04.cpp @@ -0,0 +1,58 @@ +// Fig. 6.4: fig06_04.cpp
+// Demonstrating the class member access operators . and ->
+//
+// CAUTION: IN FUTURE EXAMPLES WE AVOID PUBLIC DATA!
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// class Count definition
+class Count {
+
+public:
+ int x;
+
+ void print()
+ {
+ cout << x << endl;
+ }
+
+}; // end class Count
+
+int main()
+{
+ Count counter; // create counter object
+ Count *counterPtr = &counter; // create pointer to counter
+ Count &counterRef = counter; // create reference to counter
+
+ cout << "Assign 1 to x and print using the object's name: ";
+ counter.x = 1; // assign 1 to data member x
+ counter.print(); // call member function print
+
+ cout << "Assign 2 to x and print using a reference: ";
+ counterRef.x = 2; // assign 2 to data member x
+ counterRef.print(); // call member function print
+
+ cout << "Assign 3 to x and print using a pointer: ";
+ counterPtr->x = 3; // assign 3 to data member x
+ counterPtr->print(); // call member function print
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp new file mode 100644 index 0000000..85cca47 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Fig06_05.cpp @@ -0,0 +1,57 @@ +// Fig. 6.7: fig06_07.cpp
+// Program to test class Time.
+// NOTE: This file must be compiled with time1.cpp.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// include definition of class Time from time1.h
+#include "time1.h"
+
+int main()
+{
+ Time t; // instantiate object t of class Time
+
+ // output Time object t's initial values
+ cout << "The initial universal time is ";
+ t.printUniversal(); // 00:00:00
+ cout << "\nThe initial standard time is ";
+ t.printStandard(); // 12:00:00 AM
+
+ t.setTime( 13, 27, 6 ); // change time
+
+ // output Time object t's new values
+ cout << "\n\nUniversal time after setTime is ";
+ t.printUniversal(); // 13:27:06
+ cout << "\nStandard time after setTime is ";
+ t.printStandard(); // 1:27:06 PM
+
+ t.setTime( 99, 99, 99 ); // attempt invalid settings
+
+ // output t's values after specifying invalid values
+ cout << "\n\nAfter attempting invalid settings:"
+ << "\nUniversal time: ";
+ t.printUniversal(); // 00:00:00
+ cout << "\nStandard time: ";
+ t.printStandard(); // 12:00:00 AM
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.cpp b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.cpp new file mode 100644 index 0000000..6ffea1c --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.cpp @@ -0,0 +1,65 @@ +// Fig. 6.6: time1.cpp
+// Member-function definitions for class Time.
+#include <iostream>
+
+using std::cout;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+// include definition of class Time from time1.h
+#include "time1.h"
+
+// Time constructor initializes each data member to zero.
+// Ensures all Time objects start in a consistent state.
+Time::Time()
+{
+ hour = minute = second = 0;
+
+} // end Time constructor
+
+// Set new Time value using universal time. Perform validity
+// checks on the data values. Set invalid values to zero.
+void Time::setTime( int h, int m, int s )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+} // end function setTime
+
+// print Time in universal format
+void Time::printUniversal()
+{
+ cout << setfill( '0' ) << setw( 2 ) << hour << ":"
+ << setw( 2 ) << minute << ":"
+ << setw( 2 ) << second;
+
+} // end function printUniversal
+
+// print Time in standard format
+void Time::printStandard()
+{
+ cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
+ << ":" << setfill( '0' ) << setw( 2 ) << minute
+ << ":" << setw( 2 ) << second
+ << ( hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.h b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.h new file mode 100644 index 0000000..9adaba7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_05_07/Time1.h @@ -0,0 +1,40 @@ +// Fig. 6.5: time1.h
+// Declaration of class Time.
+// Member functions are defined in time1.cpp
+
+// prevent multiple inclusions of header file
+#ifndef TIME1_H
+#define TIME1_H
+
+// Time abstract data type definition
+class Time {
+
+public:
+ Time(); // constructor
+ void setTime( int, int, int ); // set hour, minute, second
+ void printUniversal(); // print universal-time format
+ void printStandard(); // print standard-time format
+
+private:
+ int hour; // 0 - 23 (24-hour clock format)
+ int minute; // 0 - 59
+ int second; // 0 - 59
+
+}; // end class Time
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp b/Bachelor/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp new file mode 100644 index 0000000..93cacc4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_08/Fig06_08.cpp @@ -0,0 +1,38 @@ +// Fig. 6.8: fig06_08.cpp
+// Demonstrate errors resulting from attempts
+// to access private class members.
+#include <iostream>
+
+using std::cout;
+
+// include definition of class Time from time1.h
+#include "time1.h"
+
+int main()
+{
+ Time t; // create Time object
+
+
+ t.hour = 7; // error: 'Time::hour' is not accessible
+
+ // error: 'Time::minute' is not accessible
+ cout << "minute = " << t.minute;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.cpp b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.cpp new file mode 100644 index 0000000..0f53ccf --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.cpp @@ -0,0 +1,65 @@ +// Fig. 6.6: time1.cpp
+// Member-function definitions for class Time.
+#include <iostream>
+
+using std::cout;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+// include definition of class Time from time1.h
+#include "time1.h"
+
+// Time constructor initializes each data member to zero.
+// Ensures all Time objects start in a consistent state.
+Time::Time()
+{
+ hour = minute = second = 0;
+
+} // end Time constructor
+
+// Set new Time value using universal time. Perform validity
+// checks on the data values. Set invalid values to zero.
+void Time::setTime( int h, int m, int s )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+} // end function setTime
+
+// print Time in universal format
+void Time::printUniversal()
+{
+ cout << setfill( '0' ) << setw( 2 ) << hour << ":"
+ << setw( 2 ) << minute << ":"
+ << setw( 2 ) << second;
+
+} // end function printUniversal
+
+// print Time in standard format
+void Time::printStandard()
+{
+ cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
+ << ":" << setfill( '0' ) << setw( 2 ) << minute
+ << ":" << setw( 2 ) << second
+ << ( hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.h b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.h new file mode 100644 index 0000000..9adaba7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_08/Time1.h @@ -0,0 +1,40 @@ +// Fig. 6.5: time1.h
+// Declaration of class Time.
+// Member functions are defined in time1.cpp
+
+// prevent multiple inclusions of header file
+#ifndef TIME1_H
+#define TIME1_H
+
+// Time abstract data type definition
+class Time {
+
+public:
+ Time(); // constructor
+ void setTime( int, int, int ); // set hour, minute, second
+ void printUniversal(); // print universal-time format
+ void printStandard(); // print standard-time format
+
+private:
+ int hour; // 0 - 23 (24-hour clock format)
+ int minute; // 0 - 59
+ int second; // 0 - 59
+
+}; // end class Time
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp new file mode 100644 index 0000000..82787f6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Fig06_11.cpp @@ -0,0 +1,32 @@ +// Fig. 6.11: fig06_11.cpp
+// Demonstrating a utility function.
+// Compile this program with salesp.cpp
+
+// include SalesPerson class definition from salesp.h
+#include "salesp.h"
+
+int main()
+{
+ SalesPerson s; // create SalesPerson object s
+
+ s.getSalesFromUser(); // note simple sequential code; no
+ s.printAnnualSales(); // control structures in main
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.cpp b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.cpp new file mode 100644 index 0000000..4c05a6d --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.cpp @@ -0,0 +1,86 @@ +// Fig. 6.10: salesp.cpp
+// Member functions for class SalesPerson.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setprecision;
+
+// include SalesPerson class definition from salesp.h
+#include "salesp.h"
+
+// initialize elements of array sales to 0.0
+SalesPerson::SalesPerson()
+{
+ for ( int i = 0; i < 12; i++ )
+ sales[ i ] = 0.0;
+
+} // end SalesPerson constructor
+
+// get 12 sales figures from the user at the keyboard
+void SalesPerson::getSalesFromUser()
+{
+ double salesFigure;
+
+ for ( int i = 1; i <= 12; i++ ) {
+ cout << "Enter sales amount for month " << i << ": ";
+ cin >> salesFigure;
+ setSales( i, salesFigure );
+
+ } // end for
+
+} // end function getSalesFromUser
+
+// set one of the 12 monthly sales figures; function subtracts
+// one from month value for proper subscript in sales array
+void SalesPerson::setSales( int month, double amount )
+{
+ // test for valid month and amount values
+ if ( month >= 1 && month <= 12 && amount > 0 )
+ sales[ month - 1 ] = amount; // adjust for subscripts 0-11
+
+ else // invalid month or amount value
+ cout << "Invalid month or sales figure" << endl;
+
+} // end function setSales
+
+// print total annual sales (with the help of utility function)
+void SalesPerson::printAnnualSales()
+{
+ cout << setprecision( 2 ) << fixed
+ << "\nThe total annual sales are: $"
+ << totalAnnualSales() << endl; // call utility function
+
+} // end function printAnnualSales
+
+// private utility function to total annual sales
+double SalesPerson::totalAnnualSales()
+{
+ double total = 0.0; // initialize total
+
+ for ( int i = 0; i < 12; i++ ) // summarize sales results
+ total += sales[ i ];
+
+ return total;
+
+} // end function totalAnnualSales
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.h b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.h new file mode 100644 index 0000000..240e3e7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_09_11/Salesp.h @@ -0,0 +1,36 @@ +// Fig. 6.9: salesp.h
+// SalesPerson class definition.
+// Member functions defined in salesp.cpp.
+#ifndef SALESP_H
+#define SALESP_H
+
+class SalesPerson {
+
+public:
+ SalesPerson(); // constructor
+ void getSalesFromUser(); // input sales from keyboard
+ void setSales( int, double ); // set sales for a month
+ void printAnnualSales(); // summarize and print sales
+
+private:
+ double totalAnnualSales(); // utility function
+ double sales[ 12 ]; // 12 monthly sales figures
+
+}; // end class SalesPerson
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp new file mode 100644 index 0000000..8a7546a --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Fig06_14.cpp @@ -0,0 +1,63 @@ +// Fig. 6.14: fig06_14.cpp
+// Demonstrating a default constructor for class Time.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// include definition of class Time from time2.h
+#include "time2.h"
+
+int main()
+{
+ Time t1; // all arguments defaulted
+ Time t2( 2 ); // minute and second defaulted
+ Time t3( 21, 34 ); // second defaulted
+ Time t4( 12, 25, 42 ); // all values specified
+ Time t5( 27, 74, 99 ); // all bad values specified
+
+ cout << "Constructed with:\n\n"
+ << "all default arguments:\n ";
+ t1.printUniversal(); // 00:00:00
+ cout << "\n ";
+ t1.printStandard(); // 12:00:00 AM
+
+ cout << "\n\nhour specified; default minute and second:\n ";
+ t2.printUniversal(); // 02:00:00
+ cout << "\n ";
+ t2.printStandard(); // 2:00:00 AM
+
+ cout << "\n\nhour and minute specified; default second:\n ";
+ t3.printUniversal(); // 21:34:00
+ cout << "\n ";
+ t3.printStandard(); // 9:34:00 PM
+
+ cout << "\n\nhour, minute, and second specified:\n ";
+ t4.printUniversal(); // 12:25:42
+ cout << "\n ";
+ t4.printStandard(); // 12:25:42 PM
+
+ cout << "\n\nall invalid values specified:\n ";
+ t5.printUniversal(); // 00:00:00
+ cout << "\n ";
+ t5.printStandard(); // 12:00:00 AM
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.cpp b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.cpp new file mode 100644 index 0000000..5a5d42c --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.cpp @@ -0,0 +1,65 @@ +// Fig. 6.13: time2.cpp
+// Member-function definitions for class Time.
+#include <iostream>
+
+using std::cout;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+// include definition of class Time from time2.h
+#include "time2.h"
+
+// Time constructor initializes each data member to zero;
+// ensures all Time objects start in a consistent state
+Time::Time( int hr, int min, int sec )
+{
+ setTime( hr, min, sec ); // validate and set time
+
+} // end Time constructor
+
+// set new Time value using universal time, perform validity
+// checks on the data values and set invalid values to zero
+void Time::setTime( int h, int m, int s )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+} // end function setTime
+
+// print Time in universal format
+void Time::printUniversal()
+{
+ cout << setfill( '0' ) << setw( 2 ) << hour << ":"
+ << setw( 2 ) << minute << ":"
+ << setw( 2 ) << second;
+
+} // end function printUniversal
+
+// print Time in standard format
+void Time::printStandard()
+{
+ cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
+ << ":" << setfill( '0' ) << setw( 2 ) << minute
+ << ":" << setw( 2 ) << second
+ << ( hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.h b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.h new file mode 100644 index 0000000..3b99b88 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_12_14/Time2.h @@ -0,0 +1,40 @@ +// Fig. 6.12: time2.h
+// Declaration of class Time.
+// Member functions defined in time2.cpp.
+
+// prevent multiple inclusions of header file
+#ifndef TIME2_H
+#define TIME2_H
+
+// Time abstract data type definition
+class Time {
+
+public:
+ Time( int = 0, int = 0, int = 0); // default constructor
+ void setTime( int, int, int ); // set hour, minute, second
+ void printUniversal(); // print universal-time format
+ void printStandard(); // print standard-time format
+
+private:
+ int hour; // 0 - 23 (24-hour clock format)
+ int minute; // 0 - 59
+ int second; // 0 - 59
+
+}; // end class Time
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.cpp b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.cpp new file mode 100644 index 0000000..1f7614f --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.cpp @@ -0,0 +1,47 @@ +// Fig. 6.16: create.cpp
+// Member-function definitions for class CreateAndDestroy
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// include CreateAndDestroy class definition from create.h
+#include "create.h"
+
+// constructor
+CreateAndDestroy::CreateAndDestroy(
+ int objectNumber, char *messagePtr )
+{
+ objectID = objectNumber;
+ message = messagePtr;
+
+ cout << "Object " << objectID << " constructor runs "
+ << message << endl;
+
+} // end CreateAndDestroy constructor
+
+// destructor
+CreateAndDestroy::~CreateAndDestroy()
+{
+ // the following line is for pedagogic purposes only
+ cout << ( objectID == 1 || objectID == 6 ? "\n" : "" );
+
+ cout << "Object " << objectID << " destructor runs "
+ << message << endl;
+
+} // end ~CreateAndDestroy destructor
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.h b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.h new file mode 100644 index 0000000..f0a73cb --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Create.h @@ -0,0 +1,34 @@ +// Fig. 6.15: create.h
+// Definition of class CreateAndDestroy.
+// Member functions defined in create.cpp.
+#ifndef CREATE_H
+#define CREATE_H
+
+class CreateAndDestroy {
+
+public:
+ CreateAndDestroy( int, char * ); // constructor
+ ~CreateAndDestroy(); // destructor
+
+private:
+ int objectID;
+ char *message;
+
+}; // end class CreateAndDestroy
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp new file mode 100644 index 0000000..3bd2906 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_15_17/Fig06_17.cpp @@ -0,0 +1,68 @@ +// Fig. 6.17: fig06_17.cpp
+// Demonstrating the order in which constructors and
+// destructors are called.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// include CreateAndDestroy class definition from create.h
+#include "create.h"
+
+void create( void ); // prototype
+
+// global object
+CreateAndDestroy first( 1, "(global before main)" );
+
+int main()
+{
+ cout << "\nMAIN FUNCTION: EXECUTION BEGINS" << endl;
+
+ CreateAndDestroy second( 2, "(local automatic in main)" );
+
+ static CreateAndDestroy third(
+ 3, "(local static in main)" );
+
+ create(); // call function to create objects
+
+ cout << "\nMAIN FUNCTION: EXECUTION RESUMES" << endl;
+
+ CreateAndDestroy fourth( 4, "(local automatic in main)" );
+
+ cout << "\nMAIN FUNCTION: EXECUTION ENDS" << endl;
+
+ return 0;
+
+} // end main
+
+// function to create objects
+void create( void )
+{
+ cout << "\nCREATE FUNCTION: EXECUTION BEGINS" << endl;
+
+ CreateAndDestroy fifth( 5, "(local automatic in create)" );
+
+ static CreateAndDestroy sixth(
+ 6, "(local static in create)" );
+
+ CreateAndDestroy seventh(
+ 7, "(local automatic in create)" );
+
+ cout << "\nCREATE FUNCTION: EXECUTION ENDS" << endl;
+
+} // end function create
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp new file mode 100644 index 0000000..58f5bb9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Fig06_20.cpp @@ -0,0 +1,82 @@ +// Fig. 6.20: fig06_20.cpp
+// Demonstrating the Time class set and get functions
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// include definition of class Time from time3.h
+#include "time3.h"
+
+void incrementMinutes( Time &, const int ); // prototype
+
+int main()
+{
+ Time t; // create Time object
+
+ // set time using individual set functions
+ t.setHour( 17 ); // set hour to valid value
+ t.setMinute( 34 ); // set minute to valid value
+ t.setSecond( 25 ); // set second to valid value
+
+ // use get functions to obtain hour, miunute and second
+ cout << "Result of setting all valid values:\n"
+ << " Hour: " << t.getHour()
+ << " Minute: " << t.getMinute()
+ << " Second: " << t.getSecond();
+
+ // set time using individual set functions
+ t.setHour( 234 ); // invalid hour set to 0
+ t.setMinute( 43 ); // set minute to valid value
+ t.setSecond( 6373 ); // invalid second set to 0
+
+ // display hour, minute and second after setting
+ // invalid hour and second values
+ cout << "\n\nResult of attempting to set invalid hour and"
+ << " second:\n Hour: " << t.getHour()
+ << " Minute: " << t.getMinute()
+ << " Second: " << t.getSecond() << "\n\n";
+
+ t.setTime( 11, 58, 0 ); // set time
+ incrementMinutes( t, 3 ); // increment t's minute by 3
+
+ return 0;
+
+} // end main
+
+// add specified number of minutes to a Time object
+void incrementMinutes( Time &tt, const int count )
+{
+ cout << "Incrementing minute " << count
+ << " times:\nStart time: ";
+ tt.printStandard();
+
+ for ( int i = 0; i < count; i++ ) {
+ tt.setMinute( ( tt.getMinute() + 1 ) % 60 );
+
+ if ( tt.getMinute() == 0 )
+ tt.setHour( ( tt.getHour() + 1 ) % 24 );
+
+ cout << "\nminute + 1: ";
+ tt.printStandard();
+
+ } // end for
+
+ cout << endl;
+
+} // end function incrementMinutes
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.cpp b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.cpp new file mode 100644 index 0000000..7cf0176 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.cpp @@ -0,0 +1,107 @@ +// Fig. 6.19: time3.cpp
+// Member-function definitions for Time class.
+#include <iostream>
+
+using std::cout;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+// include definition of class Time from time3.h
+#include "time3.h"
+
+// constructor function to initialize private data;
+// calls member function setTime to set variables;
+// default values are 0 (see class definition)
+Time::Time( int hr, int min, int sec )
+{
+ setTime( hr, min, sec );
+
+} // end Time constructor
+
+// set hour, minute and second values
+void Time::setTime( int h, int m, int s )
+{
+ setHour( h );
+ setMinute( m );
+ setSecond( s );
+
+} // end function setTime
+
+// set hour value
+void Time::setHour( int h )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+
+} // end function setHour
+
+// set minute value
+void Time::setMinute( int m )
+{
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+
+} // end function setMinute
+
+// set second value
+void Time::setSecond( int s )
+{
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+} // end function setSecond
+
+// return hour value
+int Time::getHour()
+{
+ return hour;
+
+} // end function getHour
+
+// return minute value
+int Time::getMinute()
+{
+ return minute;
+
+} // end function getMinute
+
+// return second value
+int Time::getSecond()
+{
+ return second;
+
+} // end function getSecond
+
+// print Time in universal format
+void Time::printUniversal()
+{
+ cout << setfill( '0' ) << setw( 2 ) << hour << ":"
+ << setw( 2 ) << minute << ":"
+ << setw( 2 ) << second;
+
+} // end function printUniversal
+
+// print Time in standard format
+void Time::printStandard()
+{
+ cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
+ << ":" << setfill( '0' ) << setw( 2 ) << minute
+ << ":" << setw( 2 ) << second
+ << ( hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.h b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.h new file mode 100644 index 0000000..2f68d31 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_18_20/Time3.h @@ -0,0 +1,50 @@ +// Fig. 6.18: time3.h
+// Declaration of class Time.
+// Member functions defined in time3.cpp
+
+// prevent multiple inclusions of header file
+#ifndef TIME3_H
+#define TIME3_H
+
+class Time {
+
+public:
+ Time( int = 0, int = 0, int = 0 ); // default constructor
+
+ // set functions
+ void setTime( int, int, int ); // set hour, minute, second
+ void setHour( int ); // set hour
+ void setMinute( int ); // set minute
+ void setSecond( int ); // set second
+
+ // get functions
+ int getHour(); // return hour
+ int getMinute(); // return minute
+ int getSecond(); // return second
+
+ void printUniversal(); // output universal-time format
+ void printStandard(); // output standard-time format
+
+private:
+ int hour; // 0 - 23 (24-hour clock format)
+ int minute; // 0 - 59
+ int second; // 0 - 59
+
+}; // end clas Time
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp new file mode 100644 index 0000000..a5b14b6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Fig06_23.cpp @@ -0,0 +1,53 @@ +// Fig. 6.23: fig06_23.cpp
+// Demonstrating a public member function that
+// returns a reference to a private data member.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// include definition of class Time from time4.h
+#include "time4.h"
+
+int main()
+{
+ Time t;
+
+ // store in hourRef the reference returned by badSetHour
+ int &hourRef = t.badSetHour( 20 );
+
+ cout << "Hour before modification: " << hourRef;
+
+ // use hourRef to set invalid value in Time object t
+ hourRef = 30;
+
+ cout << "\nHour after modification: " << t.getHour();
+
+ // Dangerous: Function call that returns
+ // a reference can be used as an lvalue!
+ t.badSetHour( 12 ) = 74;
+
+ cout << "\n\n*********************************\n"
+ << "POOR PROGRAMMING PRACTICE!!!!!!!!\n"
+ << "badSetHour as an lvalue, Hour: "
+ << t.getHour()
+ << "\n*********************************" << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.cpp b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.cpp new file mode 100644 index 0000000..eef65f2 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.cpp @@ -0,0 +1,55 @@ +// Fig. 6.22: time4.cpp
+// Member-function definitions for Time class.
+
+// include definition of class Time from time4.h
+#include "time4.h"
+
+// constructor function to initialize private data;
+// calls member function setTime to set variables;
+// default values are 0 (see class definition)
+Time::Time( int hr, int min, int sec )
+{
+ setTime( hr, min, sec );
+
+} // end Time constructor
+
+// set values of hour, minute and second
+void Time::setTime( int h, int m, int s )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+} // end function setTime
+
+// return hour value
+int Time::getHour()
+{
+ return hour;
+
+} // end function getHour
+
+// POOR PROGRAMMING PRACTICE:
+// Returning a reference to a private data member.
+int &Time::badSetHour( int hh )
+{
+ hour = ( hh >= 0 && hh < 24 ) ? hh : 0;
+
+ return hour; // DANGEROUS reference return
+
+} // end function badSetHour
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.h b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.h new file mode 100644 index 0000000..92a5d84 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_21_23/Time4.h @@ -0,0 +1,40 @@ +// Fig. 6.21: time4.h
+// Declaration of class Time.
+// Member functions defined in time4.cpp
+
+// prevent multiple inclusions of header file
+#ifndef TIME4_H
+#define TIME4_H
+
+class Time {
+
+public:
+ Time( int = 0, int = 0, int = 0 );
+ void setTime( int, int, int );
+ int getHour();
+
+ int &badSetHour( int ); // DANGEROUS reference return
+
+private:
+ int hour;
+ int minute;
+ int second;
+
+}; // end class Time
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp b/Bachelor/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp new file mode 100644 index 0000000..9df3198 --- /dev/null +++ b/Bachelor/Prog1/examples/ch06/Fig06_24/Fig06_24.cpp @@ -0,0 +1,72 @@ +// Fig. 6.24: fig06_24.cpp
+// Demonstrating that class objects can be assigned
+// to each other using default memberwise assignment.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// class Date definition
+class Date {
+
+public:
+ Date( int = 1, int = 1, int = 1990 ); // default constructor
+ void print();
+
+private:
+ int month;
+ int day;
+ int year;
+
+}; // end class Date
+
+// Date constructor with no range checking
+Date::Date( int m, int d, int y )
+{
+ month = m;
+ day = d;
+ year = y;
+
+} // end constructor Date
+
+// print Date in the format mm-dd-yyyy
+void Date::print()
+{
+ cout << month << '-' << day << '-' << year;
+
+} // end function print
+
+int main()
+{
+ Date date1( 7, 4, 2002 );
+ Date date2; // date2 defaults to 1/1/1990
+
+ cout << "date1 = ";
+ date1.print();
+ cout << "\ndate2 = ";
+ date2.print();
+
+ date2 = date1; // default memberwise assignment
+
+ cout << "\n\nAfter default memberwise assignment, date2 = ";
+ date2.print();
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp new file mode 100644 index 0000000..e2f9ee2 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Fig07_03.cpp @@ -0,0 +1,42 @@ +// Fig. 7.3: fig07_03.cpp
+// Attempting to access a const object with
+// non-const member functions.
+
+// include Time class definition from time5.h
+#include "time5.h"
+
+int main()
+{
+ Time wakeUp( 6, 45, 0 ); // non-constant object
+ const Time noon( 12, 0, 0 ); // constant object
+
+ // OBJECT MEMBER FUNCTION
+ wakeUp.setHour( 18 ); // non-const non-const
+
+ noon.setHour( 12 ); // const non-const
+
+ wakeUp.getHour(); // non-const const
+
+ noon.getMinute(); // const const
+ noon.printUniversal(); // const const
+
+ noon.printStandard(); // const non-const
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.cpp b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.cpp new file mode 100644 index 0000000..a8e8a6b --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.cpp @@ -0,0 +1,107 @@ +// Fig. 7.2: time5.cpp
+// Member-function definitions for class Time.
+#include <iostream>
+
+using std::cout;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+// include definition of class Time from time5.h
+#include "time5.h"
+
+// constructor function to initialize private data;
+// calls member function setTime to set variables;
+// default values are 0 (see class definition)
+Time::Time( int hour, int minute, int second )
+{
+ setTime( hour, minute, second );
+
+} // end Time constructor
+
+// set hour, minute and second values
+void Time::setTime( int hour, int minute, int second )
+{
+ setHour( hour );
+ setMinute( minute );
+ setSecond( second );
+
+} // end function setTime
+
+// set hour value
+void Time::setHour( int h )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+
+} // end function setHour
+
+// set minute value
+void Time::setMinute( int m )
+{
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+
+} // end function setMinute
+
+// set second value
+void Time::setSecond( int s )
+{
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+} // end function setSecond
+
+// return hour value
+int Time::getHour() const
+{
+ return hour;
+
+} // end function getHour
+
+// return minute value
+int Time::getMinute() const
+{
+ return minute;
+
+} // end function getMinute
+
+// return second value
+int Time::getSecond() const
+{
+ return second;
+
+} // end function getSecond
+
+// print Time in universal format
+void Time::printUniversal() const
+{
+ cout << setfill( '0' ) << setw( 2 ) << hour << ":"
+ << setw( 2 ) << minute << ":"
+ << setw( 2 ) << second;
+
+} // end function printUniversal
+
+// print Time in standard format
+void Time::printStandard()
+{
+ cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
+ << ":" << setfill( '0' ) << setw( 2 ) << minute
+ << ":" << setw( 2 ) << second
+ << ( hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.h b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.h new file mode 100644 index 0000000..25b583e --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_01_03/Time5.h @@ -0,0 +1,49 @@ +// Fig. 7.1: time5.h
+// Definition of class Time.
+// Member functions defined in time5.cpp.
+#ifndef TIME5_H
+#define TIME5_H
+
+class Time {
+
+public:
+ Time( int = 0, int = 0, int = 0 ); // default constructor
+
+ // set functions
+ void setTime( int, int, int ); // set time
+ void setHour( int ); // set hour
+ void setMinute( int ); // set minute
+ void setSecond( int ); // set second
+
+ // get functions (normally declared const)
+ int getHour() const; // return hour
+ int getMinute() const; // return minute
+ int getSecond() const; // return second
+
+ // print functions (normally declared const)
+ void printUniversal() const; // print universal time
+ void printStandard(); // print standard time
+
+private:
+ int hour; // 0 - 23 (24-hour clock format)
+ int minute; // 0 - 59
+ int second; // 0 - 59
+
+}; // end class Time
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp b/Bachelor/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp new file mode 100644 index 0000000..62b4464 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_04/Fig07_04.cpp @@ -0,0 +1,75 @@ +// Fig. 7.4: fig07_04.cpp
+// Using a member initializer to initialize a
+// constant of a built-in data type.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+class Increment {
+
+public:
+ Increment( int c = 0, int i = 1 ); // default constructor
+
+ void addIncrement()
+ {
+ count += increment;
+
+ } // end function addIncrement
+
+ void print() const; // prints count and increment
+
+private:
+ int count;
+ const int increment; // const data member
+
+}; // end class Increment
+
+// constructor
+Increment::Increment( int c, int i )
+ : count( c ), // initializer for non-const member
+ increment( i ) // required initializer for const member
+{
+ // empty body
+
+} // end constructor Increment
+
+// print count and increment values
+void Increment::print() const
+{
+ cout << "count = " << count
+ << ", increment = " << increment << endl;
+
+} // end function print
+
+int main()
+{
+ Increment value( 10, 5 );
+
+ cout << "Before incrementing: ";
+ value.print();
+
+ for ( int j = 0; j < 3; j++ ) {
+ value.addIncrement();
+ cout << "After increment " << j + 1 << ": ";
+ value.print();
+ }
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp b/Bachelor/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp new file mode 100644 index 0000000..f7945b4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_05/Fig07_05.cpp @@ -0,0 +1,74 @@ +// Fig. 7.5: fig07_05.cpp
+// Attempting to initialize a constant of
+// a built-in data type with an assignment.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+class Increment {
+
+public:
+ Increment( int c = 0, int i = 1 ); // default constructor
+
+ void addIncrement()
+ {
+ count += increment;
+
+ } // end function addIncrement
+
+ void print() const; // prints count and increment
+
+private:
+ int count;
+ const int increment; // const data member
+
+}; // end class Increment
+
+// constructor
+Increment::Increment( int c, int i )
+{ // Constant member 'increment' is not initialized
+ count = c; // allowed because count is not constant
+ increment = i; // ERROR: Cannot modify a const object
+
+} // end constructor Increment
+
+// print count and increment values
+void Increment::print() const
+{
+ cout << "count = " << count
+ << ", increment = " << increment << endl;
+
+} // end function print
+
+int main()
+{
+ Increment value( 10, 5 );
+
+ cout << "Before incrementing: ";
+ value.print();
+
+ for ( int j = 0; j < 3; j++ ) {
+ value.addIncrement();
+ cout << "After increment " << j + 1 << ": ";
+ value.print();
+ }
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.cpp b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.cpp new file mode 100644 index 0000000..ef3818b --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.cpp @@ -0,0 +1,85 @@ +// Fig. 7.7: date1.cpp
+// Member-function definitions for class Date.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// include Date class definition from date1.h
+#include "date1.h"
+
+// constructor confirms proper value for month; calls
+// utility function checkDay to confirm proper value for day
+Date::Date( int mn, int dy, int yr )
+{
+ if ( mn > 0 && mn <= 12 ) // validate the month
+ month = mn;
+
+ else { // invalid month set to 1
+ month = 1;
+ cout << "Month " << mn << " invalid. Set to month 1.\n";
+ }
+
+ year = yr; // should validate yr
+ day = checkDay( dy ); // validate the day
+
+ // output Date object to show when its constructor is called
+ cout << "Date object constructor for date ";
+ print();
+ cout << endl;
+
+} // end Date constructor
+
+// print Date object in form month/day/year
+void Date::print() const
+{
+ cout << month << '/' << day << '/' << year;
+
+} // end function print
+
+// output Date object to show when its destructor is called
+Date::~Date()
+{
+ cout << "Date object destructor for date ";
+ print();
+ cout << endl;
+
+} // end ~Date destructor
+
+// utility function to confirm proper day value based on
+// month and year; handles leap years, too
+int Date::checkDay( int testDay ) const
+{
+ static const int daysPerMonth[ 13 ] =
+ { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+ // determine whether testDay is valid for specified month
+ if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
+ return testDay;
+
+ // February 29 check for leap year
+ if ( month == 2 && testDay == 29 &&
+ ( year % 400 == 0 ||
+ ( year % 4 == 0 && year % 100 != 0 ) ) )
+ return testDay;
+
+ cout << "Day " << testDay << " invalid. Set to day 1.\n";
+
+ return 1; // leave object in consistent state if bad value
+
+} // end function checkDay
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.h b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.h new file mode 100644 index 0000000..5829c71 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Date1.h @@ -0,0 +1,39 @@ +// Fig. 7.6: date1.h
+// Date class definition.
+// Member functions defined in date1.cpp
+#ifndef DATE1_H
+#define DATE1_H
+
+class Date {
+
+public:
+ Date( int = 1, int = 1, int = 1900 ); // default constructor
+ void print() const; // print date in month/day/year format
+ ~Date(); // provided to confirm destruction order
+
+private:
+ int month; // 1-12 (January-December)
+ int day; // 1-31 based on month
+ int year; // any year
+
+ // utility function to test proper day for month and year
+ int checkDay( int ) const;
+
+}; // end class Date
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.cpp b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.cpp new file mode 100644 index 0000000..6cc742a --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.cpp @@ -0,0 +1,72 @@ +// Fig. 7.9: employee1.cpp
+// Member-function definitions for class Employee.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <cstring> // strcpy and strlen prototypes
+
+#include "employee1.h" // Employee class definition
+#include "date1.h" // Date class definition
+
+// constructor uses member initializer list to pass initializer
+// values to constructors of member objects birthDate and
+// hireDate [Note: This invokes the so-called "default copy
+// constructor" which the C++ compiler provides implicitly.]
+Employee::Employee( const char *first, const char *last,
+ const Date &dateOfBirth, const Date &dateOfHire )
+ : birthDate( dateOfBirth ), // initialize birthDate
+ hireDate( dateOfHire ) // initialize hireDateba
+{
+ // copy first into firstName and be sure that it fits
+ int length = strlen( first );
+ length = ( length < 25 ? length : 24 );
+ strncpy( firstName, first, length );
+ firstName[ length ] = '\0';
+
+ // copy last into lastName and be sure that it fits
+ length = strlen( last );
+ length = ( length < 25 ? length : 24 );
+ strncpy( lastName, last, length );
+ lastName[ length ] = '\0';
+
+ // output Employee object to show when constructor is called
+ cout << "Employee object constructor: "
+ << firstName << ' ' << lastName << endl;
+
+} // end Employee constructor
+
+// print Employee object
+void Employee::print() const
+{
+ cout << lastName << ", " << firstName << "\nHired: ";
+ hireDate.print();
+ cout << " Birth date: ";
+ birthDate.print();
+ cout << endl;
+
+} // end function print
+
+// output Employee object to show when its destructor is called
+Employee::~Employee()
+{
+ cout << "Employee object destructor: "
+ << lastName << ", " << firstName << endl;
+
+} // end ~Employee destructor
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.h b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.h new file mode 100644 index 0000000..cfc294a --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Employee1.h @@ -0,0 +1,42 @@ +// Fig. 7.8: employee1.h
+// Employee class definition.
+// Member functions defined in employee1.cpp.
+#ifndef EMPLY1_H
+#define EMPLY1_H
+
+// include Date class definition from date1.h
+#include "date1.h"
+
+class Employee {
+
+public:
+ Employee(
+ const char *, const char *, const Date &, const Date & );
+
+ void print() const;
+ ~Employee(); // provided to confirm destruction order
+
+private:
+ char firstName[ 25 ];
+ char lastName[ 25 ];
+ const Date birthDate; // composition: member object
+ const Date hireDate; // composition: member object
+
+}; // end class Employee
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp new file mode 100644 index 0000000..90dfc9b --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_06_10/Fig07_10.cpp @@ -0,0 +1,40 @@ +// Fig. 7.10: fig07_10.cpp
+// Demonstrating composition--an object with member objects.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "employee1.h" // Employee class definition
+
+int main()
+{
+ Date birth( 7, 24, 1949 );
+ Date hire( 3, 12, 1988 );
+ Employee manager( "Bob", "Jones", birth, hire );
+
+ cout << '\n';
+ manager.print();
+
+ cout << "\nTest Date constructor with invalid values:\n";
+ Date lastDayOff( 14, 35, 1994 ); // invalid month and day
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp b/Bachelor/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp new file mode 100644 index 0000000..995bc86 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_11/Fig07_11.cpp @@ -0,0 +1,72 @@ +// Fig. 7.11: fig07_11.cpp
+// Friends can access private members of a class.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// Count class definition
+// (note that there is no friendship declaration)
+class Count {
+ friend void setX( Count &, int ); // friend declaration
+
+public:
+
+ // constructor
+ Count()
+ : x( 0 ) // initialize x to 0
+ {
+ // empty body
+
+ } // end constructor Count
+
+ // output x
+ void print() const
+ {
+ cout << x << endl;
+
+ } // end function print
+
+private:
+ int x; // data member
+
+}; // end class Count
+
+// function setX can modify private data of Count
+// because setX is declared as a friend of Count
+void setX( Count &c, int val )
+{
+ c.x = val; // legal: setX is a friend of Count
+
+} // end function setX
+
+int main()
+{
+ Count counter; // create Count object
+
+ cout << "counter.x after instantiation: ";
+ counter.print();
+
+ setX( counter, 8 ); // set x with a friend
+
+ cout << "counter.x after call to setX friend function: ";
+ counter.print();
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp b/Bachelor/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp new file mode 100644 index 0000000..dbab9fc --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_12/Fig07_12.cpp @@ -0,0 +1,65 @@ +// Fig. 7.12: fig07_12.cpp
+// Non-friend/non-member functions cannot access
+// private data of a class.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+// Count class definition
+class Count {
+
+public:
+
+ // constructor
+ Count()
+ : x( 0 ) // initialize x to 0
+ {
+ // empty body
+
+ } // end constructor Count
+
+ // output x
+ void print() const
+ {
+ cout << x << endl;
+
+ } // end function print
+
+private:
+ int x; // data member
+
+}; // end class Count
+
+// function tries to modify private data of Count,
+// but cannot because function is not a friend of Count
+void cannotSetX( Count &c, int val )
+{
+ c.x = val; // ERROR: cannot access private member in Count
+
+} // end function cannotSetX
+
+int main()
+{
+ Count counter; // create Count object
+
+ cannotSetX( counter, 3 ); // cannotSetX is not a friend
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp b/Bachelor/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp new file mode 100644 index 0000000..2e385a4 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_13/Fig07_13.cpp @@ -0,0 +1,66 @@ +// Fig. 7.13: fig07_13.cpp
+// Using the this pointer to refer to object members.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+class Test {
+
+public:
+ Test( int = 0 ); // default constructor
+ void print() const;
+
+private:
+ int x;
+
+}; // end class Test
+
+// constructor
+Test::Test( int value )
+ : x( value ) // initialize x to value
+{
+ // empty body
+
+} // end constructor Test
+
+// print x using implicit and explicit this pointers;
+// parentheses around *this required
+void Test::print() const
+{
+ // implicitly use this pointer to access member x
+ cout << " x = " << x;
+
+ // explicitly use this pointer to access member x
+ cout << "\n this->x = " << this->x;
+
+ // explicitly use dereferenced this pointer and
+ // the dot operator to access member x
+ cout << "\n(*this).x = " << ( *this ).x << endl;
+
+} // end function print
+
+int main()
+{
+ Test testObject( 12 );
+
+ testObject.print();
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp new file mode 100644 index 0000000..70e7a64 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Fig07_16.cpp @@ -0,0 +1,48 @@ +// Fig. 7.16: fig07_16.cpp
+// Cascading member function calls with the this pointer.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "time6.h" // Time class definition
+
+int main()
+{
+ Time t;
+
+ // cascaded function calls
+ t.setHour( 18 ).setMinute( 30 ).setSecond( 22 );
+
+ // output time in universal and standard formats
+ cout << "Universal time: ";
+ t.printUniversal();
+
+ cout << "\nStandard time: ";
+ t.printStandard();
+
+ cout << "\n\nNew standard time: ";
+
+ // cascaded function calls
+ t.setTime( 20, 20, 20 ).printStandard();
+
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.cpp b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.cpp new file mode 100644 index 0000000..97205c0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.cpp @@ -0,0 +1,114 @@ +// Fig. 7.15: time6.cpp
+// Member-function definitions for Time class.
+#include <iostream>
+
+using std::cout;
+
+#include <iomanip>
+
+using std::setfill;
+using std::setw;
+
+#include "time6.h" // Time class definition
+
+// constructor function to initialize private data;
+// calls member function setTime to set variables;
+// default values are 0 (see class definition)
+Time::Time( int hr, int min, int sec )
+{
+ setTime( hr, min, sec );
+
+} // end Time constructor
+
+// set values of hour, minute, and second
+Time &Time::setTime( int h, int m, int s )
+{
+ setHour( h );
+ setMinute( m );
+ setSecond( s );
+
+ return *this; // enables cascading
+
+} // end function setTime
+
+// set hour value
+Time &Time::setHour( int h )
+{
+ hour = ( h >= 0 && h < 24 ) ? h : 0;
+
+ return *this; // enables cascading
+
+} // end function setHour
+
+// set minute value
+Time &Time::setMinute( int m )
+{
+ minute = ( m >= 0 && m < 60 ) ? m : 0;
+
+ return *this; // enables cascading
+
+} // end function setMinute
+
+// set second value
+Time &Time::setSecond( int s )
+{
+ second = ( s >= 0 && s < 60 ) ? s : 0;
+
+ return *this; // enables cascading
+
+} // end function setSecond
+
+// get hour value
+int Time::getHour() const
+{
+ return hour;
+
+} // end function getHour
+
+// get minute value
+int Time::getMinute() const
+{
+ return minute;
+
+} // end function getMinute
+
+// get second value
+int Time::getSecond() const
+{
+ return second;
+
+} // end function getSecond
+
+// print Time in universal format
+void Time::printUniversal() const
+{
+ cout << setfill( '0' ) << setw( 2 ) << hour << ":"
+ << setw( 2 ) << minute << ":"
+ << setw( 2 ) << second;
+
+} // end function printUniversal
+
+// print Time in standard format
+void Time::printStandard() const
+{
+ cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
+ << ":" << setfill( '0' ) << setw( 2 ) << minute
+ << ":" << setw( 2 ) << second
+ << ( hour < 12 ? " AM" : " PM" );
+
+} // end function printStandard
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.h b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.h new file mode 100644 index 0000000..d9413ca --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_14_16/Time6.h @@ -0,0 +1,51 @@ +// Fig. 7.14: time6.h
+// Cascading member function calls.
+
+// Time class definition.
+// Member functions defined in time6.cpp.
+#ifndef TIME6_H
+#define TIME6_H
+
+class Time {
+
+public:
+ Time( int = 0, int = 0, int = 0 ); // default constructor
+
+ // set functions
+ Time &setTime( int, int, int ); // set hour, minute, second
+ Time &setHour( int ); // set hour
+ Time &setMinute( int ); // set minute
+ Time &setSecond( int ); // set second
+
+ // get functions (normally declared const)
+ int getHour() const; // return hour
+ int getMinute() const; // return minute
+ int getSecond() const; // return second
+
+ // print functions (normally declared const)
+ void printUniversal() const; // print universal time
+ void printStandard() const; // print standard time
+
+private:
+ int hour; // 0 - 23 (24-hour clock format)
+ int minute; // 0 - 59
+ int second; // 0 - 59
+
+}; // end class Time
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp b/Bachelor/Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp new file mode 100644 index 0000000..27ba9f7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_17_19/Fig07_19.cpp @@ -0,0 +1,55 @@ +// Fig. 7.19: fig07_19.cpp
+// Driver to test class Employee.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <new> // C++ standard new operator
+
+#include "employee2.h" // Employee class definition
+
+int main()
+{
+ cout << "Number of employees before instantiation is "
+ << Employee::getCount() << endl; // use class name
+
+ Employee *e1Ptr = new Employee( "Susan", "Baker" );
+ Employee *e2Ptr = new Employee( "Robert", "Jones" );
+
+ cout << "Number of employees after instantiation is "
+ << e1Ptr->getCount();
+
+ cout << "\n\nEmployee 1: "
+ << e1Ptr->getFirstName()
+ << " " << e1Ptr->getLastName()
+ << "\nEmployee 2: "
+ << e2Ptr->getFirstName()
+ << " " << e2Ptr->getLastName() << "\n\n";
+
+ delete e1Ptr; // recapture memory
+ e1Ptr = 0; // disconnect pointer from free-store space
+ delete e2Ptr; // recapture memory
+ e2Ptr = 0; // disconnect pointer from free-store space
+
+ cout << "Number of employees after deletion is "
+ << Employee::getCount() << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.cpp b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.cpp new file mode 100644 index 0000000..540f367 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.cpp @@ -0,0 +1,88 @@ +// Fig. 7.18: employee2.cpp
+// Member-function definitions for class Employee.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <new> // C++ standard new operator
+#include <cstring> // strcpy and strlen prototypes
+
+#include "employee2.h" // Employee class definition
+
+// define and initialize static data member
+int Employee::count = 0;
+
+// define static member function that returns number of
+// Employee objects instantiated
+int Employee::getCount()
+{
+ return count;
+
+} // end static function getCount
+
+// constructor dynamically allocates space for
+// first and last name and uses strcpy to copy
+// first and last names into the object
+Employee::Employee( const char *first, const char *last )
+{
+ firstName = new char[ strlen( first ) + 1 ];
+ strcpy( firstName, first );
+
+ lastName = new char[ strlen( last ) + 1 ];
+ strcpy( lastName, last );
+
+ ++count; // increment static count of employees
+
+ cout << "Employee constructor for " << firstName
+ << ' ' << lastName << " called." << endl;
+
+} // end Employee constructor
+
+// destructor deallocates dynamically allocated memory
+Employee::~Employee()
+{
+ cout << "~Employee() called for " << firstName
+ << ' ' << lastName << endl;
+
+ delete [] firstName; // recapture memory
+ delete [] lastName; // recapture memory
+
+ --count; // decrement static count of employees
+
+} // end ~Employee destructor
+
+// return first name of employee
+const char *Employee::getFirstName() const
+{
+ // const before return type prevents client from modifying
+ // private data; client should copy returned string before
+ // destructor deletes storage to prevent undefined pointer
+ return firstName;
+
+} // end function getFirstName
+
+// return last name of employee
+const char *Employee::getLastName() const
+{
+ // const before return type prevents client from modifying
+ // private data; client should copy returned string before
+ // destructor deletes storage to prevent undefined pointer
+ return lastName;
+
+} // end function getLastName
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.h b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.h new file mode 100644 index 0000000..3010210 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_17_19/employee2.h @@ -0,0 +1,41 @@ +// Fig. 7.17: employee2.h
+// Employee class definition.
+#ifndef EMPLOYEE2_H
+#define EMPLOYEE2_H
+
+class Employee {
+
+public:
+ Employee( const char *, const char * ); // constructor
+ ~Employee(); // destructor
+ const char *getFirstName() const; // return first name
+ const char *getLastName() const; // return last name
+
+ // static member function
+ static int getCount(); // return # objects instantiated
+
+private:
+ char *firstName;
+ char *lastName;
+
+ // static data member
+ static int count; // number of objects instantiated
+
+}; // end class Employee
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp b/Bachelor/Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp new file mode 100644 index 0000000..a11a543 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/fig07_23.cpp @@ -0,0 +1,39 @@ +// Fig. 7.23: fig07_23.cpp
+// Hiding a class’s private data with a proxy class.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "interface.h" // Interface class definition
+
+int main()
+{
+ Interface i( 5 );
+
+ cout << "Interface contains: " << i.getValue()
+ << " before setValue" << endl;
+
+ i.setValue( 10 );
+
+ cout << "Interface contains: " << i.getValue()
+ << " after setValue" << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_20_23/implementation.h b/Bachelor/Prog1/examples/ch07/Fig07_20_23/implementation.h new file mode 100644 index 0000000..1630a50 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/implementation.h @@ -0,0 +1,48 @@ +// Fig. 7.20: implementation.h
+// Header file for class Implementation
+
+class Implementation {
+
+public:
+
+ // constructor
+ Implementation( int v )
+ : value( v ) // initialize value with v
+ {
+ // empty body
+
+ } // end constructor Implementation
+
+ // set value to v
+ void setValue( int v )
+ {
+ value = v; // should validate v
+
+ } // end function setValue
+
+ // return value
+ int getValue() const
+ {
+ return value;
+
+ } // end function getValue
+
+private:
+ int value;
+
+}; // end class Implementation
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.cpp b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.cpp new file mode 100644 index 0000000..0f895fd --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.cpp @@ -0,0 +1,48 @@ +// Fig. 7.22: interface.cpp
+// Definition of class Interface
+#include "interface.h" // Interface class definition
+#include "implementation.h" // Implementation class definition
+
+// constructor
+Interface::Interface( int v )
+ : ptr ( new Implementation( v ) ) // initialize ptr
+{
+ // empty body
+
+} // end Interface constructor
+
+// call Implementation's setValue function
+void Interface::setValue( int v )
+{
+ ptr->setValue( v );
+
+} // end function setValue
+
+// call Implementation's getValue function
+int Interface::getValue() const
+{
+ return ptr->getValue();
+
+} // end function getValue
+
+// destructor
+Interface::~Interface()
+{
+ delete ptr;
+
+} // end ~Interface destructor
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.h b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.h new file mode 100644 index 0000000..5d229e1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch07/Fig07_20_23/interface.h @@ -0,0 +1,34 @@ +// Fig. 7.21: interface.h
+// Header file for interface.cpp
+
+class Implementation; // forward class declaration
+
+class Interface {
+
+public:
+ Interface( int );
+ void setValue( int ); // same public interface as
+ int getValue() const; // class Implementation
+ ~Interface();
+
+private:
+
+ // requires previous forward declaration (line 4)
+ Implementation *ptr;
+
+}; // end class Interface
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp b/Bachelor/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp new file mode 100644 index 0000000..ac5e434 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_03/Fig08_03.cpp @@ -0,0 +1,89 @@ +// Fig. 8.3: fig08_03.cpp
+// Overloading the stream-insertion and
+// stream-extraction operators.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+using std::ostream;
+using std::istream;
+
+#include <iomanip>
+
+using std::setw;
+
+// PhoneNumber class definition
+class PhoneNumber {
+ friend ostream &operator<<( ostream&, const PhoneNumber & );
+ friend istream &operator>>( istream&, PhoneNumber & );
+
+private:
+ char areaCode[ 4 ]; // 3-digit area code and null
+ char exchange[ 4 ]; // 3-digit exchange and null
+ char line[ 5 ]; // 4-digit line and null
+
+}; // end class PhoneNumber
+
+// overloaded stream-insertion operator; cannot be
+// a member function if we would like to invoke it with
+// cout << somePhoneNumber;
+ostream &operator<<( ostream &output, const PhoneNumber &num )
+{
+ output << "(" << num.areaCode << ") "
+ << num.exchange << "-" << num.line;
+
+ return output; // enables cout << a << b << c;
+
+} // end function operator<<
+
+// overloaded stream-extraction operator; cannot be
+// a member function if we would like to invoke it with
+// cin >> somePhoneNumber;
+istream &operator>>( istream &input, PhoneNumber &num )
+{
+ input.ignore(); // skip (
+ input >> setw( 4 ) >> num.areaCode; // input area code
+ input.ignore( 2 ); // skip ) and space
+ input >> setw( 4 ) >> num.exchange; // input exchange
+ input.ignore(); // skip dash (-)
+ input >> setw( 5 ) >> num.line; // input line
+
+ return input; // enables cin >> a >> b >> c;
+
+} // end function operator>>
+
+int main()
+{
+ PhoneNumber phone; // create object phone
+
+ cout << "Enter phone number in the form (123) 456-7890:\n";
+
+ // cin >> phone invokes operator>> by implicitly issuing
+ // the non-member function call operator>>( cin, phone )
+ cin >> phone;
+
+ cout << "The phone number entered was: ";
+
+ // cout << phone invokes operator<< by implicitly issuing
+ // the non-member function call operator<<( cout, phone )
+ cout << phone << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.cpp new file mode 100644 index 0000000..817f7ec --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.cpp @@ -0,0 +1,177 @@ +// Fig 8.5: array1.cpp
+// Member function definitions for class Array
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <new> // C++ standard "new" operator
+
+#include <cstdlib> // exit function prototype
+
+#include "array1.h" // Array class definition
+
+// default constructor for class Array (default size 10)
+Array::Array( int arraySize )
+{
+ // validate arraySize
+ size = ( arraySize > 0 ? arraySize : 10 );
+
+ ptr = new int[ size ]; // create space for array
+
+ for ( int i = 0; i < size; i++ )
+ ptr[ i ] = 0; // initialize array
+
+} // end Array default constructor
+
+// copy constructor for class Array;
+// must receive a reference to prevent infinite recursion
+Array::Array( const Array &arrayToCopy )
+ : size( arrayToCopy.size )
+{
+ ptr = new int[ size ]; // create space for array
+
+ for ( int i = 0; i < size; i++ )
+ ptr[ i ] = arrayToCopy.ptr[ i ]; // copy into object
+
+} // end Array copy constructor
+
+// destructor for class Array
+Array::~Array()
+{
+ delete [] ptr; // reclaim array space
+
+} // end destructor
+
+// return size of array
+int Array::getSize() const
+{
+ return size;
+
+} // end function getSize
+
+// overloaded assignment operator;
+// const return avoids: ( a1 = a2 ) = a3
+const Array &Array::operator=( const Array &right )
+{
+ if ( &right != this ) { // check for self-assignment
+
+ // for arrays of different sizes, deallocate original
+ // left-side array, then allocate new left-side array
+ if ( size != right.size ) {
+ delete [] ptr; // reclaim space
+ size = right.size; // resize this object
+ ptr = new int[ size ]; // create space for array copy
+
+ } // end inner if
+
+ for ( int i = 0; i < size; i++ )
+ ptr[ i ] = right.ptr[ i ]; // copy array into object
+
+ } // end outer if
+
+ return *this; // enables x = y = z, for example
+
+} // end function operator=
+
+// determine if two arrays are equal and
+// return true, otherwise return false
+bool Array::operator==( const Array &right ) const
+{
+ if ( size != right.size )
+ return false; // arrays of different sizes
+
+ for ( int i = 0; i < size; i++ )
+
+ if ( ptr[ i ] != right.ptr[ i ] )
+ return false; // arrays are not equal
+
+ return true; // arrays are equal
+
+} // end function operator==
+
+// overloaded subscript operator for non-const Arrays
+// reference return creates an lvalue
+int &Array::operator[]( int subscript )
+{
+ // check for subscript out of range error
+ if ( subscript < 0 || subscript >= size ) {
+ cout << "\nError: Subscript " << subscript
+ << " out of range" << endl;
+
+ exit( 1 ); // terminate program; subscript out of range
+
+ } // end if
+
+ return ptr[ subscript ]; // reference return
+
+} // end function operator[]
+
+// overloaded subscript operator for const Arrays
+// const reference return creates an rvalue
+const int &Array::operator[]( int subscript ) const
+{
+ // check for subscript out of range error
+ if ( subscript < 0 || subscript >= size ) {
+ cout << "\nError: Subscript " << subscript
+ << " out of range" << endl;
+
+ exit( 1 ); // terminate program; subscript out of range
+
+ } // end if
+
+ return ptr[ subscript ]; // const reference return
+
+} // end function operator[]
+
+// overloaded input operator for class Array;
+// inputs values for entire array
+istream &operator>>( istream &input, Array &a )
+{
+ for ( int i = 0; i < a.size; i++ )
+ input >> a.ptr[ i ];
+
+ return input; // enables cin >> x >> y;
+
+} // end function
+
+// overloaded output operator for class Array
+ostream &operator<<( ostream &output, const Array &a )
+{
+ int i;
+
+ // output private ptr-based array
+ for ( i = 0; i < a.size; i++ ) {
+ output << setw( 12 ) << a.ptr[ i ];
+
+ if ( ( i + 1 ) % 4 == 0 ) // 4 numbers per row of output
+ output << endl;
+
+ } // end for
+
+ if ( i % 4 != 0 ) // end last line of output
+ output << endl;
+
+ return output; // enables cout << x << y;
+
+} // end function operator<<
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.h b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.h new file mode 100644 index 0000000..d84bc81 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Array1.h @@ -0,0 +1,61 @@ +// Fig. 8.4: array1.h
+// Array class for storing arrays of integers.
+#ifndef ARRAY1_H
+#define ARRAY1_H
+
+#include <iostream>
+
+using std::ostream;
+using std::istream;
+
+class Array {
+ friend ostream &operator<<( ostream &, const Array & );
+ friend istream &operator>>( istream &, Array & );
+
+public:
+ Array( int = 10 ); // default constructor
+ Array( const Array & ); // copy constructor
+ ~Array(); // destructor
+ int getSize() const; // return size
+
+ // assignment operator
+ const Array &operator=( const Array & );
+
+ // equality operator
+ bool operator==( const Array & ) const;
+
+ // inequality operator; returns opposite of == operator
+ bool operator!=( const Array &right ) const
+ {
+ return ! ( *this == right ); // invokes Array::operator==
+
+ } // end function operator!=
+
+ // subscript operator for non-const objects returns lvalue
+ int &operator[]( int );
+
+ // subscript operator for const objects returns rvalue
+ const int &operator[]( int ) const;
+
+private:
+ int size; // array size
+ int *ptr; // pointer to first element of array
+
+}; // end class Array
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp new file mode 100644 index 0000000..29178eb --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_04_06/Fig08_06.cpp @@ -0,0 +1,90 @@ +// Fig. 8.6: fig08_06.cpp
+// Array class test program.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include "array1.h"
+
+int main()
+{
+ Array integers1( 7 ); // seven-element Array
+ Array integers2; // 10-element Array by default
+
+ // print integers1 size and contents
+ cout << "Size of array integers1 is "
+ << integers1.getSize()
+ << "\nArray after initialization:\n" << integers1;
+
+ // print integers2 size and contents
+ cout << "\nSize of array integers2 is "
+ << integers2.getSize()
+ << "\nArray after initialization:\n" << integers2;
+
+ // input and print integers1 and integers2
+ cout << "\nInput 17 integers:\n";
+ cin >> integers1 >> integers2;
+
+ cout << "\nAfter input, the arrays contain:\n"
+ << "integers1:\n" << integers1
+ << "integers2:\n" << integers2;
+
+ // use overloaded inequality (!=) operator
+ cout << "\nEvaluating: integers1 != integers2\n";
+
+ if ( integers1 != integers2 )
+ cout << "integers1 and integers2 are not equal\n";
+
+ // create array integers3 using integers1 as an
+ // initializer; print size and contents
+ Array integers3( integers1 ); // calls copy constructor
+
+ cout << "\nSize of array integers3 is "
+ << integers3.getSize()
+ << "\nArray after initialization:\n" << integers3;
+
+ // use overloaded assignment (=) operator
+ cout << "\nAssigning integers2 to integers1:\n";
+ integers1 = integers2; // note target is smaller
+
+ cout << "integers1:\n" << integers1
+ << "integers2:\n" << integers2;
+
+ // use overloaded equality (==) operator
+ cout << "\nEvaluating: integers1 == integers2\n";
+
+ if ( integers1 == integers2 )
+ cout << "integers1 and integers2 are equal\n";
+
+ // use overloaded subscript operator to create rvalue
+ cout << "\nintegers1[5] is " << integers1[ 5 ];
+
+ // use overloaded subscript operator to create lvalue
+ cout << "\n\nAssigning 1000 to integers1[5]\n";
+ integers1[ 5 ] = 1000;
+ cout << "integers1:\n" << integers1;
+
+ // attempt to use out-of-range subscript
+ cout << "\nAttempt to assign 1000 to integers1[15]" << endl;
+ integers1[ 15 ] = 1000; // ERROR: out of range
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp b/Bachelor/Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp new file mode 100644 index 0000000..9a9d516 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_07_09/Fig08_09.cpp @@ -0,0 +1,101 @@ +// Fig. 8.9: fig08_09.cpp
+// String class test program.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "string1.h"
+
+int main()
+{
+ String s1( "happy" );
+ String s2( " birthday" );
+ String s3;
+
+ // test overloaded equality and relational operators
+ cout << "s1 is \"" << s1 << "\"; s2 is \"" << s2
+ << "\"; s3 is \"" << s3 << '\"'
+ << "\n\nThe results of comparing s2 and s1:"
+ << "\ns2 == s1 yields "
+ << ( s2 == s1 ? "true" : "false" )
+ << "\ns2 != s1 yields "
+ << ( s2 != s1 ? "true" : "false" )
+ << "\ns2 > s1 yields "
+ << ( s2 > s1 ? "true" : "false" )
+ << "\ns2 < s1 yields "
+ << ( s2 < s1 ? "true" : "false" )
+ << "\ns2 >= s1 yields "
+ << ( s2 >= s1 ? "true" : "false" )
+ << "\ns2 <= s1 yields "
+ << ( s2 <= s1 ? "true" : "false" );
+
+ // test overloaded String empty (!) operator
+ cout << "\n\nTesting !s3:\n";
+
+ if ( !s3 ) {
+ cout << "s3 is empty; assigning s1 to s3;\n";
+ s3 = s1; // test overloaded assignment
+ cout << "s3 is \"" << s3 << "\"";
+ }
+
+ // test overloaded String concatenation operator
+ cout << "\n\ns1 += s2 yields s1 = ";
+ s1 += s2; // test overloaded concatenation
+ cout << s1;
+
+ // test conversion constructor
+ cout << "\n\ns1 += \" to you\" yields\n";
+ s1 += " to you"; // test conversion constructor
+ cout << "s1 = " << s1 << "\n\n";
+
+ // test overloaded function call operator () for substring
+ cout << "The substring of s1 starting at\n"
+ << "location 0 for 14 characters, s1(0, 14), is:\n"
+ << s1( 0, 14 ) << "\n\n";
+
+ // test substring "to-end-of-String" option
+ cout << "The substring of s1 starting at\n"
+ << "location 15, s1(15, 0), is: "
+ << s1( 15, 0 ) << "\n\n"; // 0 is "to end of string"
+
+ // test copy constructor
+ String *s4Ptr = new String( s1 );
+ cout << "\n*s4Ptr = " << *s4Ptr << "\n\n";
+
+ // test assignment (=) operator with self-assignment
+ cout << "assigning *s4Ptr to *s4Ptr\n";
+ *s4Ptr = *s4Ptr; // test overloaded assignment
+ cout << "*s4Ptr = " << *s4Ptr << '\n';
+
+ // test destructor
+ delete s4Ptr;
+
+ // test using subscript operator to create lvalue
+ s1[ 0 ] = 'H';
+ s1[ 6 ] = 'B';
+ cout << "\ns1 after s1[0] = 'H' and s1[6] = 'B' is: "
+ << s1 << "\n\n";
+
+ // test subscript out of range
+ cout << "Attempt to assign 'd' to s1[30] yields:" << endl;
+ s1[ 30 ] = 'd'; // ERROR: subscript out of range
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.cpp new file mode 100644 index 0000000..7cca6d7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.cpp @@ -0,0 +1,221 @@ +// Fig. 8.8: string1.cpp
+// Member function definitions for class String.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <new> // C++ standard "new" operator
+
+#include <cstring> // strcpy and strcat prototypes
+#include <cstdlib> // exit prototype
+
+#include "string1.h" // String class definition
+
+// conversion constructor converts char * to String
+String::String( const char *s )
+ : length( ( s != 0 ) ? strlen( s ) : 0 )
+{
+ cout << "Conversion constructor: " << s << '\n';
+ setString( s ); // call utility function
+
+} // end String conversion constructor
+
+// copy constructor
+String::String( const String © )
+ : length( copy.length )
+{
+ cout << "Copy constructor: " << copy.sPtr << '\n';
+ setString( copy.sPtr ); // call utility function
+
+} // end String copy constructor
+
+// Destructor
+String::~String()
+{
+ cout << "Destructor: " << sPtr << '\n';
+ delete [] sPtr; // reclaim string
+
+} // end ~String destructor
+
+// overloaded = operator; avoids self assignment
+const String &String::operator=( const String &right )
+{
+ cout << "operator= called\n";
+
+ if ( &right != this ) { // avoid self assignment
+ delete [] sPtr; // prevents memory leak
+ length = right.length; // new String length
+ setString( right.sPtr ); // call utility function
+ }
+
+ else
+ cout << "Attempted assignment of a String to itself\n";
+
+ return *this; // enables cascaded assignments
+
+} // end function operator=
+
+// concatenate right operand to this object and
+// store in this object.
+const String &String::operator+=( const String &right )
+{
+ size_t newLength = length + right.length; // new length
+ char *tempPtr = new char[ newLength + 1 ]; // create memory
+
+ strcpy( tempPtr, sPtr ); // copy sPtr
+ strcpy( tempPtr + length, right.sPtr ); // copy right.sPtr
+
+ delete [] sPtr; // reclaim old space
+ sPtr = tempPtr; // assign new array to sPtr
+ length = newLength; // assign new length to length
+
+ return *this; // enables cascaded calls
+
+} // end function operator+=
+
+// is this String empty?
+bool String::operator!() const
+{
+ return length == 0;
+
+} // end function operator!
+
+// Is this String equal to right String?
+bool String::operator==( const String &right ) const
+{
+ return strcmp( sPtr, right.sPtr ) == 0;
+
+} // end function operator==
+
+// Is this String less than right String?
+bool String::operator<( const String &right ) const
+{
+ return strcmp( sPtr, right.sPtr ) < 0;
+
+} // end function operator<
+
+// return reference to character in String as lvalue
+char &String::operator[]( int subscript )
+{
+ // test for subscript out of range
+ if( subscript < 0 || subscript >= length ) {
+ cout << "Error: Subscript " << subscript
+ << " out of range" << endl;
+
+ exit( 1 ); // terminate program
+ }
+
+ return sPtr[ subscript ]; // creates lvalue
+
+} // end function operator[]
+
+// return reference to character in String as rvalue
+const char &String::operator[]( int subscript ) const
+{
+ // test for subscript out of range
+ if( subscript < 0 || subscript >= length ) {
+ cout << "Error: Subscript " << subscript
+ << " out of range" << endl;
+
+ exit( 1 ); // terminate program
+ }
+
+ return sPtr[ subscript ]; // creates rvalue
+
+} // end function operator[]
+
+// return a substring beginning at index and
+// of length subLength
+String String::operator()( int index, int subLength )
+{
+ // if index is out of range or substring length < 0,
+ // return an empty String object
+ if ( index < 0 || index >= length || subLength < 0 )
+ return ""; // converted to a String object automatically
+
+ // determine length of substring
+ int len;
+
+ if ( ( subLength == 0 ) || ( index + subLength > length ) )
+ len = length - index;
+ else
+ len = subLength;
+
+ // allocate temporary array for substring and
+ // terminating null character
+ char *tempPtr = new char[ len + 1 ];
+
+ // copy substring into char array and terminate string
+ strncpy( tempPtr, &sPtr[ index ], len );
+ tempPtr[ len ] = '\0';
+
+ // create temporary String object containing the substring
+ String tempString( tempPtr );
+ delete [] tempPtr; // delete temporary array
+
+ return tempString; // return copy of the temporary String
+
+} // end function operator()
+
+// return string length
+int String::getLength() const
+{
+ return length;
+
+} // end function getLenth
+
+// utility function called by constructors and operator=
+void String::setString( const char *string2 )
+{
+ sPtr = new char[ length + 1 ]; // allocate memory
+
+ // if string2 is not a null pointer, copy contents
+ if ( string2 != 0 )
+ strcpy( sPtr, string2 ); // copy literal to object
+
+ // if string2 is a null pointer, make this an empty string
+ else
+ sPtr[ 0 ] = '\0'; // empty string
+
+} // end function setString
+
+// overloaded output operator
+ostream &operator<<( ostream &output, const String &s )
+{
+ output << s.sPtr;
+
+ return output; // enables cascading
+
+} // end function operator<<
+
+// overloaded input operator
+istream &operator>>( istream &input, String &s )
+{
+ char temp[ 100 ]; // buffer to store input
+
+ input >> setw( 100 ) >> temp;
+ s = temp; // use String class assignment operator
+
+ return input; // enables cascading
+
+} // end function operator>>
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.h b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.h new file mode 100644 index 0000000..81012aa --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_07_09/String1.h @@ -0,0 +1,85 @@ +// Fig. 8.7: string1.h
+// String class definition.
+#ifndef STRING1_H
+#define STRING1_H
+
+#include <iostream>
+
+using std::ostream;
+using std::istream;
+
+class String {
+ friend ostream &operator<<( ostream &, const String & );
+ friend istream &operator>>( istream &, String & );
+
+public:
+ String( const char * = "" ); // conversion/default ctor
+ String( const String & ); // copy constructor
+ ~String(); // destructor
+
+ const String &operator=( const String & ); // assignment
+ const String &operator+=( const String & ); // concatenation
+
+ bool operator!() const; // is String empty?
+ bool operator==( const String & ) const; // test s1 == s2
+ bool operator<( const String & ) const; // test s1 < s2
+
+ // test s1 != s2
+ bool operator!=( const String & right ) const
+ {
+ return !( *this == right );
+
+ } // end function operator!=
+
+ // test s1 > s2
+ bool operator>( const String &right ) const
+ {
+ return right < *this;
+
+ } // end function operator>
+
+ // test s1 <= s2
+ bool operator<=( const String &right ) const
+ {
+ return !( right < *this );
+
+ } // end function operator <=
+
+ // test s1 >= s2
+ bool operator>=( const String &right ) const
+ {
+ return !( *this < right );
+
+ } // end function operator>=
+
+ char &operator[]( int ); // subscript operator
+ const char &operator[]( int ) const; // subscript operator
+
+ String operator()( int, int ); // return a substring
+
+ int getLength() const; // return string length
+
+private:
+ int length; // string length
+ char *sPtr; // pointer to start of string
+
+ void setString( const char * ); // utility function
+
+}; // end class String
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.cpp new file mode 100644 index 0000000..0c96a95 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.cpp @@ -0,0 +1,137 @@ +// Fig. 8.11: date1.cpp
+// Date class member function definitions.
+#include <iostream>
+#include "date1.h"
+
+// initialize static member at file scope;
+// one class-wide copy
+const int Date::days[] =
+ { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+// Date constructor
+Date::Date( int m, int d, int y )
+{
+ setDate( m, d, y );
+
+} // end Date constructor
+
+// set month, day and year
+void Date::setDate( int mm, int dd, int yy )
+{
+ month = ( mm >= 1 && mm <= 12 ) ? mm : 1;
+ year = ( yy >= 1900 && yy <= 2100 ) ? yy : 1900;
+
+ // test for a leap year
+ if ( month == 2 && leapYear( year ) )
+ day = ( dd >= 1 && dd <= 29 ) ? dd : 1;
+ else
+ day = ( dd >= 1 && dd <= days[ month ] ) ? dd : 1;
+
+} // end function setDate
+
+// overloaded preincrement operator
+Date &Date::operator++()
+{
+ helpIncrement();
+
+ return *this; // reference return to create an lvalue
+
+} // end function operator++
+
+// overloaded postincrement operator; note that the dummy
+// integer parameter does not have a parameter name
+Date Date::operator++( int )
+{
+ Date temp = *this;
+ helpIncrement(); // hold current state of object
+
+ // return unincremented, saved, temporary object
+ return temp; // value return; not a reference return
+
+} // end function operator++
+
+// add specified number of days to date
+const Date &Date::operator+=( int additionalDays )
+{
+ for ( int i = 0; i < additionalDays; i++ )
+ helpIncrement();
+
+ return *this; // enables cascading
+
+} // end function operator+=
+
+// if the year is a leap year, return true;
+// otherwise, return false
+bool Date::leapYear( int testYear ) const
+{
+ if ( testYear % 400 == 0 ||
+ ( testYear % 100 != 0 && testYear % 4 == 0 ) )
+ return true; // a leap year
+ else
+ return false; // not a leap year
+
+} // end function leapYear
+
+// determine whether the day is the last day of the month
+bool Date::endOfMonth( int testDay ) const
+{
+ if ( month == 2 && leapYear( year ) )
+ return testDay == 29; // last day of Feb. in leap year
+ else
+ return testDay == days[ month ];
+
+} // end function endOfMonth
+
+// function to help increment the date
+void Date::helpIncrement()
+{
+ // day is not end of month
+ if ( !endOfMonth( day ) )
+ ++day;
+
+ else
+
+ // day is end of month and month < 12
+ if ( month < 12 ) {
+ ++month;
+ day = 1;
+ }
+
+ // last day of year
+ else {
+ ++year;
+ month = 1;
+ day = 1;
+ }
+
+} // end function helpIncrement
+
+// overloaded output operator
+ostream &operator<<( ostream &output, const Date &d )
+{
+ static char *monthName[ 13 ] = { "", "January",
+ "February", "March", "April", "May", "June",
+ "July", "August", "September", "October",
+ "November", "December" };
+
+ output << monthName[ d.month ] << ' '
+ << d.day << ", " << d.year;
+
+ return output; // enables cascading
+
+} // end function operator<<
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.h b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.h new file mode 100644 index 0000000..d1d6148 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Date1.h @@ -0,0 +1,49 @@ +// Fig. 8.10: date1.h
+// Date class definition.
+#ifndef DATE1_H
+#define DATE1_H
+#include <iostream>
+
+using std::ostream;
+
+class Date {
+ friend ostream &operator<<( ostream &, const Date & );
+
+public:
+ Date( int m = 1, int d = 1, int y = 1900 ); // constructor
+ void setDate( int, int, int ); // set the date
+
+ Date &operator++(); // preincrement operator
+ Date operator++( int ); // postincrement operator
+
+ const Date &operator+=( int ); // add days, modify object
+
+ bool leapYear( int ) const; // is this a leap year?
+ bool endOfMonth( int ) const; // is this end of month?
+
+private:
+ int month;
+ int day;
+ int year;
+
+ static const int days[]; // array of days per month
+ void helpIncrement(); // utility function
+
+}; // end class Date
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp new file mode 100644 index 0000000..0d4c996 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_10_12/Fig08_12.cpp @@ -0,0 +1,54 @@ +// Fig. 8.12: fig08_12.cpp
+// Date class test program.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "date1.h" // Date class definition
+
+int main()
+{
+ Date d1; // defaults to January 1, 1900
+ Date d2( 12, 27, 1992 );
+ Date d3( 0, 99, 8045 ); // invalid date
+
+ cout << "d1 is " << d1 << "\nd2 is " << d2
+ << "\nd3 is " << d3;
+
+ cout << "\n\nd2 += 7 is " << ( d2 += 7 );
+
+ d3.setDate( 2, 28, 1992 );
+ cout << "\n\n d3 is " << d3;
+ cout << "\n++d3 is " << ++d3;
+
+ Date d4( 7, 13, 2002 );
+
+ cout << "\n\nTesting the preincrement operator:\n"
+ << " d4 is " << d4 << '\n';
+ cout << "++d4 is " << ++d4 << '\n';
+ cout << " d4 is " << d4;
+
+ cout << "\n\nTesting the postincrement operator:\n"
+ << " d4 is " << d4 << '\n';
+ cout << "d4++ is " << d4++ << '\n';
+ cout << " d4 is " << d4 << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp b/Bachelor/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp new file mode 100644 index 0000000..cd74972 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_13/Fig08_13.cpp @@ -0,0 +1,104 @@ +// Fig. 8.13: fig08_13.cpp
+// Standard library string class test program.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <string>
+
+using std::string;
+
+int main()
+{
+ string s1( "happy" );
+ string s2( " birthday" );
+ string s3;
+
+ // test overloaded equality and relational operators
+ cout << "s1 is \"" << s1 << "\"; s2 is \"" << s2
+ << "\"; s3 is \"" << s3 << '\"'
+ << "\n\nThe results of comparing s2 and s1:"
+ << "\ns2 == s1 yields "
+ << ( s2 == s1 ? "true" : "false" )
+ << "\ns2 != s1 yields "
+ << ( s2 != s1 ? "true" : "false" )
+ << "\ns2 > s1 yields "
+ << ( s2 > s1 ? "true" : "false" )
+ << "\ns2 < s1 yields "
+ << ( s2 < s1 ? "true" : "false" )
+ << "\ns2 >= s1 yields "
+ << ( s2 >= s1 ? "true" : "false" )
+ << "\ns2 <= s1 yields "
+ << ( s2 <= s1 ? "true" : "false" );
+
+ // test string member function empty
+ cout << "\n\nTesting s3.empty():\n";
+
+ if ( s3.empty() ) {
+ cout << "s3 is empty; assigning s1 to s3;\n";
+ s3 = s1; // assign s1 to s3
+ cout << "s3 is \"" << s3 << "\"";
+ }
+
+ // test overloaded string concatenation operator
+ cout << "\n\ns1 += s2 yields s1 = ";
+ s1 += s2; // test overloaded concatenation
+ cout << s1;
+
+ // test overloaded string concatenation operator
+ // with C-style string
+ cout << "\n\ns1 += \" to you\" yields\n";
+ s1 += " to you";
+ cout << "s1 = " << s1 << "\n\n";
+
+ // test string member function substr
+ cout << "The substring of s1 starting at location 0 for\n"
+ << "14 characters, s1.substr(0, 14), is:\n"
+ << s1.substr( 0, 14 ) << "\n\n";
+
+ // test substr "to-end-of-string" option
+ cout << "The substring of s1 starting at\n"
+ << "location 15, s1.substr(15), is:\n"
+ << s1.substr( 15 ) << '\n';
+
+ // test copy constructor
+ string *s4Ptr = new string( s1 );
+ cout << "\n*s4Ptr = " << *s4Ptr << "\n\n";
+
+ // test assignment (=) operator with self-assignment
+ cout << "assigning *s4Ptr to *s4Ptr\n";
+ *s4Ptr = *s4Ptr;
+ cout << "*s4Ptr = " << *s4Ptr << '\n';
+
+ // test destructor
+ delete s4Ptr;
+
+ // test using subscript operator to create lvalue
+ s1[ 0 ] = 'H';
+ s1[ 6 ] = 'B';
+ cout << "\ns1 after s1[0] = 'H' and s1[6] = 'B' is: "
+ << s1 << "\n\n";
+
+ // test subscript out of range with string member function "at"
+ cout << "Attempt to assign 'd' to s1.at( 30 ) yields:" << endl;
+ s1.at( 30 ) = 'd'; // ERROR: subscript out of range
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp b/Bachelor/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp new file mode 100644 index 0000000..7fda752 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_14/Fig08_14.cpp @@ -0,0 +1,134 @@ +// Fig. 8.14: fig08_14.cpp
+// Demonstrating standard library class vector.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include <iomanip>
+
+using std::setw;
+
+#include <vector>
+
+using std::vector;
+
+void outputVector( const vector< int > & );
+void inputVector( vector< int > & );
+
+int main()
+{
+ vector< int > integers1( 7 ); // 7-element vector< int >
+ vector< int > integers2( 10 ); // 10-element vector< int >
+
+ // print integers1 size and contents
+ cout << "Size of vector integers1 is "
+ << integers1.size()
+ << "\nvector after initialization:\n";
+ outputVector( integers1 );
+
+ // print integers2 size and contents
+ cout << "\nSize of vector integers2 is "
+ << integers2.size()
+ << "\nvector after initialization:\n";
+ outputVector( integers2 );
+
+ // input and print integers1 and integers2
+ cout << "\nInput 17 integers:\n";
+ inputVector( integers1 );
+ inputVector( integers2 );
+
+ cout << "\nAfter input, the vectors contain:\n"
+ << "integers1:\n";
+ outputVector( integers1 );
+ cout << "integers2:\n";
+ outputVector( integers2 );
+
+ // use overloaded inequality (!=) operator
+ cout << "\nEvaluating: integers1 != integers2\n";
+
+ if ( integers1 != integers2 )
+ cout << "integers1 and integers2 are not equal\n";
+
+ // create vector integers3 using integers1 as an
+ // initializer; print size and contents
+ vector< int > integers3( integers1 ); // copy constructor
+
+ cout << "\nSize of vector integers3 is "
+ << integers3.size()
+ << "\nvector after initialization:\n";
+ outputVector( integers3 );
+
+
+ // use overloaded assignment (=) operator
+ cout << "\nAssigning integers2 to integers1:\n";
+ integers1 = integers2;
+
+ cout << "integers1:\n";
+ outputVector( integers1 );
+ cout << "integers2:\n";
+ outputVector( integers1 );
+
+ // use overloaded equality (==) operator
+ cout << "\nEvaluating: integers1 == integers2\n";
+
+ if ( integers1 == integers2 )
+ cout << "integers1 and integers2 are equal\n";
+
+ // use overloaded subscript operator to create rvalue
+ cout << "\nintegers1[5] is " << integers1[ 5 ];
+
+ // use overloaded subscript operator to create lvalue
+ cout << "\n\nAssigning 1000 to integers1[5]\n";
+ integers1[ 5 ] = 1000;
+ cout << "integers1:\n";
+ outputVector( integers1 );
+
+ // attempt to use out of range subscript
+ cout << "\nAttempt to assign 1000 to integers1.at( 15 )"
+ << endl;
+ integers1.at( 15 ) = 1000; // ERROR: out of range
+
+ return 0;
+
+} // end main
+
+// output vector contents
+void outputVector( const vector< int > &array )
+{
+ for ( int i = 0; i < array.size(); i++ ) {
+ cout << setw( 12 ) << array[ i ];
+
+ if ( ( i + 1 ) % 4 == 0 ) // 4 numbers per row of output
+ cout << endl;
+
+ } // end for
+
+ if ( i % 4 != 0 )
+ cout << endl;
+
+} // end function outputVector
+
+// input vector contents
+void inputVector( vector< int > &array )
+{
+ for ( int i = 0; i < array.size(); i++ )
+ cin >> array[ i ];
+
+} // end function inputVector
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.cpp new file mode 100644 index 0000000..130d39e --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.cpp @@ -0,0 +1,54 @@ +// Fig. 8.16: complex1.cpp
+// Complex class member function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "complex1.h" // Complex class definition
+
+// Constructor
+Complex::Complex( double realPart, double imaginaryPart )
+ : real( realPart ),
+ imaginary( imaginaryPart )
+{
+ // empty body
+
+} // end Complex constructor
+
+// addition operator
+Complex Complex::operator+( const Complex &operand2 ) const
+{
+ return Complex( real + operand2.real,
+ imaginary + operand2.imaginary );
+
+} // end function operator+
+
+// subtraction operator
+Complex Complex::operator-( const Complex &operand2 ) const
+{
+ return Complex( real - operand2.real,
+ imaginary - operand2.imaginary );
+
+} // end function operator-
+
+// display a Complex object in the form: (a, b)
+void Complex::print() const
+{
+ cout << '(' << real << ", " << imaginary << ')';
+
+} // end function print
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.h b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.h new file mode 100644 index 0000000..934f2f2 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Complex1.h @@ -0,0 +1,35 @@ +// Fig. 8.15: complex1.h
+// Complex class definition.
+#ifndef COMPLEX1_H
+#define COMPLEX1_H
+
+class Complex {
+
+public:
+ Complex( double = 0.0, double = 0.0 ); // constructor
+ Complex operator+( const Complex & ) const; // addition
+ Complex operator-( const Complex & ) const; // subtraction
+ void print() const; // output
+
+private:
+ double real; // real part
+ double imaginary; // imaginary part
+
+}; // end class Complex
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp new file mode 100644 index 0000000..d98f9bb --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_15_17/Fig08_17.cpp @@ -0,0 +1,57 @@ +// Fig. 8.17: fig08_17.cpp
+// Complex class test program.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "complex1.h"
+
+int main()
+{
+ Complex x;
+ Complex y( 4.3, 8.2 );
+ Complex z( 3.3, 1.1 );
+
+ cout << "x: ";
+ x.print();
+ cout << "\ny: ";
+ y.print();
+ cout << "\nz: ";
+ z.print();
+
+ x = y + z;
+ cout << "\n\nx = y + z:\n";
+ x.print();
+ cout << " = ";
+ y.print();
+ cout << " + ";
+ z.print();
+
+ x = y - z;
+ cout << "\n\nx = y - z:\n";
+ x.print();
+ cout << " = ";
+ y.print();
+ cout << " - ";
+ z.print();
+ cout << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp new file mode 100644 index 0000000..f73bde7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Fig08_20.cpp @@ -0,0 +1,51 @@ +// Fig. 8.20: fig08_20.cpp
+// HugeInt test program.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "hugeint1.h"
+
+int main()
+{
+ HugeInt n1( 7654321 );
+ HugeInt n2( 7891234 );
+ HugeInt n3( "99999999999999999999999999999" );
+ HugeInt n4( "1" );
+ HugeInt n5;
+
+ cout << "n1 is " << n1 << "\nn2 is " << n2
+ << "\nn3 is " << n3 << "\nn4 is " << n4
+ << "\nn5 is " << n5 << "\n\n";
+
+ n5 = n1 + n2;
+ cout << n1 << " + " << n2 << " = " << n5 << "\n\n";
+
+ cout << n3 << " + " << n4 << "\n= " << ( n3 + n4 )
+ << "\n\n";
+
+ n5 = n1 + 9;
+ cout << n1 << " + " << 9 << " = " << n5 << "\n\n";
+
+ n5 = n2 + "10000";
+ cout << n2 << " + " << "10000" << " = " << n5 << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp new file mode 100644 index 0000000..6e1aff7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.cpp @@ -0,0 +1,121 @@ +// Fig. 8.19: hugeint1.cpp
+// HugeInt member-function and friend-function definitions.
+
+#include <cctype> // isdigit function prototype
+#include <cstring> // strlen function prototype
+
+#include "hugeint1.h" // HugeInt class definition
+
+// default constructor; conversion constructor that converts
+// a long integer into a HugeInt object
+HugeInt::HugeInt( long value )
+{
+ // initialize array to zero
+ for ( int i = 0; i <= 29; i++ )
+ integer[ i ] = 0;
+
+ // place digits of argument into array
+ for ( int j = 29; value != 0 && j >= 0; j-- ) {
+ integer[ j ] = value % 10;
+ value /= 10;
+
+ } // end for
+
+} // end HugeInt default/conversion constructor
+
+// conversion constructor that converts a character string
+// representing a large integer into a HugeInt object
+HugeInt::HugeInt( const char *string )
+{
+ // initialize array to zero
+ for ( int i = 0; i <= 29; i++ )
+ integer[ i ] = 0;
+
+ // place digits of argument into array
+ int length = strlen( string );
+
+ for ( int j = 30 - length, k = 0; j <= 29; j++, k++ )
+
+ if ( isdigit( string[ k ] ) )
+ integer[ j ] = string[ k ] - '0';
+
+} // end HugeInt conversion constructor
+
+// addition operator; HugeInt + HugeInt
+HugeInt HugeInt::operator+( const HugeInt &op2 )
+{
+ HugeInt temp; // temporary result
+ int carry = 0;
+
+ for ( int i = 29; i >= 0; i-- ) {
+ temp.integer[ i ] =
+ integer[ i ] + op2.integer[ i ] + carry;
+
+ // determine whether to carry a 1
+ if ( temp.integer[ i ] > 9 ) {
+ temp.integer[ i ] %= 10; // reduce to 0-9
+ carry = 1;
+
+ } // end if
+
+ // no carry
+ else
+ carry = 0;
+ }
+
+ return temp; // return copy of temporary object
+
+} // end function operator+
+
+// addition operator; HugeInt + int
+HugeInt HugeInt::operator+( int op2 )
+{
+ // convert op2 to a HugeInt, then invoke
+ // operator+ for two HugeInt objects
+ return *this + HugeInt( op2 );
+
+} // end function operator+
+
+// addition operator;
+// HugeInt + string that represents large integer value
+HugeInt HugeInt::operator+( const char *op2 )
+{
+ // convert op2 to a HugeInt, then invoke
+ // operator+ for two HugeInt objects
+ return *this + HugeInt( op2 );
+
+} // end operator+
+
+// overloaded output operator
+ostream& operator<<( ostream &output, const HugeInt &num )
+{
+ int i;
+
+ for ( i = 0; ( num.integer[ i ] == 0 ) && ( i <= 29 ); i++ )
+ ; // skip leading zeros
+
+ if ( i == 30 )
+ output << 0;
+ else
+
+ for ( ; i <= 29; i++ )
+ output << num.integer[ i ];
+
+ return output;
+
+} // end function operator<<
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.h b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.h new file mode 100644 index 0000000..46dd1df --- /dev/null +++ b/Bachelor/Prog1/examples/ch08/Fig08_18_20/Hugeint1.h @@ -0,0 +1,47 @@ +// Fig. 8.18: hugeint1.h
+// HugeInt class definition.
+#ifndef HUGEINT1_H
+#define HUGEINT1_H
+
+#include <iostream>
+
+using std::ostream;
+
+class HugeInt {
+ friend ostream &operator<<( ostream &, const HugeInt & );
+
+public:
+ HugeInt( long = 0 ); // conversion/default constructor
+ HugeInt( const char * ); // conversion constructor
+
+ // addition operator; HugeInt + HugeInt
+ HugeInt operator+( const HugeInt & );
+
+ // addition operator; HugeInt + int
+ HugeInt operator+( int );
+
+ // addition operator;
+ // HugeInt + string that represents large integer value
+ HugeInt operator+( const char * );
+
+private:
+ short integer[ 30 ];
+
+}; // end class HugeInt
+
+#endif
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog1/examples/elevator/ElevatorSimulation.cpp b/Bachelor/Prog1/examples/elevator/ElevatorSimulation.cpp new file mode 100644 index 0000000..6f9e648 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/ElevatorSimulation.cpp @@ -0,0 +1,45 @@ +// Fig. 7.24: elevatorSimulation.cpp
+// Driver for the simulation.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include "building.h" // Building class definition
+
+int main()
+{
+ int duration; // length of simulation in seconds
+
+ cout << "Enter run time: ";
+ cin >> duration;
+ cin.ignore(); // ignore return char
+
+ Building building; // create the building
+
+ cout << endl << "*** ELEVATOR SIMULATION BEGINS ***"
+ << endl << endl;
+
+ building.runSimulation( duration ); // start simulation
+
+ cout << "*** ELEVATOR SIMULATION ENDS ***" << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/bell.cpp b/Bachelor/Prog1/examples/elevator/bell.cpp new file mode 100644 index 0000000..350b826 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/bell.cpp @@ -0,0 +1,44 @@ +// Fig. 7.32: bell.cpp
+// Member-function definitions for class Bell.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "bell.h" // Bell class definition
+
+// constructor
+Bell::Bell()
+{
+ cout << "bell created" << endl;
+
+} // end Bell constructor
+
+// destructor
+Bell::~Bell()
+{
+ cout << "bell destructed" << endl;
+
+} // end ~Bell destructor
+
+// ring bell
+void Bell::ringBell() const
+{
+ cout << "elevator rings its bell" << endl;
+
+} // end function ringBell
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/bell.h b/Bachelor/Prog1/examples/elevator/bell.h new file mode 100644 index 0000000..a0ef0bc --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/bell.h @@ -0,0 +1,30 @@ +// Fig. 7.31: bell.h
+// Bell class definition.
+#ifndef BELL_H
+#define BELL_H
+
+class Bell {
+
+public:
+ Bell(); // constructor
+ ~Bell(); // destructor
+ void ringBell() const; // ring the bell
+
+}; // end class Bell
+
+#endif // BELL_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/building.cpp b/Bachelor/Prog1/examples/elevator/building.cpp new file mode 100644 index 0000000..b2eaec3 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/building.cpp @@ -0,0 +1,65 @@ +// Fig. 7.26: building.cpp
+// Member-function definitions for class Building.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include "building.h" // Building class definition
+
+// constructor
+Building::Building()
+ : floor1( Floor::FLOOR1, elevator ),
+ floor2( Floor::FLOOR2, elevator ),
+ elevator( floor1, floor2 ),
+ scheduler( floor1, floor2 )
+{
+ cout << "building constructed" << endl;
+
+} // end Building constructor
+
+// destructor
+Building::~Building()
+{
+ cout << "building destructed" << endl;
+
+} // end ~Building destructor
+
+// function to control simulation
+void Building::runSimulation( int totalTime )
+{
+ int currentTime = 0;
+
+ while ( currentTime < totalTime ) {
+ clock.tick(); // increment time
+ currentTime = clock.getTime(); // get new time
+ cout << "TIME: " << currentTime << endl;
+
+ // process person arrivals for currentTime
+ scheduler.processTime( currentTime );
+
+ // process elevator events for currentTime
+ elevator.processTime( currentTime );
+
+ // wait for Enter key press, so user can view output
+ cin.get();
+
+ } // end while
+
+} // end function runSimulation
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/building.h b/Bachelor/Prog1/examples/elevator/building.h new file mode 100644 index 0000000..e45e3cd --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/building.h @@ -0,0 +1,42 @@ +// Fig. 7.25: building.h
+// Building class definition.
+#ifndef BUILDING_H
+#define BUILDING_H
+
+#include "elevator.h" // Elevator class definition
+#include "floor.h" // Floor class definition
+#include "clock.h" // Clock class definition
+#include "scheduler.h" // Scheduler class definition
+
+class Building {
+
+public:
+ Building(); // constructor
+ ~Building(); // destructor
+ void runSimulation( int ); // controls simulation
+
+private:
+ Floor floor1; // floor1 object
+ Floor floor2; // floor2 object
+ Elevator elevator; // elevator object
+ Clock clock; // clock object
+ Scheduler scheduler; // scheduler object
+
+}; // end class Building
+
+#endif // BUILDING_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/clock.cpp b/Bachelor/Prog1/examples/elevator/clock.cpp new file mode 100644 index 0000000..466f392 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/clock.cpp @@ -0,0 +1,52 @@ +// Fig. 7.28: clock.cpp
+// Member-function definitions for class Clock.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "clock.h" // Clock class definition
+
+// constructor
+Clock::Clock()
+ : time( 0 ) // initialize time to 0
+{
+ cout << "clock constructed" << endl;
+
+} // end Clock constructor
+
+// destructor
+Clock::~Clock()
+{
+ cout << "clock destructed" << endl;
+
+} // end ~Clock destructor
+
+// increment time by 1
+void Clock::tick()
+{
+ time++;
+
+} // end function tick
+
+// return current time
+int Clock::getTime() const
+{
+ return time;
+
+} // end function getTime
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/clock.h b/Bachelor/Prog1/examples/elevator/clock.h new file mode 100644 index 0000000..29bb55a --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/clock.h @@ -0,0 +1,34 @@ +// Fig. 7.27: clock.h
+// Clock class definition.
+#ifndef CLOCK_H
+#define CLOCK_H
+
+class Clock {
+
+public:
+ Clock(); // constructor
+ ~Clock(); // destructor
+ void tick(); // increment clock by one second
+ int getTime() const; // returns clock's current time
+
+private:
+ int time; // clock's time
+
+}; // end class Clock
+
+#endif // CLOCK_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/door.cpp b/Bachelor/Prog1/examples/elevator/door.cpp new file mode 100644 index 0000000..047fc1b --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/door.cpp @@ -0,0 +1,81 @@ +// Fig. 7.36: door.cpp
+// Member-function definitions for class Door.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "door.h" // Door class definition
+#include "person.h" // Person class definition
+#include "floor.h" // Floor class definition
+#include "elevator.h" // Elevator class definition
+
+// constructor
+Door::Door()
+ : open( false ) // initialize open to false
+{
+ cout << "door constructed" << endl;
+
+} // end Door constructor
+
+// destructor
+Door::~Door()
+{
+ cout << "door destructed" << endl;
+
+} // end ~Door destructor
+
+// open the door
+void Door::openDoor( Person * const passengerPtr,
+ Person * const nextPassengerPtr, Floor ¤tFloor,
+ Elevator &elevator )
+{
+ if ( !open ) { // if door is not open, open door
+ open = true;
+
+ cout << "elevator opens its door on floor "
+ << currentFloor.getNumber() << endl;
+
+ // if passenger is in elevator, tell person to leave
+ if ( passengerPtr != 0 ) {
+ passengerPtr->exitElevator( currentFloor, elevator );
+ delete passengerPtr; // passenger leaves simulation
+
+ } // end if
+
+ // if passenger waiting to enter elevator,
+ // tell passenger to enter
+ if ( nextPassengerPtr != 0 )
+ nextPassengerPtr->enterElevator(
+ elevator, currentFloor );
+
+ } // end outer if
+
+} // end function openDoor
+
+// close the door
+void Door::closeDoor( const Floor ¤tFloor )
+{
+ if ( open ) { // if door is open, close door
+ open = false;
+ cout << "elevator closes its door on floor "
+ << currentFloor.getNumber() << endl;
+
+ } // end if
+
+} // end function closeDoor
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/door.h b/Bachelor/Prog1/examples/elevator/door.h new file mode 100644 index 0000000..a15a5d1 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/door.h @@ -0,0 +1,40 @@ +// Fig. 7.35: door.h
+// Door class definition.
+#ifndef DOOR_H
+#define DOOR_H
+
+class Person; // forward declaration
+class Floor; // forward declaration
+class Elevator; // forward declaration
+
+class Door {
+
+public:
+ Door(); // constructor
+ ~Door(); // destructor
+
+ void openDoor( Person * const, // opens door
+ Person * const, Floor &, Elevator & );
+ void closeDoor( const Floor & ); // closes door
+
+private:
+ bool open; // open or closed
+
+};
+
+#endif // DOOR_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/elevator.cpp b/Bachelor/Prog1/examples/elevator/elevator.cpp new file mode 100644 index 0000000..1f271c1 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/elevator.cpp @@ -0,0 +1,231 @@ +// Fig. 7.42: elevator.cpp
+// Member-function definitions for class Elevator.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "elevator.h" // Elevator class definition
+#include "person.h" // Person class definition
+#include "floor.h" // Floor class definition
+
+// constants that represent time required to travel
+// between floors and directions of the elevator
+const int Elevator::ELEVATOR_TRAVEL_TIME = 5;
+const int Elevator::UP = 0;
+const int Elevator::DOWN = 1;
+
+// constructor
+Elevator::Elevator( Floor &firstFloor, Floor &secondFloor )
+ : elevatorButton( *this ),
+ currentBuildingClockTime( 0 ),
+ moving( false ),
+ direction( UP ),
+ currentFloor( Floor::FLOOR1 ),
+ arrivalTime( 0 ),
+ floor1NeedsService( false ),
+ floor2NeedsService( false ),
+ floor1Ref( firstFloor ),
+ floor2Ref( secondFloor ),
+ passengerPtr( 0 )
+{
+ cout << "elevator constructed" << endl;
+
+} // end Elevator constructor
+
+// destructor
+Elevator::~Elevator()
+{
+ delete passengerPtr;
+ cout << "elevator destructed" << endl;
+
+} // end ~Elevator destructor
+
+// give time to elevator
+void Elevator::processTime( int time )
+{
+ currentBuildingClockTime = time;
+
+ if ( moving ) // elevator is moving
+ processPossibleArrival();
+
+ else // elevator is not moving
+ processPossibleDeparture();
+
+ if ( !moving )
+ cout << "elevator at rest on floor "
+ << currentFloor << endl;
+
+} // end function processTime
+
+// when elevator is moving, determine if it should stop
+void Elevator::processPossibleArrival()
+{
+ // if elevator arrives at destination floor
+ if ( currentBuildingClockTime == arrivalTime ) {
+
+ currentFloor = // update current floor
+ ( currentFloor == Floor::FLOOR1 ?
+ Floor::FLOOR2 : Floor::FLOOR1 );
+
+ direction = // update direction
+ ( currentFloor == Floor::FLOOR1 ? UP : DOWN );
+
+ cout << "elevator arrives on floor "
+ << currentFloor << endl;
+
+ // process arrival at currentFloor
+ arriveAtFloor( currentFloor == Floor::FLOOR1 ?
+ floor1Ref : floor2Ref );
+
+ return;
+
+ } // end if
+
+ // elevator still moving
+ cout << "elevator moving "
+ << ( direction == UP ? "up" : "down" ) << endl;
+
+} // end function processPossibleArrival
+
+// determine whether elevator should move
+void Elevator::processPossibleDeparture()
+{
+ // this floor needs service?
+ bool currentFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor1NeedsService : floor2NeedsService;
+
+ // other floor needs service?
+ bool otherFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor2NeedsService : floor1NeedsService;
+
+ // service this floor (if needed)
+ if ( currentFloorNeedsService ) {
+ arriveAtFloor( currentFloor == Floor::FLOOR1 ?
+ floor1Ref : floor2Ref );
+
+ return;
+ }
+
+ // service other floor (if needed)
+ if ( otherFloorNeedsService )
+ prepareToLeave( true );
+
+} // end function processPossibleDeparture
+
+// arrive at a particular floor
+void Elevator::arriveAtFloor( Floor& arrivalFloor )
+{
+ moving = false; // reset state
+
+ cout << "elevator resets its button" << endl;
+ elevatorButton.resetButton();
+
+ bell.ringBell();
+
+ // notify floor that elevator has arrived
+ Person *floorPersonPtr = arrivalFloor.elevatorArrived();
+
+ door.openDoor(
+ passengerPtr, floorPersonPtr, arrivalFloor, *this );
+
+ // this floor needs service?
+ bool currentFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor1NeedsService : floor2NeedsService;
+
+ // other floor needs service?
+ bool otherFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor2NeedsService : floor1NeedsService;
+
+ // if this floor does not need service
+ // prepare to leave for the other floor
+ if ( !currentFloorNeedsService )
+ prepareToLeave( otherFloorNeedsService );
+
+ else // otherwise, reset service flag
+ currentFloor == Floor::FLOOR1 ?
+ floor1NeedsService = false: floor2NeedsService = false;
+
+} // end function arriveAtFloor
+
+// request service from elevator
+void Elevator::summonElevator( int floor )
+{
+ // set appropriate servicing flag
+ floor == Floor::FLOOR1 ?
+ floor1NeedsService = true : floor2NeedsService = true;
+
+} // end function summonElevator
+
+// accept a passenger
+void Elevator::passengerEnters( Person * const personPtr )
+{
+ // board passenger
+ passengerPtr = personPtr;
+
+ cout << "person " << passengerPtr->getID()
+ << " enters elevator from floor "
+ << currentFloor << endl;
+
+} // end function passengerEnters
+
+// notify elevator that passenger is exiting
+void Elevator::passengerExits()
+{
+ passengerPtr = 0;
+
+} // end function passengerExits
+
+// prepare to leave a floor
+void Elevator::prepareToLeave( bool leaving )
+{
+ // get reference to current floor
+ Floor &thisFloor =
+ currentFloor == Floor::FLOOR1 ? floor1Ref : floor2Ref;
+
+ // notify floor that elevator may be leaving
+ thisFloor.elevatorLeaving();
+
+ door.closeDoor( thisFloor );
+
+ if ( leaving ) // leave, if necessary
+ move();
+
+} // end function prepareToLeave
+
+// go to other floor
+void Elevator::move()
+{
+ moving = true; // change state
+
+ // schedule arrival time
+ arrivalTime = currentBuildingClockTime +
+ ELEVATOR_TRAVEL_TIME;
+
+ cout << "elevator begins moving "
+ << ( direction == DOWN ? "down " : "up " )
+ << "to floor "
+ << ( direction == DOWN ? '1' : '2' )
+ << " (arrives at time " << arrivalTime << ')'
+ << endl;
+
+} // end function move
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/elevator.h b/Bachelor/Prog1/examples/elevator/elevator.h new file mode 100644 index 0000000..e032607 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/elevator.h @@ -0,0 +1,75 @@ +// Fig. 7.41: elevator.h
+// Elevator class definition.
+#ifndef ELEVATOR_H
+#define ELEVATOR_H
+
+#include "elevatorButton.h"
+#include "door.h"
+#include "bell.h"
+
+class Floor; // forward declaration
+class Person; // forward declaration
+
+class Elevator {
+
+public:
+ Elevator( Floor &, Floor & ); // constructor
+ ~Elevator(); // destructor
+ void summonElevator( int ); // request to service floor
+ void prepareToLeave( bool ); // prepare to leave
+ void processTime( int ); // give current time to elevator
+ void passengerEnters( Person * const ); // board a passenger
+ void passengerExits(); // exit a passenger
+
+ // public object accessible to client code with
+ // access to Elevator object
+ ElevatorButton elevatorButton;
+
+private:
+
+ // utility functions
+ void processPossibleArrival();
+ void processPossibleDeparture();
+ void arriveAtFloor( Floor & );
+ void move();
+
+ // static constants that represent time required to travel
+ // between floors and directions of the elevator
+ static const int ELEVATOR_TRAVEL_TIME;
+ static const int UP;
+ static const int DOWN;
+
+ // data members
+ int currentBuildingClockTime; // current time
+ bool moving; // elevator state
+ int direction; // current direction
+ int currentFloor; // current location
+ int arrivalTime; // time to arrive at a floor
+ bool floor1NeedsService; // floor1 service flag
+ bool floor2NeedsService; // floor2 service flag
+
+ Floor &floor1Ref; // reference to floor1
+ Floor &floor2Ref; // reference to floor2
+ Person *passengerPtr; // pointer to passenger
+
+ Door door; // door object
+ Bell bell; // bell object
+
+}; // end class Elevator
+
+#endif // ELEVATOR_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/elevatorButton.cpp b/Bachelor/Prog1/examples/elevator/elevatorButton.cpp new file mode 100644 index 0000000..f1e3a51 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/elevatorButton.cpp @@ -0,0 +1,57 @@ +// Fig. 7.38: elevatorButton.cpp:
+// Member-function definitions for class ElevatorButton.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "elevatorButton.h" // ElevatorButton class definition
+#include "elevator.h" // Elevator class definition
+
+// constructor
+ElevatorButton::ElevatorButton( Elevator &elevatorHandle )
+ : pressed( false ),
+ elevatorRef( elevatorHandle )
+{
+ cout << "elevator button constructed" << endl;
+
+} // end ElevatorButton constructor
+
+// destructor
+ElevatorButton::~ElevatorButton()
+{
+ cout << "elevator button destructed" << endl;
+
+} // end ~ElevatorButton destructor
+
+// press button and signal elevator to prepare to leave floor
+void ElevatorButton::pressButton()
+{
+ pressed = true;
+ cout << "elevator button tells elevator to prepare to leave"
+ << endl;
+ elevatorRef.prepareToLeave( true );
+
+} // end function pressButton
+
+// reset button
+void ElevatorButton::resetButton()
+{
+ pressed = false;
+
+} // end function resetButton
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/elevatorButton.h b/Bachelor/Prog1/examples/elevator/elevatorButton.h new file mode 100644 index 0000000..7b2c5be --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/elevatorButton.h @@ -0,0 +1,40 @@ +// Fig. 7.37: elevatorButton.h
+// ElevatorButton class definition.
+#ifndef ELEVATORBUTTON_H
+#define ELEVATORBUTTON_H
+
+class Elevator; // forward declaration
+
+class ElevatorButton {
+
+public:
+ ElevatorButton( Elevator & ); // constructor
+ ~ElevatorButton(); // destructor
+
+ void pressButton(); // press the button
+ void resetButton(); // reset the button
+
+private:
+ bool pressed; // state of button
+
+ // reference to elevator containing this button
+ Elevator &elevatorRef;
+
+}; // end class ElevatorButton
+
+#endif // ELEVATORBUTTON_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/floor.cpp b/Bachelor/Prog1/examples/elevator/floor.cpp new file mode 100644 index 0000000..c651095 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/floor.cpp @@ -0,0 +1,98 @@ +// Fig. 7.44: floor.cpp
+// Member-function definitions for class Floor.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "floor.h" // Floor class definition
+#include "person.h" // Person class definition
+#include "elevator.h" // Elevator class definition
+#include "door.h" // Door class definition
+
+// static constants that represent the floor numbers
+const int Floor::FLOOR1 = 1;
+const int Floor::FLOOR2 = 2;
+
+// constructor
+Floor::Floor(int number, Elevator &elevatorHandle )
+ : floorButton( number, elevatorHandle ),
+ floorNumber( number ),
+ elevatorRef( elevatorHandle ),
+ occupantPtr ( 0 ),
+ light( floorNumber )
+{
+ cout << "floor " << floorNumber << " constructed" << endl;
+
+} // end Floor constructor
+
+// destructor
+Floor::~Floor()
+{
+ delete occupantPtr;
+ cout << "floor " << floorNumber << " destructed" << endl;
+
+} // end ~Floor destructor
+
+// determine whether floor is occupied
+bool Floor::isOccupied() const
+{
+ return ( occupantPtr != 0 );
+
+} // end function isOccupied
+
+// return this floor's number
+int Floor::getNumber() const
+{
+ return floorNumber;
+
+} // end function getNumber
+
+// person arrives on floor
+void Floor::personArrives( Person * const personPtr )
+{
+ occupantPtr = personPtr;
+
+} // end function personArrives
+
+// notify floor that elevator has arrived
+Person *Floor::elevatorArrived()
+{
+ cout << "floor " << floorNumber
+ << " resets its button" << endl;
+
+ floorButton.resetButton();
+ light.turnOn();
+
+ return occupantPtr;
+
+} // end function elevatorArrived
+
+// tell floor that elevator is leaving
+void Floor::elevatorLeaving()
+{
+ light.turnOff();
+
+} // end function elevatorLeaving
+
+// notifies floor that person is leaving
+void Floor::personBoardingElevator()
+{
+ occupantPtr = 0; // person no longer on floor
+
+} // end function personBoardingElevator
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/floor.h b/Bachelor/Prog1/examples/elevator/floor.h new file mode 100644 index 0000000..6ead42a --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/floor.h @@ -0,0 +1,63 @@ +// Fig. 7.43: floor.h
+// Floor class definition.
+#ifndef FLOOR_H
+#define FLOOR_H
+
+#include "floorButton.h"
+#include "light.h"
+
+class Elevator; // forward declaration
+class Person; // forward declaration
+
+class Floor {
+
+public:
+ Floor( int, Elevator & ); // constructor
+ ~Floor(); // destructor
+ bool isOccupied() const; // return true if floor occupied
+ int getNumber() const; // return floor's number
+
+ // pass a handle to new person coming on floor
+ void personArrives( Person * const );
+
+ // notify floor that elevator has arrived
+ Person *elevatorArrived();
+
+ // notify floor that elevator is leaving
+ void elevatorLeaving();
+
+ // notify floor that person is leaving floor
+ void personBoardingElevator();
+
+ // static constants representing floor numbers
+ static const int FLOOR1;
+ static const int FLOOR2;
+
+ // public FloorButton object accessible to
+ // any client code with access to a Floor
+ FloorButton floorButton;
+
+private:
+ const int floorNumber; // the floor's number
+ Elevator &elevatorRef; // reference to elevator
+ Person *occupantPtr; // pointer to person on floor
+ Light light; // light object
+
+}; // end class Floor
+
+#endif // FLOOR_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/floorButton.cpp b/Bachelor/Prog1/examples/elevator/floorButton.cpp new file mode 100644 index 0000000..6d19769 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/floorButton.cpp @@ -0,0 +1,62 @@ +// Fig. 7.40: floorButton.cpp
+// Member-function definitions for class FloorButton.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "floorButton.h"
+#include "elevator.h"
+
+// constructor
+FloorButton::FloorButton( int floor, Elevator &elevatorHandle )
+ : floorNumber( floor ),
+ pressed( false ),
+ elevatorRef( elevatorHandle )
+{
+ cout << "floor " << floorNumber << " button constructed"
+ << endl;
+
+} // end FloorButton constructor
+
+// destructor
+FloorButton::~FloorButton()
+{
+ cout << "floor " << floorNumber << " button destructed"
+ << endl;
+
+} // end ~FloorButton destructor
+
+// press the button
+void FloorButton::pressButton()
+{
+ pressed = true;
+ cout << "floor " << floorNumber
+ << " button summons elevator" << endl;
+
+ // call elevator to this floor
+ elevatorRef.summonElevator( floorNumber );
+
+} // end function pressButton
+
+// reset button
+void FloorButton::resetButton()
+{
+ pressed = false;
+
+} // end function resetButton
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/floorButton.h b/Bachelor/Prog1/examples/elevator/floorButton.h new file mode 100644 index 0000000..b09c6e5 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/floorButton.h @@ -0,0 +1,42 @@ +// Fig. 7.39: floorButton.h
+// FloorButton class definition.
+#ifndef FLOORBUTTON_H
+#define FLOORBUTTON_H
+
+class Elevator; // forward declaration
+
+class FloorButton {
+
+public:
+ FloorButton( int, Elevator & ); // constructor
+ ~FloorButton(); // destructor
+
+ void pressButton(); // press the button
+ void resetButton(); // reset the button
+
+private:
+ const int floorNumber; // button's floor number
+ bool pressed; // button state
+
+ // reference to elevator used to summon
+ // elevator to floor
+ Elevator &elevatorRef;
+
+}; // end class FloorButton
+
+#endif // FLOORBUTTON_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/light.cpp b/Bachelor/Prog1/examples/elevator/light.cpp new file mode 100644 index 0000000..1a9eb79 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/light.cpp @@ -0,0 +1,65 @@ +// Fig. 7.34: light.cpp
+// Member-function definitions for class Light.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "light.h" // Light class definition
+
+// constructor
+Light::Light( int number )
+ : on( false ),
+ floorNumber( number )
+{
+ cout << "floor " << floorNumber << " light constructed"
+ << endl;
+
+} // end Light constructor
+
+// destuctor
+Light::~Light()
+{
+ cout << "floor " << floorNumber
+ << " light destructed" << endl;
+
+} // end ~Light destructor
+
+// turn light on
+void Light::turnOn()
+{
+ if ( !on ) { // if light not on, turn it on
+ on = true;
+ cout << "floor " << floorNumber
+ << " light turns on" << endl;
+
+ } // end if
+
+} // end function turnOn
+
+// turn light off
+void Light::turnOff()
+{
+ if ( on ) { // if light is on, turn it off
+ on = false;
+ cout << "floor " << floorNumber
+ << " light turns off" << endl;
+
+ } // end if
+
+} // end function turnOff
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/light.h b/Bachelor/Prog1/examples/elevator/light.h new file mode 100644 index 0000000..88e920d --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/light.h @@ -0,0 +1,36 @@ +// Fig. 7.33: light.h
+// Light class definition.
+#ifndef LIGHT_H
+#define LIGHT_H
+
+class Light {
+
+public:
+ Light( int ); // constructor
+ ~Light(); // destructor
+
+ void turnOn(); // turns light on
+ void turnOff(); // turns light off
+
+private:
+ bool on; // true if on; false if off
+ const int floorNumber; // floor number that contains light
+
+}; // end class Light
+
+#endif // LIGHT_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/person.cpp b/Bachelor/Prog1/examples/elevator/person.cpp new file mode 100644 index 0000000..72e070d --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/person.cpp @@ -0,0 +1,91 @@ +// Fig. 7.46: person.cpp
+// Member-function definitions for class Person.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "person.h" // Person class definition
+#include "floor.h" // Floor class definition
+#include "elevator.h" // Elevator class definition
+
+// initialize static member personCount
+int Person::personCount = 0;
+
+// constructor
+Person::Person( int destFloor )
+ : ID( ++personCount ),
+ destinationFloor( destFloor )
+{
+ cout << "person " << ID << " constructed" << endl;
+
+} // end Person constructor
+
+// destructor
+Person::~Person()
+{
+ cout << "(person " << ID << " destructor invoked)" << endl;
+
+} // end ~Person destructor
+
+// return person's ID number
+int Person::getID() const
+{
+ return ID;
+
+} // end function getID
+
+// person walks onto a floor
+void Person::stepOntoFloor( Floor& floor )
+{
+ // notify floor person is coming
+ cout << "person " << ID << " steps onto floor "
+ << floor.getNumber() << endl;
+ floor.personArrives( this );
+
+ // press button on floor
+ cout << "person " << ID
+ << " presses floor button on floor "
+ << floor.getNumber() << endl;
+ floor.floorButton.pressButton();
+
+} // end function stepOntoFloor
+
+// person enters elevator
+void Person::enterElevator( Elevator &elevator, Floor &floor )
+{
+ floor.personBoardingElevator(); // person leaves floor
+
+ elevator.passengerEnters( this ); // person enters elevator
+
+ // press button on elevator
+ cout << "person " << ID
+ << " presses elevator button" << endl;
+ elevator.elevatorButton.pressButton();
+
+} // end function enterElevator
+
+// person exits elevator
+void Person::exitElevator(
+ const Floor &floor, Elevator &elevator ) const
+{
+ cout << "person " << ID << " exits elevator on floor "
+ << floor.getNumber() << endl;
+ elevator.passengerExits();
+
+} // end function exitElevator
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/person.h b/Bachelor/Prog1/examples/elevator/person.h new file mode 100644 index 0000000..7a6f10c --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/person.h @@ -0,0 +1,42 @@ +// Fig. 7.45: person.h
+// Person class definition.
+#ifndef PERSON_H
+#define PERSON_H
+
+class Floor; // forward declaration
+class Elevator; // forward declaration
+
+class Person {
+
+public:
+ Person( int ); // constructor
+ ~Person(); // destructor
+ int getID() const; // returns person's ID
+
+ void stepOntoFloor( Floor & );
+ void enterElevator( Elevator &, Floor & );
+ void exitElevator( const Floor &, Elevator & ) const;
+
+private:
+ static int personCount; // total number of people
+ const int ID; // person's unique ID #
+ const int destinationFloor; // destination floor #
+
+}; // end class Person
+
+#endif // PERSON_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/scheduler.cpp b/Bachelor/Prog1/examples/elevator/scheduler.cpp new file mode 100644 index 0000000..73bdebb --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/scheduler.cpp @@ -0,0 +1,134 @@ +// Fig. 7.30: scheduler.cpp
+// Member-function definitions for class Scheduler.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <new>
+#include <cstdlib>
+#include <ctime>
+
+#include "scheduler.h" // Scheduler class definition
+#include "floor.h" // Floor class definition
+#include "person.h" // Person class definition
+
+// constructor
+Scheduler::Scheduler( Floor &firstFloor, Floor &secondFloor )
+ : currentClockTime( 0 ),
+ floor1Ref( firstFloor ),
+ floor2Ref( secondFloor )
+{
+ srand( time( 0 ) ); // seed random number generator
+ cout << "scheduler constructed" << endl;
+
+ // schedule first arrivals for floor 1 and floor 2
+ scheduleTime( floor1Ref );
+ scheduleTime( floor2Ref );
+
+} // end Scheduler constructor
+
+// destructor
+Scheduler::~Scheduler()
+{
+ cout << "scheduler destructed" << endl;
+
+} // end Scheduler destructor
+
+// schedule arrival on a floor
+void Scheduler::scheduleTime( const Floor &floor )
+{
+ int floorNumber = floor.getNumber();
+ int arrivalTime = currentClockTime + ( 5 + rand() % 16 );
+
+ floorNumber == Floor::FLOOR1 ?
+ floor1ArrivalTime = arrivalTime :
+ floor2ArrivalTime = arrivalTime;
+
+ cout << "(scheduler schedules next person for floor "
+ << floorNumber << " at time " << arrivalTime << ')'
+ << endl;
+
+} // end function scheduleTime
+
+// reschedule arrival on a floor
+void Scheduler::delayTime( const Floor &floor )
+{
+ int floorNumber = floor.getNumber();
+
+ int arrivalTime = ( floorNumber == Floor::FLOOR1 ) ?
+ ++floor1ArrivalTime : ++floor2ArrivalTime;
+
+ cout << "(scheduler delays next person for floor "
+ << floorNumber << " until time " << arrivalTime << ')'
+ << endl;
+
+} // end function delayTime
+
+// give time to scheduler
+void Scheduler::processTime( int time )
+{
+ currentClockTime = time; // record time
+
+ // handle arrivals on floor 1
+ handleArrivals( floor1Ref, currentClockTime );
+
+ // handle arrivals on floor 2
+ handleArrivals( floor2Ref, currentClockTime );
+
+} // end function processTime
+
+// create new person and place it on specified floor
+void Scheduler::createNewPerson( Floor &floor )
+{
+ int destinationFloor =
+ floor.getNumber() == Floor::FLOOR1 ?
+ Floor::FLOOR2 : Floor::FLOOR1;
+
+ // create new person
+ Person *newPersonPtr = new Person( destinationFloor );
+
+ cout << "scheduler creates person "
+ << newPersonPtr->getID() << endl;
+
+ // place person on proper floor
+ newPersonPtr->stepOntoFloor( floor );
+
+ scheduleTime( floor ); // schedule next arrival
+
+} // end function createNewPerson
+
+// handle arrivals for a specified floor
+void Scheduler::handleArrivals( Floor &floor, int time )
+{
+ int floorNumber = floor.getNumber();
+
+ int arrivalTime = ( floorNumber == Floor::FLOOR1 ) ?
+ floor1ArrivalTime : floor2ArrivalTime;
+
+ if ( arrivalTime == time ) {
+
+ if ( floor.isOccupied() ) // if floor occupied,
+ delayTime( floor ); // delay arrival
+
+ else // otherwise,
+ createNewPerson( floor ); // create new person
+
+ } // end outer if
+
+} // end function handleArrivals
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/examples/elevator/scheduler.h b/Bachelor/Prog1/examples/elevator/scheduler.h new file mode 100644 index 0000000..a035d08 --- /dev/null +++ b/Bachelor/Prog1/examples/elevator/scheduler.h @@ -0,0 +1,53 @@ +// Fig. 7.29: scheduler.h
+// Scheduler class definition.
+#ifndef SCHEDULER_H
+#define SCHEDULER_H
+
+class Floor; // forward declaration
+
+class Scheduler {
+
+public:
+ Scheduler( Floor &, Floor & ); // constructor
+ ~Scheduler(); // destructor
+ void processTime( int ); // set scheduler's time
+
+private:
+ // schedule arrival to a floor
+ void scheduleTime( const Floor & );
+
+ // delay arrival to a floor
+ void delayTime( const Floor & );
+
+ // create new person; place on floor
+ void createNewPerson( Floor & );
+
+ // handle person arrival on a floor
+ void handleArrivals( Floor &, int );
+
+ int currentClockTime;
+
+ Floor &floor1Ref;
+ Floor &floor2Ref;
+
+ int floor1ArrivalTime;
+ int floor2ArrivalTime;
+
+}; // end class Scheduler
+
+#endif // SCHEDULER_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog1/probeklausur/lotto.h b/Bachelor/Prog1/probeklausur/lotto.h new file mode 100644 index 0000000..373a19a --- /dev/null +++ b/Bachelor/Prog1/probeklausur/lotto.h @@ -0,0 +1,25 @@ +// Sven Eisenhauer
+// Probeklausur 09.02.2005
+//
+// Definition of class LottoGenerator
+
+#ifndef LOTTO_H
+#define LOTTO_H
+
+class LottoGenerator {
+public:
+ LottoGenerator();
+ ~LottoGenerator();
+ void drawAllNumbers();
+ void printAllNumbers();
+ void sortSixNumbers();
+ int getAllNumbers( int* );
+ long getNumberOfDraws();
+private:
+ const int ARRAY_SIZE;
+ int * sixNumbers;
+ int seventhNumber;
+ long numberOfDraws;
+};
+
+#endif
diff --git a/Bachelor/Prog1/probeklausur/lottogenerator.cpp b/Bachelor/Prog1/probeklausur/lottogenerator.cpp new file mode 100644 index 0000000..02c0f46 --- /dev/null +++ b/Bachelor/Prog1/probeklausur/lottogenerator.cpp @@ -0,0 +1,89 @@ +// Sven Eisenhauer
+// Probeklausur 09.02.2005
+//
+// Implementation of class LottoGenerator
+
+#include <iostream>
+#include <new>
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+using std::setw;
+
+#include "lotto.h"
+
+LottoGenerator::LottoGenerator()
+ :ARRAY_SIZE(6)
+{
+ numberOfDraws=0;
+ sixNumbers = new int[ARRAY_SIZE];
+ for (int i=0;i<ARRAY_SIZE;i++)
+ sixNumbers[i]=0;
+}
+
+LottoGenerator::~LottoGenerator()
+{
+ delete [] sixNumbers;
+ cout << endl << "Number of draws: " << numberOfDraws << endl;
+}
+
+void LottoGenerator::drawAllNumbers()
+{
+ const int nrBalls=49;
+ int temp;
+ int randPos;
+ int balls[nrBalls];
+
+ for (int i=0;i<nrBalls;i++)
+ balls[i]=i+1;
+
+ for (i=0;i<nrBalls;i++)
+ {
+ randPos=(rand()%49)+1;
+ temp=balls[i];
+ balls[i]=balls[randPos];
+ balls[randPos]=temp;
+ }
+
+ for (i=0;i<ARRAY_SIZE;i++)
+ {
+ sixNumbers[i]=balls[i];
+ }
+ seventhNumber=balls[i+1];
+
+ numberOfDraws++;
+}
+
+void LottoGenerator::printAllNumbers()
+{
+ cout << endl << "Zahlen: ";
+ for (int n=0;n<ARRAY_SIZE;n++)
+ cout << setw(4) << sixNumbers[n];
+ cout << endl << "Zusatzzahl: " << seventhNumber;
+}
+
+void LottoGenerator::sortSixNumbers()
+{
+ int temp;
+
+ for (int i=0;i<ARRAY_SIZE;i++)
+ {
+ for (int j=i;j<ARRAY_SIZE;j++)
+ {
+ if (sixNumbers[j]<sixNumbers[i])
+ {
+ temp=sixNumbers[i];
+ sixNumbers[i]=sixNumbers[j];
+ sixNumbers[j]=temp;
+ }
+ }
+ }
+}
+
+int LottoGenerator::getAllNumbers(int * Numbers)
+{
+ for(int i=0;i<ARRAY_SIZE;i++)
+ Numbers[i]=sixNumbers[i];
+ return seventhNumber;
+}
diff --git a/Bachelor/Prog1/probeklausur/main.cpp b/Bachelor/Prog1/probeklausur/main.cpp new file mode 100644 index 0000000..a96bd6f --- /dev/null +++ b/Bachelor/Prog1/probeklausur/main.cpp @@ -0,0 +1,67 @@ +// Sven Eisenhauer
+// Probeklausur 09.02.2005
+//
+// Application to test class LottoGenerator
+
+#include "lotto.h"
+#include <iostream>
+using std::cout;
+using std::endl;
+#include<iomanip>
+using std::setw;
+
+int average(int *);
+
+const int ARRAY_SIZE=6;
+
+int main()
+{
+ LottoGenerator lotto;
+ int nrEinstZusatzZ=0;
+ long ZusatzZ;
+ int erg[ARRAY_SIZE];
+ const int NUMBERS=49;
+ int result[NUMBERS]={0};
+ int avg=0;
+
+ for(int i=0;i<10;i++)
+ {
+ lotto.drawAllNumbers();
+ lotto.sortSixNumbers();
+ lotto.printAllNumbers();
+ }
+
+ for(i=0;i<1000000;i++)
+ {
+ lotto.drawAllNumbers();
+ ZusatzZ=lotto.getAllNumbers(erg);
+ if(ZusatzZ<10)
+ nrEinstZusatzZ++;
+ }
+ cout << endl << "Eine einstellige Zusatzzahl gab es "<< nrEinstZusatzZ <<" mal.";
+
+ for(i=0;i<1000000;i++)
+ {
+ lotto.drawAllNumbers();
+ lotto.getAllNumbers(erg);
+ avg=average(erg);
+ result[avg]++;
+ }
+
+ cout << endl <<"Häufigkeitsverteilung: " << endl;
+ for (i=0;i<NUMBERS;i++)
+ cout << setw(3) << i+1 << setw(8) << result[i] << endl;
+
+ return 0;
+}
+
+int average(int* array)
+{
+ int sum=0;
+ int avg=0;
+
+ for (int i=0;i<ARRAY_SIZE;i++)
+ sum+=array[i];
+ avg=sum/ARRAY_SIZE;
+ return avg;
+}
|
