Need Help! Please. Urgent.Urgent.Urgent.

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

+isNumberFound(someNumber: int); bool
//if the array contains someNumber, return true, otherwise return false

+display():void //specialized display of the array. See output.
----------------------------------





OUTPUT should be like this:

Example output:
Exam Scores
-----------
[0] 67 81 50 29 27 Total:254 Avg:50.8
[1] 58 4 0 6 37 Total:105 Avg:21
[2] 29 4 85 50 12 Total:180 Avg:36
[3] 88 50 38 51 44 Total:271 Avg:54.2
[4] 7 64 67 52 32 Total:222 Avg:44.4
[5] 97 2 28 76 43 Total:246 Avg:49.2
[6] 82 82 99 53 0 Total:316 Avg:63.2
[7] 69 47 36 19 54 Total:225 Avg:45
[8] 33 23 88 61 86 Total:291 Avg:58.2
[9] 45 51 75 92 45 Total:308 Avg:61.6
The minimum value : 0
The maximum value : 99
The total is : 2418
The average is : 48.36
Number of A's : 3
Sorry, you DO NOT have a perfect exam score.
Do you want to try again? (Y or N) y
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
};
I know this



#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <time.h>
using namespace std;

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;
}
}
}



Then I dont know how to go on?
using namespace 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.
Topic archived. No new replies allowed.