The following program prints a picture of a large letter I. The output has 13 rows and 7 columns. The first row and last two rows make horizontal lines at the top and bottom of the letter. The other 10 rows form a vertical line in the letter. The program output should look as follows:
-------
|
|
|
|
|
|
|
|
|
|
-------
-------
Some pieces of the code have been replaced by PART (a), PART (b), and so on. To answer the 6 parts of this question you should supply the part of the line of C++ code that was replaced. Each answer must fit on a single line.
int main()
{
int rows = 13;
int cols = 7;
for (int c = 1; {\bf PART (a)} ){
cout << "-"; }
cout << endl;
for (int r = 1; {\bf PART (b)} ){
for (int c = 1; {\bf PART (c)} ){
cout << " "; }
cout << {\bf PART (d)}; }
for ({\bf PART(e) }){
for ({\bf PART (f) }){
cout << "-"; }
cout << endl; }
return 0; }
Recovered code example
#include <iostream>
using namespace std;
int main()
{
int rows = 13;
int cols = 7;
for (int c = 1; c <= cols;c++) {
cout << "-";
}
cout << endl;
for (int r = 1; r <= rows-3;r++) {
for (int c = 1; c <= cols / 2;c++) {
cout << " ";
}
cout << "|\n";
}
for (int r = 1; r <= 2;r++) {
for (int c = 1; c <= cols; c++) {
cout << "-";
}
cout << endl;
}
return 0;
}
Answer:
c <= cols; c++
r <= rows-3; r++
c <= cols / 2; c++
"|\n"
int r = 1; r <= 2; r++
int c = 1; c <= cols; c++
Comments
Leave a comment