summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp')
-rw-r--r--Bachelor/Prog1/Prakt5/prg1p5_1/main.cpp124
1 files changed, 124 insertions, 0 deletions
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