


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!!
#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:

Console:

Output file:

The second problem, the one I'm asking about, is only making changes to the first problem, which ...
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 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 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 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: 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 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 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, 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 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> #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 =...