Can anyone please tell me the difference between the output of the two codes?
FIRST Code:
SECOND Code:
FIRST Code:
| Code: |
| void Example1Chap2V1()
{ cout << "Please enter your first name: "; string name; cin >> name; cout << endl; const string greetings = "Hello " + name + "!"; const int pad = 1; const int rows = pad*2 + 3; const string::size_type cols = greetings.size() + pad*2 + 2; for(int r = 0; r < rows; ++r) { string::size_type c = 0; while(c != cols) { if((r == pad + 1) && (c == pad + 1)) { cout << greetings; c += greetings.size(); } else { if((r == 0) || (r == rows - 1) || (c == 0) || (c == cols - 1) ) { cout << "*"; } else { cout << " "; } ++c; } } cout << endl; } } |
SECOND Code:
| Code: |
| void Example1Chap2V2()
{ cout << "Please enter your first name: "; string name; cin >> name; const string greeting = "Hello, " + name + "!"; const int pad = 1; const int rows = pad * 2 + 3; const string::size_type cols = greeting.size() + pad * 2 + 2; cout << endl; for(int r = 0; r != rows; ++r) { string::size_type c = 0; while(c != cols) { if(r == pad + 1 && c == pad + 1) { cout << greeting; c += greeting.size(); } else { if(r == 0 || r == rows - 1 || c == 0 || c == cols - 1) { cout << "*"; } else cout << " "; ++c; } } cout << endl; } } |
