Question

een be modeled by diding the plate io adiscrese grid of cels and sulting the change in tenspentureof ell over 90 2.2 3) dared

#include-iostream> #include-ioma nip> #include<fstream> using namespace std; const int NROWS-20, NCOLS = 20; void display (do

Many scienee aad engineering snlations have the general form of the metal plate problem r lab you have a number ok sample sit

The second problem, the one I'm asking about, is only making changes to the first problem, which I have included the correct code for. Thank you!!

een be modeled by diding the plate io adiscrese grid of cels and sulting the change in tenspentureof ell over 90 2.2 3) dared es dlebel css (saggestion:use5 both ves w fint, ut increme this 1o 20asee you get yeur pragranı warking. Your progrars shcald do the Sllasing lain the cs alus of the prid erptures and enay tesp wll be used to ongnethe te vel Poript te Eser·nd efter 'erperature valaes Rr the top, boom, let, teht sides. Also prompt and enter an initiel tepentare T fer the inneriar cels. Fo this leh, you may iniialie ell the inaioe Initielie tenp usingthese values and disply the istial conts of the terp amay on the cesole 2. Copy temp ald 3 Leepova all the ieor cels (bar sot the odge cellst s,aceady nca true afer all cella are checood This is alenper popam thas useal se lere re a number ofhiets reik ahaat theae qu stigul ฝีd dnu ob wish your purt.vr bvtare arv.hy wrinng งเ'y codo. Lay Idouble print α.ต tīt array ary tite, and so te fitxtke, will be useful in debugging your prog om. stake แถเ you can csplan ta fleticg bstween old array th tmparay, and why your pro- stake แถเ yo1tdemnd how to have your propan kxp through only wvrlorof amay Make sare you end what the cenverpesee eterin dest and what role it plays in yoproge
#include-iostream> #include-ioma nip> #include using namespace std; const int NROWS-20, NCOLS = 20; void display (double temp NCOLS]); void update(double temp [) [NCOLS], double old[ INCOLS], double tol, bool& steady); int main) ofstream fout; string filenametemp.dat"; fout.open (filename.c str)); double top, botton, left, right, initial, old[NROWS][NCOLS), temp [NROWS] [NCOLS], tol; int i, j; bool steadyfalse; cout top bottom >> left >> right; cout initial; cout tol; for (i=0; ǐ
Comments
    0 0
    Add a comment Improve this question Transcribed image text
    Answer #1

    #include <iostream>

    #include <cmath>

    #include <string>

    #include <iomanip>

    #include <fstream>

    using namespace std;

    const int NROWS= 10, NCOLS= 10;

    void display(double temp[][NCOLS], int rows, int cols);

    double computeDiff(double oldTemp[][NCOLS],double newTemp[][NCOLS],int rows,int cols);

    void update(double temp[][NCOLS], double T[][NCOLS], double tol, int rows, int cols,bool &steady);

    int main() {

                   ofstream fout;

                   string filename = "temp.dat";

                   fout.open(filename.c_str());

                   double temp[NROWS][NCOLS], old[NROWS][NCOLS], tol;

                   int i, j;

                   bool steady = false;

                   string infile;

                   int rows,cols;

                   cout<<"Enter the filename : ";

                   getline(cin,infile);

                   ifstream fin(infile.substr(0,infile.length()-1).c_str());

                   if(fin.is_open()) // if file can be opened

                   {

                                  fin>>rows>>cols; // read the rows and cols

                                  i=0,j=0;

                                  // read till end of file, reading the values

                                  while(!fin.eof())

                                  {

                                                 fin>>temp[i][j];

                                                 if(j == cols-1)

                                                 {

                                                                i++;

                                                                j=0;

                                                 }else

                                                                j++;

                                  }

                                  fin.close(); //close the file

                                  for(i=0; i<rows; i++){

                                                 for(j=0; j<cols; j++)

                                                                old[i][j]=temp[i][j];

                                  }

                                  display(old,rows,cols);

                                  cout<<"Input the tolerance : ";

                                  cin>>tol;

                                  if(tol <= 0)

                                  {

                                                 cout<<"Tolerance must be positive"<<endl;

                                                 return 1;

                                  }

                                  while(steady == false)

                                  {

                                                 update(temp,old,tol,rows,cols,steady);

                                                 for(i=0; i<rows; i++){

                                                                for(j=0; j<cols; j++){

                                                                               old[i][j]=temp[i][j];

                                                                }

                                                 }

                                  }

                                  cout<<endl;

                                  display(old,rows,cols);

                                  for(i=0;i<rows;i++)

                                  {

                                                 for(j=0;j<cols;j++){

                                                                fout<<left<<setw(9)<<fixed<<setprecision(3)<<temp[i][j]<<" ";

                                                 }

                                                 fout<<endl;

                                  }

                                  fout.close();

                   }else

                                  cout<<"Cannot open file"<<endl;

                   return 0;

    }

    void display(double temp[][NCOLS], int rows, int cols)

    {

                   int i, j;

                   for(i=0; i<rows; i++){

                                  for(j=0; j<cols; j++)

                                                 cout<<left<<setw(9)<<fixed<<setprecision(3)<<temp[i][j];

                                  cout<< endl;

                   }

    }

    double computeDiff(double oldTemp[][NCOLS],double newTemp[][NCOLS],int rows,int cols)

    {

                   int i,j;

                   double sum=0;

                   for(i=0;i<rows;i++)

                   {

                                  for(j=0;j<cols;j++)

                                                 sum += pow(newTemp[i][j]-oldTemp[i][j],2);

                   }

                   return sqrt(sum);

    }

    void update(double temp[][NCOLS], double T[][NCOLS], double tol, int rows, int cols,bool &steady)

    {

                   int i,j;

                   steady = true;

                   for(i=1; i<rows-1;i++){

                                  for(j=1;j<cols-1;j++){

                                                 temp[i][j]=(T[i-1][j]+T[i+1][j]+T[i][j-1]+T[i][j+1])/4.0;

                                                 if(computeDiff(T,temp,rows,cols) >= tol ){

                                                                steady = false;

                                                 }

                                  }

                   }

    }

    //end of program

    Output:

    Input file:

    3 4 1.0 1.0 1.0 2.0 1.1 1.2 1.2 2.0 1.2 1.2 1.2 2.5 2

    Console:

    Enter the filename hw5btest1.dat 1.000 1.000 1.000 2.000 1.100 1.200 1.200 2.000 1.200 1.200 1.200 2.500 Input the tolerance

    Output file:

    1.000 1.000 1.000 2.000 1.100 1.163 1.331 2.000 1.200 1.200 1.200 2.500

    Add a comment
    Know the answer?
    Add Answer to:
    The second problem, the one I'm asking about, is only making changes to the first problem, which ...
    Your Answer:

    Post as a guest

    Your Name:

    What's your source?

    Earn Coins

    Coins can be redeemed for fabulous gifts.

    Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
    Similar Homework Help Questions
    • Hello, I am trying to write this program and have received a "Segmentation Fault" error but...

      Hello, I am trying to write this program and have received a "Segmentation Fault" error but cannot seem to figure out where. I haven't been able to find it and have been looking for quite a while. The goal is to basically create a version of Conway's Game of Life. I am able to generate a table if the input values for rows and columns are equal, but if they are not I receive a segmentation fault and cannot continue...

    • Am I getting this error because i declared 'n' as an int, and then asking it...

      Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

    • C++ Programming I have finished the code but there's one error which shows that "strcpy" might...

      C++ Programming I have finished the code but there's one error which shows that "strcpy" might be unsafe. Consider using strcpy_s instead. I've tried that but it's not working probably because I didn't implement it correctly. I am posting my code below. It'd be really helpful if you could fix all the strcpy errors and post it below. Thank you. Text.cpp: #include <iostream> #include <iomanip> #include <cassert> #include <cstring> #include "Text.h" Text::Text ( const char *charSeq ) {    bufferSize...

    • C++: Need help debugging my code I am writing this and using some other examples as reference code while rewriting it with my own understanding of the material but am having trouble making it finally...

      C++: Need help debugging my code I am writing this and using some other examples as reference code while rewriting it with my own understanding of the material but am having trouble making it finally compile. Below is a picture of the error messages. //main.cpp //Semester Project //Created by J---on 5/6/2019 #include <iostream> #include <fstream> #include <string> #include <sstream> #include <bits/stdc++.h> using namespace std; void instructions(); //displays program details and instructions void openFile(); void takeInput(int*); void switchBoard(int*); struct price {...

    • Posted this a few hours ago. Can anyone help with this? IN C++ Perform the following:...

      Posted this a few hours ago. Can anyone help with this? IN C++ Perform the following: Read 10 bowlers with 3 scores each into 1 string array and 1 numeric array(2 dimension double array) Sort the data by individual bowlers averages, Don't forget to sort their names also. Calculate the average across and store in your existing array. Calculate the average down and store in your existing array. Print out the contents of both arrays. This will print the averages...

    • I'm not getting out put what should I do I have 3 text files which is...

      I'm not getting out put what should I do I have 3 text files which is in same folder with main program. I have attached program with it too. please help me with this. ------------------------------------------------------------------------------------ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the...

    • (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the...

      (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the date of birth.            **fall.sort(compare_DOB); //Here lies your error** #include <fstream> #include <iostream> #include <string> #include <list> #include <cctype> using namespace std; const char THIS_TERM[] = "fall.txt"; const string HEADER = "\nWhat do you want to do ?\n\n" "\t. Add a new friend name and DOB ? \n" "\t. Edit/Erase a friend record ? \n" "\t. Sort a Friend's record ? \n"...

    • C++ only. PROBLEM STATEMENT: A review and extension of cs132:sort a file with 120 records. However,...

      C++ only. PROBLEM STATEMENT: A review and extension of cs132:sort a file with 120 records. However, due to memory restrictions only 20 records may be placed into memory. You are to implement a “quasi” external sort CODE/DIRECTIONS: For the sake of simplicity, and without much loss of generality, we will say for this lab are records are just ints : thus sort a file with 120 ints where only 20 ints maybe placed into memory at any one time general...

    • Please program in C++ and document the code as you go so I can understand what...

      Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

    • /* Implementation of the main() method of the program. */ #include <iostream> #include <string> #include <vector>...

      /* Implementation of the main() method of the program. */ #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; class Student { public:    // default constructor    Student()    {        studentID = 0;        studentFirst = "First";        studentMiddle = "Middle";        studentLast = "Last";    }    void SetStudentID(int number) { studentID = number; }    void SetStudentFirst(string name) { studentFirst = name; }    void SetStudentMiddle(string name) { studentMiddle =...

    ADVERTISEMENT
    Free Homework Help App
    Download From Google Play
    Scan Your Homework
    to Get Instant Free Answers
    Need Online Homework Help?
    Ask a Question
    Get Answers For Free
    Most questions answered within 3 hours.
    ADVERTISEMENT
    ADVERTISEMENT