Question
Here is sample code to read and write text data using files. int value1; ifstream finput(input.txt); finput >> value1; ofstream foutput(output.txt); foutput < < value1;
Here is sample code to read and write text data using files.
int value1; ifstream finput("input.txt"); finput >> value1;
ofstream foutput("output.txt"); foutput << value1; foutput.close();
Now, let us say each column of data (sample given below) has been stored in a separate file (file1.txt, file2.txt, file3.txt, filen.txt). We need to read all the data files, find the total of each row of data and output the values to output.txt. Let us assume that all the specified data files have same # of lines & it does not exceed 1000. Assume that there will be maximum 10 data files. IN C++ PLEASE. ALL TEST CASES MUST PASS
Here is some sample data, actual data can be anything:
file1.txt | file2.txt | file3.txt | filen.txt | |
---|---|---|---|---|
1 | 2 | 3 | 10 | |
10 | 20 | 30 | 100 | |
Program should accept a list of filenames in one line, read the data from all those files and total each row of data. Corresponding output.txt will look like
55 550 ...
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started