Code Review: Review the code (Metal_Plate_Temp.cpp) in the attached program list
ID: 3741844 • Letter: C
Question
Code Review:
Review the code (Metal_Plate_Temp.cpp) in the attached program listing. As it should be, all the information required to understand this program is included in the code comments. Below is a screen-shot for the program’s expected output.
Project Requirements:
Your objective for this coding problem is to implement the code for main() along with the user defined function in plate.cpp & plate.cpp.
You must submit the FULLY DOCUMENTED source code for the three source files (Metal_Plate_Temp.cpp, plate.cpp & plate.h).
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Name : Metal_Plate_Temp.cpp
// Author : Dr. George H. Zion
// Course : Computation Problem Solving II (CPET-321)
// Date : Fall 2018 (2181)
// Description :
//
// Under steady-state conditions, the temperature at any point on the
// surface of a metal plate will be the average of the temperatures of
// all the points surrounding it. This fact can be used in an iterative
// procedure to calculate the temperature distribution at all points on a
// plane.
//
// Figure #1 shows a square plate divided into 100 squares or nodes by a
// grid. The temperature of the nodes form two-dimensional array.
//
// 9 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 8 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 7 [ ][ ][X][ ][ ][ ][ ][ ][ ][ ]
// 6 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 5 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 4 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 3 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 2 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 1 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 0 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
// 0 1 2 3 4 5 6 7 8 9
//
// Figure #1
//
// The temperature at all nodes at the edges of the plate are constrained
// to 20 degrees Celsius by a cooling system, and the temperature at the
// node (2,7) is fixed at 100 degrees Celsius by exposure to boiling water.
//
// A new estimate of the temperature T(R,C) at any node can be calculated
// from the average of the temperatures of all nodes surrounding it using
// the formula in Equation #1.
//
// T(R,C)new = 1/4 ([ T(R+1, C) + T(R-1), C) + T(R, C+1) + T(R, C-1)]
//
// Equation #1
//
// To determine the temperature distribution on the surface of a plate,
// initial assumptions must be made about the temperature at each node,
// then equation #1 is applied to calculate the new temperature at the
// node. These updated temperatures are, in turn, used to calculate new
// temperature. This process is repeated until all new temperatures at
// each node reach a steady-state.
//
// This program calculates the steady-state temperature distribution
// throughout the plate, making an initial assumption that all interior
// segments are at a temperature of 50 degrees Celsius (Remember that
// all outside segments are fixed at 20 degrees Celsius and the node (2,7)
// is fixed at 100 degrees Celsius).
//
// The program follows the following algorithm/pseudo-code:
//
// 1) Display the temperatures of the plane (initial conditions).
// 2) Display an '*' on the screen.
// 3) Perform one interation of new temperature calculations
// for the plate.
// 4) If the change in any node temperature was greater-than 0.01
// degrees Celsius, return to step 2.
// 5) Display the temperatures of the plane (steady-state conditions)
// 6) Display the temperature at node (4,4).
//
// The program utilizes a user-defined library (plate.h & plate.cpp) that
// contains the following user-defined functions:
//
// displayPlate() : Purpose.: Displays the current temperature of
// the plate in a grid format.
// Input...: None
// Output..: None
//
// distributeHeat() : Purpose.: Performs one iteration of new
// temperature calculations for the
// plate.
// Input...: None
// Output..: Returns a boolean value. Returns
// true if the temperature change in
// all the nodes is less-than 0.01
// degrees. Otherwise, returns false.
//
// plateValue() : Purpose.: Determine the current temperature
// of one node of the plate given the
// node's coordinates.
// Input...: The coordinates (column, row) of a
// node.
// Output..: Returns the temperature (double) of
// the node.
//
The program must have three files (Metal_Plate_Temp.cpp, plate.cpp & plate.h) and using three functions listed above. It can include more than 3 functions listed above.
Problems Tasks ConsolePropertiesExplanation / Answer
Metal_Plate_Temp.cpp
#include <iostream> // Required for cin & cout
#include "plate.h" // Contains the user-defined class Plate
using namespace std;
int main()
{
// Instantiate an object (p1) of class Plate
Plate p1;
// Display the temperatures (initial values) of the plate
p1.displayPlate();
// // Display one '*' to the screen and perform one iteration of new
// // temperature calculations. Continue this process until the change
// // in temperature for all nodes is less-then 0.01 degrees.
// do
// {
// cout << '*';
// }
// while(!p1.distributeHeat());
//
// // Display the temperatures (steady-state values) of the plate
// cout << endl;
// p1.displayPlate();
//
// // Display the temperature of node (4,4). If correct, this value
// // will equal 29.43
// cout << "The Steady-State Temperature for Segment (4,4) is : ";
// cout << p1.plateValue(4,4) << endl;
return 0;
}
plate.cpp
#include <iostream> // Required for cin & cout
#include "plate.h" // Contains the user-defined class Plate
#include <iomanip>
using namespace std;
Plate::Plate(){
for(int c=1;c<=9;c++){
for (int r=1;r<=9;r++)
boardarray[c][r]=50.00;
}
for (int i=0;i<10;i++){
boardarray[i][9]=20.00;
boardarray[9][i]=20.00;
boardarray[0][i]=20.00;
boardarray[i][0]=20.00;
};
boardarray[2][7]=100.00;
};
void Plate::displayPlate(){
cout<<fixed<<setprecision(2);
for (int r=9;r>=0;r--){
cout<<r<<" | ";
for (int c=0;c<10;c++){
cout<<setw(7)<<boardarray[c][r];
}
cout<<endl;
}
for(int das=0;das<10;das++){
// cout<<setw(7)<<das;
cout<<setw(7)<<"--";
};
cout<<endl;
for(int num=0;num<10;num++){
// cout<<setw(7)<<"-----"<<endl;
cout<<setw(7)<<num;
};
};
bool Plate::distributeHeat(){
bool tempchange;
for(int i=0;i<10;i++){
for(int k=0;i<10;i++){
if (boardarray[i][k]!=20){
boardarray[i][k]=1/4(boardarray[i+1][k]+boardarray[i-1][k]+boardarray[i][k+1]+boardarray[i][k-1]);
}
}
}
return tempchange;
}
plate.h
#ifndef plate
class Plate
{
private:
double boardarray[10][10];
public:
Plate();
void displayPlate();
bool distributeHeat();
double plateValue();
};
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.