#include #include #include using namespace std; //prototypes void rectangle(int, int, ostream&); void rep(char, int, ostream&); int main (){ int rows,cols; char outputType; //ask info from user cout << "How many rows? "; cin >> rows; cout << "How many columns? "; cin >> cols; cout << "(S)creen or (F)ile? "; cin >> outputType; if (outputType == 'F'){ string name; cout << "Enter the name of the output file: "; cin >> name; ofstream fout(name.c_str()); rectangle(rows,cols,fout); } else rectangle(rows,cols,cout); return 0; } void rectangle(int r, int c, ostream & out){ if (r==0) // base case, nothing to print return; else{ // recursive case rep('*',c,out); // print a c number of * on a row out << endl; // newline rectangle(r-1,c,out); // recursive call for 1 less row } } void rep(char c, int k, ostream& out){ for(int i = 0; i < k; i++) out << c; }