Advertisement
akosiraff

File_Sum_of_Integers

Feb 1st, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1.  
  2. Download: https://solutionzip.com/downloads/file_sum_of_integers/
  3. Write a program that prints “Please enter your filename.”, reads in the name of the file, and then tries to open it. If the input file is there and can be opened, the program should read the list of integers in the file, which will have one integer per line as in the following example:
  4. 14
  5. 9
  6. 12
  7. -6
  8. -30
  9. 8
  10. 109
  11. Note: This example is just to demonstrate the format of the input file. Your program would not print these values out to the console or to the output file.
  12. The program will then add together all the integers in the file, create an output file called sum.txt, write the sum to that file (just that number – no additional text), and then print (to the console) “result written to sum.txt”. Remember to close both the input and output files. If the input file is not there (or is there but couldn’t be opened for some reason), the program should just print out “could not access file”.
  13. Using a string variable as the parameter of the open function is a C++11 feature, so to compile, you’ll need the “-std=c++0x” flag as discussed in the section “Note on different C++ standards”.
  14. The file must be named: fileAdder.cpp
  15.  
  16. Download: https://solutionzip.com/downloads/file_sum_of_integers/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement