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
|
#include<iostream>
const int ROWS = 5;
const int COLS = 5;
// ZERO = '0': probably a good idea not to mix characters and integers
enum symbol : char { AT = '@', STAR = '*', X = 'X', ZERO = '0', ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};
// 'array_type' is a succinct name (an alias) for 'two-dimensional array of ROWSxCOLS symbols'
using array_type = symbol[ROWS][COLS] ;
void fill( array_type& symbolArr, symbol sym ) // fill the array with symbol 'sym'
{
for( auto& row : symbolArr ) // for each row in the array
for( symbol& s : row ) s = sym ; // assign 'sym' to each symbol in the row
}
void putStar( array_type& symbolArr ) { fill( symbolArr, STAR ) ; }
void print( const array_type& symbolArr )
{
for( const auto& row : symbolArr ) // for each row in the array
{
for( symbol s : row ) std::cout << char(s) ; // print each symbol in the row as a character
std::cout << '\n' ; // and then, a new line
}
}
int main()
{
symbol symbolArr[ROWS][COLS] ;
putStar(symbolArr);
print(symbolArr) ;
std::cout << '\n' ;
fill( symbolArr, SEVEN ) ;
print(symbolArr) ;
}
|