Hello, everyone. Please help me create a HEADER file. Due by tomorrow. Thanks Thanks Thanks.
Implement a class called MultiArray based on the UML below. You will also need the following constants:
const int ROWSIZE = 10; // Number of rows the array can hold
const int COLSIZE = 5; // Numbe of columns the array can hold
MultiArray
-----------------
-data[ROWSIZE][COLSIZE]:int //2DArray int with ROWSIZE and COLSIZE
-------------------------------
+MultiArray() // Constructor. Initialize all elements to 0.
+randomFill():void //fill array with random numbers (int) in the range 0 -100
+getRowSize():int //return the row size of the array.
+getColSize():int //return the column size of the array
+getTotal(): int //Calculate and return the total of the values in the array.
+getRowTotal(r:int):int
//Calculate and return the total of the values stored in a given row in the array.
+getAvg():double //Calculate and return the average of the values in the array.
getRowAvg(r:int):double
//Calculate and return the average of the values in a given row in the array.
+getLargest():int //Find and return the largest value in the array.
+getSmallest():int //Find and return the smallest value in the array.
+countValues (lowRange: int, highRange: int); int
//counts and return the number of values that are >= lowRange and <= highRange
The header file typically contains the object definition and the function declarations. Here's something to get you started:
MultiArray.h
1 2 3 4 5 6 7 8 9
class MultiArray{
int width; // will probably be same as the appropriate const value
int height; // will probably be same as the appropriate const value
MultiArray();
randomFill();
// and so on - all function declarations here. Some need to be private, some public
};
const int ROWSIZE = 10; // Number of rows the array can hold
const int COLSIZE = 5; // Numbe of columns the array can hold
class MultiArray
{
private:
int data[ROWSIZE][COLSIZE]; //2DArray holding ROWSIZE x COLSIZE int values
public:
MultiArray();
void randomFill();
int getRowSize();
int getColSize();
int getTotal();
int getRowTotal(int);
double getAvg();
double getRowAvg(int);
int getLargest();
int getSmallest();
int countValues (int, int);
bool isNumberFound(int);
void display();
};
MultiArray::MultiArray()
{ for (int r = 0; r < ROWSIZE; r++)
{
for (int c = 0; c < COLSIZE; c++)
{
data[r][c] = 0;
}
}
}
usingnamespace std;
Please do not ever put this in a header. It invisibly trashes the namespace.
Do not put function definitions in the header file. If more than one cpp file includes the header, the linker will refuse to build the programme because the same functions are defined repeatedly.
Then I dont know how to go on?
Take the next function to be written, and write it. For example:
1 2 3 4 5 6 7 8 9
int getRowSize()
{
// Hmm, I need to return something. What could
// that be? Maybe it's the number of Number of rows the array can hold
// How can I know that? Oh yes, it's a value I already put in. I can
// return that.
return ROWSIZE;
}
This is programming. Thinking about the problem and working out how to solve it using the language chosen. Your problem does not seem to be coding; your problem is thinking. Take each function and think about what it is meant to do, and think about how you would solve it if you just had to do it on paper.