Homework 21
 

Write a recursive function

 

void rectangle(int rowNum, int colNum, ostream &OUT);

that prints out rectangles of *'s with rowNum rows and colNum columns. In the spirit of bottom-up design, I'll provide you with a function you may want to use:

void rep(char c, int k, ostream& OUT)
{
  for(int i = 0; i < k; i++)
    OUT << c;
}

Test your function with a program that reads the dimensions of the rectangle (you may assume non-negative integer input from the user) and the destination (screen or file) that you’re writing to from the user.  If the user asks for a file output, then ask for the name of the file.  Here is a sample output (user input shown in red):

How many rows? 8
How many columns? 3
(S)creen or (F)ile? S
 
***
***
***
***
***
***
***
***
 
Here is a second run of the program, this time to a file:
 
How many rows? 8
How many columns? 3
(S)creen or (F)ile? F
Filename? hw21.txt
Rectangle saved to file hw21.txt.

 

Turn In a printout of your program, hw21.txt, and two screen captures, one showing your program run on the above example with output going to the screen, and another showing the same input with the output going to a file called hw21.txt.