Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help //****************************************************************** /

ID: 3879699 • Letter: N

Question

need help

//******************************************************************
// Chessboard program
// This program prints a chessboard pattern that is built up from
// basic strings of white and black characters.
//******************************************************************

#include <iostream>
#include <string>

using namespace std;


const string BLACK = "$$$$$$$$"; // Define a line of a black square
const string WHITE = "        "; // Define a line of a white square

int main ()
{
string whiteRow;            // A row beginning with a white square
string blackRow;            // A row beginning with a black square

// 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 rows
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 rows
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 rows
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 rows
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;                 
}     
   
       

025903_CH02 DaleLab 18 20 Exercise 3: Change the program so that only the outline of each square is shown. Here is an example row: ss$ss$$$ SS$$$S$$ SSS$SSS$ s$$SS$$S $$$SS$$ S$$SS$$ SSS$SS$ Compile and run your program. Exercise 4: Change the program from Exercise 3 so that the squares are 8 by 8 rather than 5 by 8. Here is an example row: $$$S$$ Compile and run your program. Clearly an 8-by-8 design is not a square but a 5-by-B design is. Explain

Explanation / Answer

The code for 3 is

//******************************************************************
// Chessboard program
// This program prints a chessboard pattern that is built up from
// basic strings of white and black characters.
//******************************************************************

#include <iostream>
#include <string>

using namespace std;


const string BLACK = "$$$$$$$$"; // Define a line of a black square
const string WHITE = " "; // Define a line of a white square
const string s= "$ $";
int main ()
{
string whiteRow; // A row beginning with a white square
string blackRow; // A row beginning with a black square
string row2;
string row3;
// Create a white-black row by concatenating the basic strings
whiteRow = WHITE + BLACK + WHITE + BLACK +
WHITE + BLACK + WHITE + BLACK;
row2=WHITE + s + WHITE + s +
WHITE + s + WHITE + s;
// Create a black-white row by concatenating the basic strings
blackRow = BLACK + WHITE + BLACK + WHITE +
BLACK + WHITE + BLACK + WHITE;
row3=s + WHITE + s + WHITE +
s + WHITE + s + WHITE;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

return 0;
}

Code for 4 is

//******************************************************************
// Chessboard program
// This program prints a chessboard pattern that is built up from
// basic strings of white and black characters.
//******************************************************************

#include <iostream>
#include <string>

using namespace std;


const string BLACK = "$$$$$$$$"; // Define a line of a black square
const string WHITE = " "; // Define a line of a white square
const string s= "$ $";
int main ()
{
string whiteRow; // A row beginning with a white square
string blackRow; // A row beginning with a black square
string row2;
string row3;
// Create a white-black row by concatenating the basic strings
whiteRow = WHITE + BLACK + WHITE + BLACK +
WHITE + BLACK + WHITE + BLACK;
row2=WHITE + s + WHITE + s +
WHITE + s + WHITE + s;
// Create a black-white row by concatenating the basic strings
blackRow = BLACK + WHITE + BLACK + WHITE +
BLACK + WHITE + BLACK + WHITE;
row3=s + WHITE + s + WHITE +
s + WHITE + s + WHITE;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

// Print five white-black rows
cout << whiteRow << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << row2 << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << row3 << endl;
cout << blackRow << endl;

return 0;
}

The answer to this would be the difference in height and breadth of the $ sign so that's why the 8X5 seems to be square whereas 8X8 is not.