(Function Template Overloading) Overload function template printArray of Fig. 14.1 with a nontemplate version that prints an array of character strings in neat, tabular, column format.
What will be an ideal response?
```
// Using template functions
#include
#include
#include
using namespace std;
// function template printArray
template< typename T >
void printArray( T const * array, int size )
{
// display elements of array
for ( int i = 0; i < size; i++ )
cout << array[ i ] << ' ';
cout << endl;
} // end function printArray
// function that prints array of strings in tabular format
void printArray( const string stringArray[], int size )
{
// display elements of array
for ( int i = 0; i < size; i++ )
{
cout << setw( 10 ) << stringArray[ i ];
if ( ( i + 1 ) % 4 == 0 ) // create rows
cout << '\n';
} // end for
cout << endl;
} // end function printArray
int main()
{
const int ACOUNT = 5; // size of array a
const int BCOUNT = 7; // size of array b
const int CCOUNT = 6; // size of array c
const int SCOUNT = 8; // size of array strings
// initialize arrays
int a[ ACOUNT ] = { 1, 2, 3, 4, 5 };
double b[ BCOUNT ] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 };
char c[ CCOUNT ] = "HELLO"; // 6th position for null
string strings[ SCOUNT ] =
{ "one", "two", "three", "four", "five", "six", "seven", "eight" };
cout << "Array a contains:\n";
printArray( a, ACOUNT ); // integer template function
cout << "\nArray b contains:\n";
printArray( b, BCOUNT ); // float template function
cout << "\nArray c contains:\n";
printArray( c, CCOUNT ); // character template function
cout << "\nArray strings contains:\n";
printArray( strings, SCOUNT ); // function specific to string arrays
} // end main
```
Array a contains:
1 2 3 4 5
Array b contains:
1.1 2.2 3.3 4.4 5.5 6.6 7.7
Array c contains:
H E L L O
Array strings contains:
one two three four
five six seven eight
You might also like to view...
Copy /bin/bash to the working directory and make two copies so you have three identical files: bash1, bash2, and bash3. Compress bash1 using gzip and bash2 using bzip2. Do not change bash3. Which utility does the best job of compressing the file? Which does the worst? How big is bash2.bz2 compared to bash3?
What will be an ideal response?
HTML 4 supports ____ different input types.
A. 10 B. 15 C. 16 D. 17
The ____________________ Tool is used to draw straight lines.
Fill in the blank(s) with the appropriate word(s).
The critical path is always a series of critical tasks; it cannot be a single task.
Answer the following statement true (T) or false (F)