Write a complete C++ program to read the integers in the file numbers.txt and re
ID: 3681127 • Letter: W
Question
Write a complete C++ program to read the integers in the file numbers.txt and report to cout how many numbers are in the file and the sum of all the numbers. Copy and paste the output to your source file. Then modify the file numbers.txt by adding the numbers 224 and 543 at the end of the file. Run your program again and copy and paste this second output to your source file.
NOTE: For end-of-file processing for a file of numbers, review the sample programs presented in class.
12 82 34 24 33 47 21 88 123 21
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
// your code goes here
int sum=0;
int n,i=1;
int c1[60];
ifstream Numfile("numbers.txt");
while(Numfile>>n){
c1[i]=n;
sum = sum + c1[i];
i++;
}
Numfile << (sum +224)<<endl;
Numfile << (sum+543)<<endl;
Numfile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.