From 869e68986aa8f69af6e7842260a68d1e5c6f796f Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:24:20 +0200 Subject: Add a bunch of code Signed-off-by: Carlos Maiolino --- CPP/accel/greetings | Bin 0 -> 19656 bytes CPP/accel/greetings.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 CPP/accel/greetings create mode 100644 CPP/accel/greetings.cpp (limited to 'CPP/accel') diff --git a/CPP/accel/greetings b/CPP/accel/greetings new file mode 100755 index 0000000..003c6e8 Binary files /dev/null and b/CPP/accel/greetings differ 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 +#include + +#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; +} -- cgit v1.2.3