diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog1/Prakt4/prg1p4_3 | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Bachelor/Prog1/Prakt4/prg1p4_3')
| -rw-r--r-- | Bachelor/Prog1/Prakt4/prg1p4_3/main.cpp | 102 | ||||
| -rw-r--r-- | Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsp | 100 | ||||
| -rw-r--r-- | Bachelor/Prog1/Prakt4/prg1p4_3/prg1p4_3.dsw | 29 |
3 files changed, 231 insertions, 0 deletions
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>
+{{{
+}}}
+
+###############################################################################
+
|
