A file named data.txt contains an unknown number of lines, each consisting of a single integer. Write a program that creates the following three files: dataplus.txt dataminus.txt zeros.txt The program should read each line of the data.txt file and perform the following: If the line contains a positive number, that number should be written to the dataplus.txt file. If the line contains a negative number, that number should be written to the dataminus.txt file. If the line contains the value 0, do not write the value to a file. Instead, keep a count of the number of times 0 is read from the data.txt file.  After all the lines have been read from the data.txt file, the program should write the count of zeros to the zeros.txt file.

icon
Related questions
Question
A file named data.txt contains an unknown number of lines, each consisting of a single integer.
Write a program that creates the following three files:
  • dataplus.txt
  • dataminus.txt
  • zeros.txt
The program should read each line of the data.txt file and perform the following:
  • If the line contains a positive number, that number should be written to the dataplus.txt file.
  • If the line contains a negative number, that number should be written to the dataminus.txt file.
  • If the line contains the value 0, do not write the value to a file. Instead, keep a count of the number of times 0 is read from the data.txt file. 
After all the lines have been read from the data.txt file, the program should write the count of zeros to the zeros.txt file. 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.