blob: 52c43d366f70953a8474cabbffaf93877e801ffb (
plain)
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
|
// === FUNCTION ======================================================================
// Name: print_array
// Description: Print an array with one dimension.
// Use
// print_array<T,w>( *matrix, n1*n2, n2, "matrix" );
// for
// T matrix[n1][n2];
// =====================================================================================
template <class T, int width>
void print_array ( T *array, // array to print
int n, // number of elements to print
int nrow, // number of elements per row
string arrayname // array name
)
{
string line(" index | content\n ------+-");
cout << "\n\n array \"" << arrayname << "\", length " << n << endl << endl;
cout << line.append(width*nrow, '-');
for ( int i=0; i<n; i+=1 ) {
if( i%nrow == 0 )
cout << endl << setw(6) << i << " | ";
cout << "" << setw(width) << fixed << setprecision(2) << array[i];
}
cout << endl << endl;
return ;
} // ---------- end of function print_double_array ----------
|