CJCoding With Joseph
15free / daySign inCreate account

Squares Table

Write a function void writeSquares(const string& filename, int n) that opens filename with an ofstream and writes one line for every integer k from 1 to n (n is always at least 1). Each line holds k, a single space, and k*k, followed by a newline. For writeSquares("squares_a.txt", 3) the file must contain exactly (see Expected Output).

The test reopens the file and prints every line, so that is also the output.

Do NOT write a main function.

Expected Output:

1 1
2 4
3 9
1 1
2 4
3 9
4 16
5 25

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

Hints3 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.