Very new need an explanation

Very new need an explanation

1
2
3
4
5
6
7
8
9
	
// the number of blanks surrounding the greeting
	const int pad = 1;
	
// the number of rows and columns to write
	const int rows = pad * 2 + 3;
	
const string::size_type cols = greeting.size() + pad*2+2;
	


We begin by observing that all the output lines are the same length. If we think of the output
as a rectangular array, then that length is the number of columns in the array. We can compute that number by adding twice the padding to the length of the greeting, and then adding two for the asterisks at the ends:


The out put is

********************
* *
* Hello, Estragon! *
* *
********************

I don't understand why she double The amount of blanks then add'd 2. the out put is only 1 column then the *. and removing the numbers still gives me a * and a blank column on the left side.


1,2 3,4
****************
* *
* Hello, Estragon! *
* *
****************

Is what I thought but changing that number still leaves the other ones on the left side. and how is knowing to divide them equally? I guess I just need a further explanation of the math behind it.

The spacing doesn't work on forums but there's 1 space and then one astreik between the start and end of the greeting. so 2 on one side 2 on the other for a total of 4.
Last edited on
For rows you multiply by 2 since you will need the padding on the top and the bottom then add 3 so that way there is an empty line between the padding and the message on the top and bottom. For columns you want the size of the message then add the padding * 2 again for left/right then add 2 for the space on the left and the right.


********************
*                  *
* Hello, Estragon! *
*                  *
********************


If the padding was 2 it would be something like


**********************
**********************
**                  **
** Hello, Estragon! **
**                  **
**********************
**********************


unless they mean by padding just the spaces/empty lines between the border and the message it would be something like:

**********************
*                    *
*                    *
*  Hello, Estragon!  *
*                    *
*                    *
**********************
Last edited on
Topic archived. No new replies allowed.