Multiplication Grid to a File
mediumQuestion 617Write a function void writeGrid(const string& filename, int n) that opens filename with an ofstream and writes an n by n multiplication table. Row i (from 1 to n) contains the products i*1, i*2, ..., i*n, each written right-aligned in a field 3 characters wide (setw(3)) with no other separator, followed by a newline.
For writeGrid("grid_a.txt", 3) the file must contain:
1 2 3
2 4 6
3 6 9
Do NOT write a main function.
Expected output
1 2 3 2 4 6 3 6 9 1 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
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.