Question: ( the code you need to work on is included underneth ) MPL Session 7: Ch. 5.11, PP 70020, copyfile, and debugger, C-I/O Problem: 1.
( the code you need to work on is included underneth )
MPL Session 7: Ch. 5.11, PP 70020, copyfile, and debugger, C-I/O
Problem:
1.Copy the preceding copyfile program, get it working in MS VC++, and do the following:
1.Have it copy the input file to 2 output files: prompt for 3 file names, have 2 output files
2.Have it check for open() errors on the 2 output files, and report error messages on them.
3.Have it report, on the screen, the total # of lines copied.
#include
int main () { int aNumber=0; int numbers=0; double sum=0.0; double average=0.0;
ifstream randomFile; randomFile.open("Random.txt");
if (randomFile.fail()) cout << "failed to read file."; else {
while (randomFile >> aNumber) { numbers++; sum+=aNumber; }
if (numbers>0) average = sum/numbers; else average=0.0;
cout << "Number of numbers: " << numbers << " "; cout << "Sum of the numbers: " << sum << " "; cout << "Average of the numbers: " << average;
}
randomFile.close(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
