CJCoding With Joseph
15free / daySign inCreate account

Split by Parity

Write a function void splitByParity(const string& src, const string& evens, const string& odds) that reads all the whitespace-separated integers from the file src and writes every even integer to the file evens and every odd integer to the file odds, in the order they were read. Each output file is created (truncated) and holds exactly one line: its integers separated by single spaces, no space before the first, followed by a newline. Print nothing to cout. Every test source has at least one even and one odd number.

The test creates the source file, calls your function, prints Evens: a space and the even count, a space, Odds: a space and the odd count, then prints every line of the evens file and then the odds file. For a source containing 1 2 3 4 5 (see Expected Output).

Do NOT write a main function.

Expected Output:

Evens: 2 Odds: 3
2 4
1 3 5
Evens: 2 Odds: 2
10 8
7 3

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Streamsofstream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.