Identify three structural (not comments or formatting) improvements that could b
ID: 3743707 • Letter: I
Question
Identify three structural(not comments or formatting) improvements that could be made to the program. Explain why these are improvements. Implement the improvements in a fully documented and compilable c++ program
#include <iostream>
#include<string>
using namespace std;
const string BLACK = "********"; //define a line of black squares
const string WHITE = " ";//define a line of white squares
int main()
{
string whiteRow; //a row beginning with white squares
string blackRow; //a row beginning with black squares
//create a white-black row by concatenating the basic strings
whiteRow = WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK;
//create a black-white row by concatenating the basic strings
blackRow = BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE;
//print five white-black spaces
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
//print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
//print five white-black spaces
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
//print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
//print five white-black spaces
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
//print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
//print five white-black spaces
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
//print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
} return 0;
Explanation / Answer
#include #include using namespace std; const string BLACK = "********"; //define a line of black squares const string WHITE = " "; //define a line of white squares int main() { string whiteRow; //a row beginning with white squares string blackRow; //a row beginning with black squares //create a white-black row by concatenating the basic strings // 1. improvement 1 for(int i = 0; i < 4; ++i) { whiteRow += WHITE + BLACK; } // 2. improvement 2 //create a black-white row by concatenating the basic strings for(int i = 0; i < 4; ++i) { blackRow += BLACK + WHITE; } // 3. improvement 3 for(int i = 0; i < 4; ++i) { for(int j = 0; j < 5; ++j) { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.