# Project #77687 - ARRAYS C++

Problem: Suppose you have a thin metal plate where each of the edges are maintained at a constant temperature. You can model the plate as a 2-dimensional array of square cells each of which may have a different temperature. Given the size of the array and the temperature of the edges, you are to calculate the temperature of an interior cell by averaging the 4 neighboring (cells immediately above, below, left and right) cell temperatures. The temperature of four corner cells will be the average of the two corresponding edge temperatures.

Your program is going to use the case of “immediate” updating in which you will be begin with the cell in the left most interior cell in the top interior row and work across the row, calculating new temperatures for each cell and replacing the old temperatures with the new ones. Then you will proceed to the second interior row. After calculating the temperatures for the all the interior cells an iteration counter should be updated and the process should repeat until all the cells have absolute change in temperature of less than a value, epsilon, which indicates that equilibrium has been reached. (Epsilon may vary from experiment to experiment and user to user.) The temperatures of the edge cells should remain constant.

Your program should prompt the user to enter the size of the array and the temperature of the top edge, bottom edge, left edge and right edge. The size of the array may not be more than 26 by 30. The temperatures of the edges may not be less than 0 or greater than 300. Store the temperature values in the appropriate cells, the corner cells should be the average of the two bordering edge cells. You should assume that the interior cells originally are at 0 degrees. The user should also be prompted to enter the value of epsilon that will be used to determine when the plate has reached equilibrium.

After the array has been initialized, begin the process of determining temperature of the interior cells (the average of the 4 cells that share an edge). The temperatures of the cells on the outside should remain constant, only the temperatures of the internal cells should change. Once all the interior cells change less than epsilon you should output the array with the temperatures and state how many iterations were needed to reach the equilibrium temperature distribution. Your program should employ a function to output the 2-D array. The function should use appropriate formatting so the output of the temperatures in the cell are displayed to 1 decimal place and are aligned.

For example, suppose you had a plate that could be modeled using a 5 by 7 array of cells, with the temperature of the top edge being at 100 degrees, the bottom edge being at 90 degrees, the left edge being at 75 degrees and the right edges being at 75 degrees. Initially the array would look like:

Initial array

```    87.5   100.0   100.0   100.0   100.0   100.0    87.5
75.0     0.0     0.0     0.0     0.0     0.0    75.0
75.0     0.0     0.0     0.0     0.0     0.0    75.0
```

Programming Project 2 1 CMPSC 201 – Summer 2015

```75.0     0.0     0.0     0.0     0.0     0.0    75.0
82.5    90.0    90.0    90.0    90.0    90.0    82.5
```

If we assume epsilon is 0.01 degrees, after 20 iterations equilibrium would be reached and would look as follows:

The plate reached equilibrium after 20 iterations.

```    87.5   100.0   100.0   100.0   100.0   100.0    87.5
75.0    87.9    92.6    93.8    92.6    87.9    75.0
75.0    83.9    88.6    90.0    88.6    83.9    75.0
75.0    84.2    87.9    89.0    87.9    84.2    75.0
82.5    90.0    90.0    90.0    90.0    90.0    82.5
```

Hint: When you are testing, calculate by hand what the array would like after each of the first 3 iterations. Then run your loop for only 3 iterations (rather than when the change is less than epsilon), output after each iteration and compare to your hand calculations.

Your code should only contain one 2-dimensional array. Do not use vectors for this assignment.

You may use functions for this project. If you do use function make sure you write comments immediately before each function describing the purpose of that function, input to that function (what is passed to the function), output from the function (what the function sends back to the call and/or outputs with cout), and processing for this function. The comments for each function should be in addition to the introductory comments for the entire program which occur at the very beginning of the code.

 Subject Computer Due By (Pacific Time) 07/28/2015 11:00 pm
TutorRating
pallavi

Chat Now!

out of 1971 reviews
amosmm

Chat Now!

out of 766 reviews
PhyzKyd

Chat Now!

out of 1164 reviews
rajdeep77

Chat Now!

out of 721 reviews
sctys

Chat Now!

out of 1600 reviews

Chat Now!

out of 770 reviews
topnotcher

Chat Now!

out of 766 reviews
XXXIAO

Chat Now!

out of 680 reviews