#include #include using namespace std; void graphPaper(int nrows, int ncols, int nrowsb, int ncolsb); int main() { //Output four sheets of customized graph paper. graphPaper(10, 10, 1, 4); cout << "\n"; graphPaper(5, 5, 2, 6); cout << "\n"; graphPaper(1, 1, 4, 10); //one big box cout << "\n"; graphPaper(10, 10, 1, 1); //Each box contains just 1 blank. return EXIT_SUCCESS; } //Output graph paper with the given number of rows and columns of boxes. //Each box will contain nrowsb and ncolsb of blanks. void graphPaper(int nrows, int ncols, int nrowsb, int ncolsb) { if (nrows < 1) { cerr << "Must have at least 1 row, not " << nrows << ".\n"; exit(EXIT_FAILURE); } if (ncols < 1) { cerr << "Must have at least 1 column, not " << ncols << ".\n"; exit(EXIT_FAILURE); } if (nrowsb < 1) { cerr << "Each box must contain at least 1 row of blanks, not " << nrowsb << ".\n"; exit(EXIT_FAILURE); } if (ncolsb < 1) { cerr << "Each box must contain at least 1 col of blanks, not " << ncolsb << ".\n"; exit(EXIT_FAILURE); } for (int r {0}; r < nrows; ++r) { for (int c {0}; c < ncols; ++c) { //Output a plus, followed by ncolsb dashes. cout << "+"; for (int cb {0}; cb < ncolsb; ++cb) { cout << "-"; } } cout << "+"; cout << "\n"; for (int rb {0}; rb < nrowsb; ++rb) { for (int c {0}; c < ncols; ++c) { //Output vertical bar, followed by ncolsb blanks cout << "|"; for (int cb {0}; cb < ncolsb; ++cb) { cout << " "; } } cout << "|"; cout << "\n"; } } for (int c {0}; c < ncols; ++c) { //Output a plus, followed by ncolsb dashes. cout << "+"; for (int cb {0}; cb < ncolsb; ++cb) { cout << "-"; } } cout << "+"; cout << "\n"; }