In this project, you will program C++ code to open an existing data file to read
ID: 3625067 • Letter: I
Question
In this project, you will program C++ code to open an existing data file to read the number of two arrays, each of them contains 10 elements. The corresponding element in those two arrays will be added to each other and assign to the element in the third array, which is:C[ i ] = A [ i ] + B [ i ] , i = 1 ,2,3 ….. 10
Open another data file to write the result of c [i] into it. Print out the source code and result data file.
Explanation / Answer
So I am not sure what you meant by "print out the source code and result data file." Anyways, for my input test file I called it "input.txt" if you need it to be something different just change it in the code which will follow. Information in input.txt 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 I told the program to output the values of Array C into output.txt. Again just change the filename in the code. Code: #include #include #include #include #define MAX_SIZE 10 using namespace std; int main(int argc, char *argv[]) { int A[MAX_SIZE]; int B[MAX_SIZE]; int C[MAX_SIZE]; int get_number = 0; ifstream inputFile; ofstream outputFile; /* First open the input text file and check to see if it can open */ inputFile.open("input.txt"); if(inputFile.fail()) { cout = 0 && i > get_number; A[i] = get_number; } else if(i >= MAX_SIZE && i < (MAX_SIZE*2)) { inputFile >> get_number; B[i-MAX_SIZE] = get_number; } } if(inputFile.eof()) { break; } for(int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.