forked from orazaro/accelerated
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-00.cpp
More file actions
40 lines (34 loc) · 979 Bytes
/
02-00.cpp
File metadata and controls
40 lines (34 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
using std::cout; using std::endl;
using std::cin;
int main()
{
cout << "Please enter your first name: ";
std::string name;
cin >> name;
const std::string greeting = "Hello, " + name + "!";
const int pad = 1;
const int rows = pad * 2 + 3;
const std::string::size_type cols = greeting.size() + pad * 2 + 2;
cout << endl;
// invariant: r rows written so far
for(int r = 0; r != rows; ++r) {
std::string::size_type c = 0;
// invariant: c columns written so far
while( c != cols) {
if(r == pad+1 && (int)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;
}
return 0;
}