From 8beb1bcf1f4620d7e8099b24ff42aea9ccfa02d2 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Sun, 21 Jun 2026 18:11:20 +0000 Subject: [PATCH] [Sync Iteration] cpp/beer-song/1 --- solutions/cpp/beer-song/1/beer_song.cpp | 51 +++++++++++++++++++++++++ solutions/cpp/beer-song/1/beer_song.h | 12 ++++++ 2 files changed, 63 insertions(+) create mode 100644 solutions/cpp/beer-song/1/beer_song.cpp create mode 100644 solutions/cpp/beer-song/1/beer_song.h diff --git a/solutions/cpp/beer-song/1/beer_song.cpp b/solutions/cpp/beer-song/1/beer_song.cpp new file mode 100644 index 0000000..27054dd --- /dev/null +++ b/solutions/cpp/beer-song/1/beer_song.cpp @@ -0,0 +1,51 @@ +#include "beer_song.h" +#include + +using namespace std; + +namespace beer_song { + + string verse(int number) { + ostringstream ss; + + switch (number) { + case 0: + ss << "No more bottles of beer on the wall, no more bottles of beer.\n" + << "Go to the store and buy some more, 99 bottles of beer on the wall.\n"; + break; + + case 1: + ss << "1 bottle of beer on the wall, 1 bottle of beer.\n" + << "Take it down and pass it around, no more bottles of beer on the wall.\n"; + break; + + case 2: + ss << "2 bottles of beer on the wall, 2 bottles of beer.\n" + << "Take one down and pass it around, 1 bottle of beer on the wall.\n"; + break; + + default: + ss << number << " bottles of beer on the wall, " << number << " bottles of beer.\n" + << "Take one down and pass it around, " << (number - 1) << " bottles of beer on the wall.\n"; + break; + } + + return ss.str(); + } + + string sing(int start, int end) { + ostringstream ss; + + // La canción siempre va en cuenta regresiva + for (int i = start; i >= end; --i) { + ss << verse(i); + // Salto de linea entre versos + if (i > end) { + ss << "\n"; + } + } + + return ss.str(); + } + +} \ No newline at end of file diff --git a/solutions/cpp/beer-song/1/beer_song.h b/solutions/cpp/beer-song/1/beer_song.h new file mode 100644 index 0000000..d45beb1 --- /dev/null +++ b/solutions/cpp/beer-song/1/beer_song.h @@ -0,0 +1,12 @@ +#pragma once +#include + +namespace beer_song { + + // Genera un único verso específico (de 0 a 99) + std::string verse(int number); + + // Genera una serie de versos desde un punto de inicio hasta un punto de fin + std::string sing(int start, int end = 0); + +} \ No newline at end of file