Advertisement
Guest User

Weird Case Generator

a guest
Jun 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. void print_headers();
  4. void print_exception();
  5. void print_functions(char c);
  6. void from_to(char c, char d);
  7. void print_main();
  8.  
  9. int main()
  10. {
  11.     print_headers();
  12.     std::printf("\n");
  13.     print_exception();
  14.     std::printf("\n");
  15.     for(char c = 'A'; c <= 'Z'; ++c)
  16.     {
  17.         print_functions(c);
  18.     }
  19.     print_main();
  20.     std::printf("\n");
  21. }
  22.  
  23. void print_headers()
  24. {
  25.     std::printf("#include <exception>\n"\
  26.                 "#include <string>\n"\
  27.                 "#include <iostream>\n");
  28. }
  29.  
  30. void print_exception()
  31. {
  32.     std::printf("struct WrongChar : public std::exception\n"\
  33.                 "{\n"\
  34.                 "    const char* what() const throw()\n"\
  35.                 "    {\n"\
  36.                 "        return \"Wrong input char\";\n"\
  37.                 "    }\n"\
  38.                 "};\n");
  39. }
  40.  
  41. void print_functions(char c)
  42. {
  43.     from_to(c, c + 32);
  44.     std::printf("\n");
  45.     from_to(c + 32, c);
  46.     std::printf("\n");
  47. }
  48.  
  49. void from_to(char c, char d)
  50. {
  51.     std::printf("char %c_to_%c(char c)\n"\
  52.                 "{\n"\
  53.                 "    if(c != '%c')\n"\
  54.                 "    {\n"\
  55.                 "        throw WrongChar();\n"\
  56.                 "    }\n"
  57.                 "    return '%c';\n"\
  58.                 "}\n", c, d, c, d);
  59. }
  60.  
  61. void print_main()
  62. {
  63.     std::printf(
  64.         "// std is just bloat\n"\
  65.         "using namespace std;\n"\
  66.         "int main(int count, char* values[])\n"\
  67.         "{\n"\
  68.         "    // it is easier to work with c++ string then c string\n"\
  69.         "    string text;\n"\
  70.         "    int counter = 0;\n"\
  71.         "    while(values[counter] != 0)\n"\
  72.         "    {\n"\
  73.         "        text = text = values[counter];\n"\
  74.         "        counter = counter + 1;\n"\
  75.         "    }\n"\
  76.         "\n"\
  77.         "    counter = 0;\n"\
  78.         "    bool make_small = true;\n"\
  79.         "    bool make_big = false;\n"\
  80.         "\n"\
  81.         "    while(text[counter] != 0)\n"\
  82.         "    {\n"
  83.         "        if(make_small == true && make_big == false)\n"\
  84.         "        {\n"
  85.     );
  86.  
  87.     for(char c = 'A'; c <= 'Z'; ++c)
  88.     {
  89.         std::printf(
  90.         "            try\n"\
  91.         "            {\n"\
  92.         "                char c;\n"\
  93.         "                c = %c_to_%c(text[counter]);\n"\
  94.         "                text[counter] = c;\n"\
  95.         "            }\n"\
  96.         "            catch(...)\n"\
  97.         "            {\n"\
  98.         "            }\n\n", c, c + 32);
  99.     }
  100.  
  101.     std::printf(
  102.         "            make_small = false;\n"\
  103.         "            make_big = true;\n"\
  104.         "        }\n"\
  105.         "        else if(make_small == false && make_big == true)\n"\
  106.         "        {\n"
  107.     );
  108.  
  109.     for(char c = 'A'; c <= 'Z'; ++c)
  110.     {
  111.         std::printf(
  112.         "            try\n"\
  113.         "            {\n"\
  114.         "                char c;\n"\
  115.         "                c = %c_to_%c(text[counter]);\n"\
  116.         "                text[counter] = c;\n"\
  117.         "            }\n"\
  118.         "            catch(...)\n"\
  119.         "            {\n"\
  120.         "            }\n\n", c + 32, c);
  121.     }
  122.  
  123.     std::printf(
  124.         "            make_small = true;\n"\
  125.         "            make_big = false;\n"\
  126.         "        }\n"
  127.     );
  128.  
  129.     std::printf(
  130.         "        counter = counter + 1;\n"\
  131.         "    }\n"\
  132.         "\n"\
  133.         "    cout << text << endl;\n"\
  134.         "\n"\
  135.         "    return 0;\n"\
  136.         "}\n"
  137.     );
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement