TOUGH LAB ASSIGNIMENT......

I have no idea how to do this lab assigniment please point in right direction....

coding language is c++

Read in a matrix of 6 x 6 numbers (date type: float) from the text file called “depth.txt” representing 36 measured ocean depths (in meters). This grid represents 36 measurements in an area 6 meters by 6 meters (a measurement is recorded every meter in each direction).

You need to print the coordinates of the following:

PART A) the deepest point in the ocean, and

PART B) the deepest 2 x 2 area (computed to be the average depth over four measurements in a 2 x 2 square)

and also calculate:

PART C) the average depth of all the measurements

In solving PART C, you must create a function (function name: avg_depth) that calculates the average depth and returns the average value via the return command. You should pass 3 arguments to the function: the array name (pointer) itself, the number of rows and the number of columns. Do not overwrite any of the data in the array.

The answers should be written to an output file called the LAB9OUTxxx.txt, where xxx=your initials. Output should appear as PART A , PART B and PART C, as follows:

PART A:

The depth matrix is:

542.2 543.3 542.3 543.1 544.1 543.6
543.1 543.4 546.1 545.8 546.6 547.2
544.1 544.3 547.1 546.9 548.7 547.8
544.6 545.5 545.6 547.6 546.5 546.3
543.2 543.9 544.5 547.6 546.5 545.9
543.4 544.6 545.7 544.9 544.8 543.9
What have you written so far?

Hint: start with laying out the shell of the program (e.g. put the includes you will need and put an empty main function)
First of all, read up on the handling of in- and output at the documentation section of the website, more specifically, 'Input/Output with files' of the tutorial should be enough.

If you know how to handle input, the next step is to put the data into a matrix. You probably want to store them in a std::vector (for part b).

For part A, all you have to do is iterate the matrix, storing the largest value in a variable and comparing that value with the other values as you go further down the matrix.

For part C, all you have to do is iterate the whole matrix, adding every value to a variable that you add every value to. Then after iterating the whole matrix, divide by the amount of values in the matrix (36).

For part B, you will have to iterate every possible 2X2 square. You only have to know one of the coordinates (example, top-left coordinate of the square), to know the rest of the coordinates of a 2X2 square. By iterating all the possible top-left coordinates and calculating the average values of 2X2 squares. You'll need three variables in this case, one for the column coordinate of the top-left coordinate of the deepest 2X2 square, one for the row coordinate of the top-left coordinate of the deepest 2X2 square and one for holding the depth of the deepest 2X2 square.
2 things you should keep in mind:
- Not every location can be the top-left coordinate (the most right/bottom values), and thus shouldn't be calculated.
- Write a function that has the column and row coordinates as input and returns the average depth of the 2X2 square. Compare the returned value with the variable holding the deepest depth and change the variables if necessary.


To write to documents, again, refer to the 'input/output with files' page in the tutorial.
Topic archived. No new replies allowed.