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;
}
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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.