Example Code for Bridge Hands Problem
/* Read in an array and print it out inverted (up-side-down). */
#include <iostream.h>
void getImage (char picture[5][4]) ;
void writeInversion(char picture[5][4]) ;
int main ()
{
char picture [5][4] ; // 2D array, 5 rows, 4 columns
getImage(picture) ;
cout << endl << endl ;
writeInversion(picture) ;
return 0;
}
/* ################################################## */
/* getImage */
/* ################################################## */
void getImage (char picture[5][4])
{
/* This function puts some input into an array of characters.
Precondition: there are exactly 5 lines of input. Each
line starts with 4 characters that are not whitespace
characters and terminates with a newline character. */
int row, col ;
for (row=0; row<5; row++)
{
for (col=0; col<4; col++)
{
cin >> picture[row][col] ;
}
}
}
/* ################################################## */
/* writeInversion */
/* ################################################## */
void writeInversion(char picture[5][4])
{
/* This function outputs a matrix of characters "upside
down." In other words it writes each row of the matrix in
reverse order, starting with the last row and going up to the
first. */
int row, col ;
for (row=4; row>=0; row--)
{
for (col=3; col>=0; col--)
{
cout << picture[row][col] ;
}
cout << endl;
}
}