qoo111
2007.04.16, 04:21 PM
In this assignment i have to develop functions that allow us to create,
manipulate, convert to a string, and delete dynamic 2D arrays.
Can anyone help me to creat this?? I know it is really long and hard to understand but please help me~~~ T.T
Implement the following functions:
int ** NewArray2D( int nRow, int nCol ) { ... }
This functions uses the new operator to create a 2D array of ints with
nRow rows and nCol columns. It returns a pointer to the 0,0 element of the
array.
void DelArray2D( int ** & array2D, int nRow ) { ... }
This function uses the delete operator to delete all the memory
allocated for array2D and then sets array2D to 0.
void InitArray2D( int ** array2D, int nRow, int nCol, int val ) { ... }
This function sets every element of array2D to the value val.
CopyArray2D( int ** a2D, int ** b2D, int nRow, int nCol ) { ... }
This function copies array b2D over array a2D, which means that all
elements of b2D are copied over corresponding elements of a2D.
int ** AddArray2D( int ** a2D, int ** b2D, int nRow, int nCol ) { ... }
This function adds corresponding elements of arrays a2D and b2D and
assigns the values to corresponding elements of a new array c2D, which the function creates for the purpose. The function returns a pointer to the 0,0 element of array c2D.
string ToString( int ** a2D, int nRow, int nCol ) { ... }
This function creates a C++ string from the values of the elements of
array a2D. The string is designed to be displayed using standard stream output as follows
cout << "a2D = \n" <<ToString( ) << endl;
The array will be shown one row per line of output, left to right, top to
bottom.
Testing
Test your functions as follows
* Create 2 2D arrays, a2D and b2D.
* Initialize a2D to all 8's and Display it.
* Copy a2D over b2D and show b2D.
* Declare 2D array c2D and make it equal to the sum of arrays a2D and
b2D. Show the sum now in c2D.
Hint
The simplest way to produce a C++ string from numeric data is to use a
stringstream object as follows:
#include <sstream>
stringstream ss;
ss << "..." << val_1 << "..." <<
... << val_n; // "outputs"
return ss.str( ); // converts ss to a C++ string
Think of ss as a string that can be used as a stream for output.
manipulate, convert to a string, and delete dynamic 2D arrays.
Can anyone help me to creat this?? I know it is really long and hard to understand but please help me~~~ T.T
Implement the following functions:
int ** NewArray2D( int nRow, int nCol ) { ... }
This functions uses the new operator to create a 2D array of ints with
nRow rows and nCol columns. It returns a pointer to the 0,0 element of the
array.
void DelArray2D( int ** & array2D, int nRow ) { ... }
This function uses the delete operator to delete all the memory
allocated for array2D and then sets array2D to 0.
void InitArray2D( int ** array2D, int nRow, int nCol, int val ) { ... }
This function sets every element of array2D to the value val.
CopyArray2D( int ** a2D, int ** b2D, int nRow, int nCol ) { ... }
This function copies array b2D over array a2D, which means that all
elements of b2D are copied over corresponding elements of a2D.
int ** AddArray2D( int ** a2D, int ** b2D, int nRow, int nCol ) { ... }
This function adds corresponding elements of arrays a2D and b2D and
assigns the values to corresponding elements of a new array c2D, which the function creates for the purpose. The function returns a pointer to the 0,0 element of array c2D.
string ToString( int ** a2D, int nRow, int nCol ) { ... }
This function creates a C++ string from the values of the elements of
array a2D. The string is designed to be displayed using standard stream output as follows
cout << "a2D = \n" <<ToString( ) << endl;
The array will be shown one row per line of output, left to right, top to
bottom.
Testing
Test your functions as follows
* Create 2 2D arrays, a2D and b2D.
* Initialize a2D to all 8's and Display it.
* Copy a2D over b2D and show b2D.
* Declare 2D array c2D and make it equal to the sum of arrays a2D and
b2D. Show the sum now in c2D.
Hint
The simplest way to produce a C++ string from numeric data is to use a
stringstream object as follows:
#include <sstream>
stringstream ss;
ss << "..." << val_1 << "..." <<
... << val_n; // "outputs"
return ss.str( ); // converts ss to a C++ string
Think of ss as a string that can be used as a stream for output.