Question: Write a short program in C++ to read in a list of integers from a file. Each integer should be placed in one of three

Write a short program in C++ to read in a list of integers from a file. Each integer should be placed in one of three arrays the positive even numbers go into an array called evenNum, the positive odd numbers into an array called oddNum and the negatives into an array called negNum. Print the contents (with indexes) of each array properly labeled after the entire file has been read (print only those values you input from the file not the unused elements).

Note that 0 is not positive or negative and should not be stored anywhere, yet is a valid value in the file. You may assume the file contains no more than 30 integers however, they may all be even, odd or negative and the file may contain less than 30 integers.

Connect to my input file by declaring the file name as a constant string, as in:

const string FILENAME = "/home/fac/ohsh/submit/18sq1230/files/lab4input.dat";

You must name your file lab4.cpp

Sample Output:

evenNum[0]: 2 evenNum[1]: 14

OR

evenNum array: index 0: 2 index 1: 14

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!