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/Prakt5/prg1p5_1/main.cpp | 124 ++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp (limited to 'Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp') diff --git a/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp new file mode 100644 index 0000000..61644cc --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp @@ -0,0 +1,124 @@ +// Programmieren 1, Praktikum 5, Aufgabe 1 +// Sven Eisenhauer +// 16.12.2004 +// +// file: main.cpp +// +// purpose: Shuffle a standard deck of 52 cards and deal them +// + +#include + +using std::cin; +using std::cout; +using std::endl; +using std::left; +using std::right; + + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include +#include + +const int maxColumns=13; +const int maxRows=4; +const int maxCards=52; + +// prototypes +void shuffle( int [][ maxColumns ] ); +void deal( const int [][ maxColumns ], const char *[], const char *[] ); + + + +int main() +{ + // initialize suit array + const char *suit[ 4 ] = + { "Hearts", "Diamonds", "Clubs", "Spades" }; + + // initialize face array + const char *face[ 13 ] = + { "Ace", "Deuce", "Three", "Four", + "Five", "Six", "Seven", "Eight", + "Nine", "Ten", "Jack", "Queen", "King" }; + + // initialize deck array + int deck[ maxRows ][ maxColumns ] = + { + { 1,2,3,4,5,6,7,8,9,10,11,12,13 }, + { 14,15,16,17,18,19,20,21,22,23,24,25,26 }, + { 27,28,29,30,31,32,33,34,35,36,37,38,39 }, + { 40,41,42,43,44,45,46,47,48,49,50,51,52 } + }; + + srand( time( 0 ) ); // seed random number generator + + shuffle( deck ); + deal( deck, face, suit ); + + return 0; // indicates successful termination + +} // end main + +// shuffle cards in deck +void shuffle( int wDeck[][ 13 ] ) +{ + int temp=0; + int randRow, + randCol; + + for (int column=0;column