summaryrefslogtreecommitdiff
path: root/CPP/accel/greetings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/accel/greetings.cpp')
-rw-r--r--CPP/accel/greetings.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/CPP/accel/greetings.cpp b/CPP/accel/greetings.cpp
new file mode 100644
index 0000000..d916d87
--- /dev/null
+++ b/CPP/accel/greetings.cpp
@@ -0,0 +1,51 @@
+#include <iostream>
+#include <string>
+
+#define PADDING 1
+
+using std::cin;
+using std::cout;
+using std::endl;
+using std::string;
+
+int main(void) {
+ string name;
+
+ const int pad = PADDING;
+ const int rows = pad * 2 + 3 ; // * 2 blanks + (greeting+borders)
+
+ cout << "Type your name: ";
+ cin >> name;
+
+ // Build the message to write
+ const string greeting = "Hello, " + name + "!";
+
+ // pad * 2 blank borders + 2 * edges
+ const string::size_type cols = greeting.size() + pad * 2 + 2;
+
+ cout << std::endl;
+
+ // Write 'rows' rows of output
+ // invariant: we have written 'r' rows
+ 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 << std::endl;
+ }
+
+ return 0;
+}