Questions string & dynamic array

qoo111
Unregistered
 
Post: #1
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.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #2
qoo111 Wrote: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
It is actually not very long, nor is it hard to understand. It is a very simple assignment that you should easily be able to implement on your own. We do not want to do your homework for you, but if there is a specific part of it which you do not understand then we might be able to help with that.

The first thing you should ask yourself when approaching this is, `do I know what a 2 dimensional array is?' Once you know what that is, then write NewArray2D. One step at a time is how it's done.
Quote this message in a reply
Member
Posts: 715
Joined: 2003.04
Post: #3
I used to work in Englewood NJ.
Now I live in Englewood Colorado.
Small world.

Wish I could help you, but I don't even know where to start from what you posted. One step at a time for sure.

Would help if the process was numbered, the way its posted looks
like "do all this at once".

I bet my wife did that exact assignment from the same school seven years ago.
I'll ask her when she wakes up and see if she recalls any of it.

I wouldn't mind doing your homework without having to pay for it.
If I knew my wife was going to get her degree and say "I hate programming" I would have dressed up like a cute asian girl and went to class for her. LOL
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #4
igame3d Wrote:If I knew my wife was going to get her degree and say "I hate programming" I would have dressed up like a cute asian girl and went to class for her. LOL

I may be generalizing but, *every* woman in CS seems to hate programming (or at least everyone I know)... including many of the female teachers I had, which was terribly annoying Wacko

edit: oh, about the original post Wink - Don't just copy from this, but if you don't even know where to start, take a look at some of these results.
Quote this message in a reply
Member
Posts: 715
Joined: 2003.04
Post: #5
PowerMacX Wrote:Don't just copy from this, but if you don't even know where to start, take a look at some of these results.

Good thing that link was posted, my wife hasn't touched C++ in five years and barely remembers covering dynamic arrays, sorry can't help.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #6
(I know, off-topic but still...)
PowerMacX Wrote:I may be generalizing but, *every* woman in CS seems to hate programming (or at least everyone I know)... including many of the female teachers I had, which was terribly annoying Wacko

This was just posted today in the NYTimes:
http://www.nytimes.com/2007/04/17/scienc...&8dpc&_r=1
Quote:Moving emphasis away from programming proficiency was a key to the success of programs Dr. Blum and her colleagues at Carnegie Mellon instituted to draw more women into computer science. At one time, she said, admission to the program depended on high overall achievement and programming experience. The criteria now, she said, are high overall achievement and broad interests, diverse perspectives and whether applicants seem to have potential to be future leaders.
Huh
Quote this message in a reply
Moderator
Posts: 371
Joined: 2006.08
Post: #7
PowerMacX Wrote:I may be generalizing but, *every* woman in CS seems to hate programming (or at least everyone I know)... including many of the female teachers I had, which was terribly annoying Wacko

edit: oh, about the original post Wink - Don't just copy from this, but if you don't even know where to start, take a look at some of these results.

I actually do know of one girl who likes programming....only one in two years, though Rasp

Anyway, on to the original post: Do you already know how to make two-dimensional arrays? If not, experiment with them before doing the functions. And what are writing this in, Java? I saw a ToString method down there somewhere.
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Haskell IO String Problem michxs 2 5,027 Mar 11, 2008 06:24 PM
Last Post: wyrmmage
  Deleting The End of A String With BM Nick 0 2,345 Jul 2, 2005 08:49 AM
Last Post: Nick