Manipulating Array in FileInput

closed account (yhTXSL3A)
My code is supposed to take an array from a fileInput and use each indvidual entry in an equation then it outputs the result onto another file. However, I am having trouble getting each entry in the equation.

Sorry if I don't use the proper words to describe my problem. This is actually my first semester using C++ and I've done past assignments pretty well but this one confuses me since it has a lot of things at once going on, and I've been working on it for 2 days now. Just a few hints would be appreciated.

Here is the original question:

a) Read “distance1.txt” and “distance2.txt” – These are 15 x 10 matrices.

a) Use 1/sqrt(2*3.14)*exp^(-x^(2)/2) on each entry of these two matrices. (x is the individual entry from the matrix)

b) Generate “distribution1.txt” and “distribution2.txt” based on the result of the previous step – the dimension has to be 15 x 10 for each matrix in the individual txt file.

And this is what I've got so far:


#include <iostream>

#include <string>

#include <fstream>

#include <cmath>


int main () {


std::string array;

int numbers [15][10];


std::ifstream fileInput("distance1.txt");



if (fileInput.is_open()) {

std::cout << "The following arrays have been recorded..\n\n";

for (int row=0;row<15;row++){

for(int column=0;column<10;column++){










fileInput.close();

}
}
}else { //couldn't open file

std::cout <<"The file could not be opened ! \n";

return 1; //Indicates a problem occurred.



//Wait for the user to press Enter or Return.
std::cout <<"Press Enter or Return to continue.\n";
std::cin.get();

return 0;
}}



I'd create 3 functions:
void readArray(int arr[15][10], istream &is) should read the array from "is" into arr. writeArray(int arr[15][10], ostream &os) should write the array out to os. Finally changeArray(int arr[15][10]) should modify the array using the formula given.

- Create readArray() and writeArray(). Write the main() program to read distance1.txt and write it out (unchanged) to distribution1.txt.

- Next create changeArray(). Modify the main() program to change the array so that distribution1.txt has the right values.

- Check a few of the values in distribution1.txt with a calculator to make sure they are right. Don't worry about small differences.

Finally, add code to main to read/change/write distance1.txt.
Topic archived. No new replies allowed.