Last active
January 8, 2019 18:19
-
-
Save RealKC/f522238ce852e70a5fcb263fc041aa91 to your computer and use it in GitHub Desktop.
A simple C++ console app that will make any given string into a box.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
* Version 2, December 2004 | |
* | |
* Copyright (C) 2018 Mitca Dumitru | |
* | |
* Everyone is permitted to copy and distribute verbatim or modified | |
* copies of this license document, and changing it is allowed as long | |
* as the name is changed. | |
* | |
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
* | |
* 0. You just DO WHAT THE FUCK YOU WANT TO. | |
*/ | |
#include <cctype> | |
#include <iostream> | |
#include <fstream> | |
enum class line : int { | |
hor = 1, | |
hor_rev = 2, | |
ver = 3, | |
}; | |
std::string makeLine(std::string& strIn, line l, int spaces = 0) { | |
std::string line_ret; | |
switch(l) { | |
case line::hor: { | |
for(size_t i = 0; i < strIn.length(); i++) { | |
line_ret.push_back(toupper(strIn[i])); | |
line_ret.push_back(' '); | |
} | |
line_ret.push_back('\n'); | |
return line_ret; | |
} | |
case line::hor_rev: { | |
for(int i = strIn.length() - 1; i >= 0; i--) { | |
line_ret.push_back(toupper(strIn[i])); | |
line_ret.push_back(' '); | |
} | |
line_ret.push_back('\n'); | |
return line_ret; | |
} | |
case line::ver: { | |
//We'll handle both the vertical cases on a single case | |
std::string emptySpace(spaces, ' '); | |
size_t i = 1, j = strIn.length() - 2; // we skip the first and last characters | |
//as those should be in the bottom and up lines | |
for(size_t k = 0; k < strIn.length()-2; i++, j--, k++) { | |
line_ret.push_back(toupper(strIn[i])); | |
line_ret += emptySpace; | |
line_ret.push_back(toupper(strIn[j])); | |
line_ret.push_back('\n'); | |
} | |
return line_ret; | |
} | |
default: | |
//This is exceptional because someone had to specificall write static_cast<line>(somebadint) | |
//or a similar cast | |
throw std::invalid_argument("You fucked up the \' line l \' argument, gj"); | |
} | |
} | |
std::string makeBox(std::string strIn) | |
{ | |
std::string box = makeLine(strIn, line::hor) | |
+ makeLine(strIn, line::ver, 2 * strIn.length() - 3) | |
+ makeLine(strIn, line::hor_rev) | |
; | |
return box; | |
} | |
void boxify() | |
{ | |
std::cout << "Please input the string you'd like to see as a box: "; | |
std::string toBox, firstLine, box; | |
std::getline(std::cin, toBox); | |
if(toBox.length() <= 1) { std::cout << "You can't make a box out of one character!"; } | |
else { std::cout<<"Your box is:\n" << makeBox(toBox); } | |
} | |
int main() | |
{ | |
boxify(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment