From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp | 122 ++++++++++++++++++++++++++++ Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp | 100 +++++++++++++++++++++++ Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw | 29 +++++++ 3 files changed, 251 insertions(+) create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw (limited to 'Bachelor/Prog1/Prakt4/prg1p4_4') diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp new file mode 100644 index 0000000..8f481ff --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/main.cpp @@ -0,0 +1,122 @@ +// Programmieren 1, Praktikum 4, Aufgabe 4 +// Sven Eisenhauer +// 14.12.2004 +// +// file: main.cpp +// +// purpose: Simulate a Galton Board +// + +#include + +using std::cin; +using std::cout; +using std::endl; + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include + +#include + +const int maxBoxes=100; +const int minBoxes=1; + +int fall(int &,int &); +void getInput(int &,int &, char &); +void textOutput(int[], const int, const int); +void graphicalOutput(int[], const int, const int); + +int main() +{ + srand(time(0)); + + int nrBalls; + int minBox,maxBox,nrBox; + int box; + int result[maxBoxes+1]={0}; + char outputMode; + + getInput(nrBalls,nrBox,outputMode); + for (int i=1;i<=nrBalls;i++) + { + minBox=minBoxes; + maxBox=nrBox; + box=fall(minBox,maxBox); + result[box]++; + } + if (outputMode=='t' || outputMode=='T') + textOutput(result,nrBalls,nrBox); + else + graphicalOutput(result,nrBalls,nrBox); + + return 0; +}// end function main + +void getInput(int& nrBa, int& nrBo, char &outpMode) +{ + cout << "Please enter number of boxes (max." << maxBoxes <<"): "; + cin>>nrBo; + cout << "Please enter number of balls: "; + cin>>nrBa; + cout << "Please enter output mode: [T/t] table, [G/g] graphical: "; + cin >> outpMode; +}// end function getInput + +int fall(int &minB, int &maxB) +{ + // if we are not over last 2 boxes + if((maxB-minB)>1) + { + if (0==rand()%2) + // ball falls to the right => we cannot reach the most left box anymore + minB++; + else + // ball falls to the left => we cannot reach the most right box anymore + maxB--; + fall(minB,maxB); + //return 0; + } + // only 2 possible boxes left... the base case + else + { + if (0==rand()%2) + // left box + return minB; + else + // right box + return maxB; + } +} + +void textOutput(int resArray[], const int balls,const int nrBox) +{ + //int sum=0; + + cout << endl << setw(10) << "Box" << setw(10) << "Balls" << setw(16) << "Norm." <(resArray[n])/balls<(((static_cast (resArray[n]))/balls)*maxColumns);i++) + cout<<"*"; + cout << endl; + + + } +}// end function graphicalOutput diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp new file mode 100644 index 0000000..760be15 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="prg1p4_4" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prg1p4_4 - Win32 Debug +!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE +!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl +!MESSAGE +!MESSAGE NMAKE /f "prg1p4_4.mak". +!MESSAGE +!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben +!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: +!MESSAGE +!MESSAGE NMAKE /f "prg1p4_4.mak" CFG="prg1p4_4 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "prg1p4_4 - Win32 Release" (basierend auf "Win32 (x86) Console Application") +!MESSAGE "prg1p4_4 - Win32 Debug" (basierend auf "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "prg1p4_4 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "prg1p4_4 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "prg1p4_4 - Win32 Release" +# Name "prg1p4_4 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Ressourcendateien" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw new file mode 100644 index 0000000..85399da --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_4/prg1p4_4.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN! + +############################################################################### + +Project: "prg1p4_4"=.\prg1p4_4.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + -- cgit v1.2.3