Free2Code
 
Time: 2008-11-21, 07:53pm
Another Needs C++ HELP!
Subject: Another Needs C++ HELP!  ·  Posted: 2006-12-07, 12:16pm
Rank: ? (2)
Member #: 29343
Before I get to the problem itself, I need to let you all know that I have very limited knowledge of C++ (very little). So please, don't assume I understand C++ (take it slow with me). Now, onto the problem.

The assignment is below, follwed by the changes that my professor wants made:

ASSIGNMENT

Implement an integer array hierarchy in which the base class represents a one-dimensional array & the derived calsses represent different multidimensional arrays. The base class uses a one-dimensional array to store the integers, and each derived class uses the inherited array to store its intergers.

class intArray { //base class
public:
//interface
protected
int ar[ MaxArray ];
int n; //element count
//rest of implementation
};

A Matrix class could add a data member rowCount to store the number of rows & a data member colCount to store the number of columns. The data could be stored in ar by rows: row 1 first, then row , and so on.

Each class defines its own print method. For example, intArray's print method might include the statement:

//print elements on 1 line, separated by blanks
for ( int = 0; i < n; i++)
cout << ar[ i ] << ' ';

whereas Matrix's print method might include:

//print element with each row on 1 line
for ( int row = 0; row < rowCount; row++ ) {
cout << ar[ col + row * colCount ] << ' ';
cout << '/n';
}

PROFESSOR'S CHANGES

You need only 2 classes in your hierarchy--a base class "array" & a derived class "two_dimensional."

I would like storage to be on the heap, and the array data member to be a pointer to this heap space--that means that your array constructor must get the space and that the destructor must release it (the way C++ handles pointers allows you to use subscripts w/ them so their examples on printing the arrays should work fine).

The "array" class should have 2 data members:
1. An int "n" which indicates the number of elements in the array
2. An int pointer "ar" which points to the array on the heap

This class should have 5 methods:
1. A parameterized constructor
2. A destructor--one that actually does something
3. A "print" method--prints out the 1-dimensional array
4. A "fill" method--asks for & accepts the ints to place in the Array (this method is also inherited & used by the derived class).
5. A "sum_array" method that sums all of the elements in the array (this is also inherited & used by the derived class).


The class "two_dimensional" is a derived class derived from the class "array."

The "two_dimensional" class will have 2 data members:
1. "rowcount"--an int that will give the # of rows
2. "colCount"--an int that will give the # of columns

This class should have 3 methods--in addition to those inherited:
1. A "print()" method that prints out the 2-dimensional array by row
2. A "print_columns()" method that prints out the 2-dimensional array by column
3. A parameterized constructor that will get 2 int parameters--first being the # of rows, & the second being the number of columns (this constructor MUST call the base class constructor).

Do not see "two_dimensional" as needing a destructor. Most difficult part is the subscripting, but they (the original problem) have given you that in the examples. C++ stores 2D by columns. The methods "print()" and "print_columns()" will need these subscripts. About the only difference in these 2 is the order of the loops.

I have absolutely NO IDEA how to do this, and my professor's not a huge help (he expects me to understand this). A walkthrough this problem with detailed instructions would be greatly appreciated !

Sincerely,

Jason Seehusen

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons