Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. /*
  2. Program: ANewAlphabet.cpp
  3. Author: Piggy
  4. Program Information:
  5.   This program will replace normal letters of the alphabet with
  6.   new characters (can range from 1-6 chars per letter).
  7.  
  8. Algorithm Steps:
  9. 1. Ask user to input a string.
  10. 2. Convert string to lowercase so it is NOT caSe-SeNSiTiVe.
  11. 3. call checkDict() function which will compare all of the characters
  12.    in the string to those in the dictionary. Then will convert them to
  13.    their translated form and return those.
  14.   - Set up contents of unordered map in checkDict() function.
  15. 4. Output newly translated info.
  16. 5. Add assert() test cases (at least 3)
  17. 6. Review instructions to make sure I didn't forget anything.
  18.   - Also comment out cout << "Please input a string: "; etc..
  19. */
  20. #include <iostream>
  21. #include <string>
  22. #include <unordered_map>
  23. #include <algorithm> // for transform()
  24. #include <assert.h>
  25.  
  26. // Will only be using this for map related stuff because
  27. // I'm new to it and this makes it easier to learn.
  28. using namespace std;
  29.  
  30. void test();
  31. std::string transToLower(std::string uIn);
  32. std::string checkMap(std::string userInput);
  33.  
  34.  
  35. int main() {
  36.     // Declaring variables
  37.     std::string uInput, lowerUInput, result;
  38.    
  39.     // Automatically testing program:
  40.     test();
  41.  
  42.     // Asks for user input and stores information into uInput
  43.     std::cout << "Please input a string: ";
  44.     std::getline(std::cin, uInput);
  45.  
  46.     // Makes user input all lowercase so checkDict() works properly.
  47.     uInput = transToLower(uInput);
  48.     //std::cout << "[Debug] uInput = " << uInput << "\n";
  49.    
  50.     // Checks unordered_map for each character in string
  51.     // then returns translated values.
  52.     result = checkMap(uInput);
  53.    
  54.     // Outputs result
  55.     std::cout << result << "\n";
  56.  
  57.     return 0;
  58. }
  59.  
  60.  
  61. // Converts user input string to lowercase.
  62. std::string transToLower(std::string uIn) {
  63.     std::transform(uIn.begin(), uIn.end(), uIn.begin(), ::tolower);
  64.     return uIn;
  65. }
  66.  
  67.  
  68. // Checks dictionary for each character in string then returns translated values.
  69. std::string checkMap(std::string userInput) {
  70.     // Declares an unordered map of type <string, string> called stringMap.
  71.     // AKA <key in map, mapped value>. Example: {"a", "@"}
  72.     unordered_map<string, string> stringMap;
  73.    
  74.     const typedef unordered_map<string, string> stringMap;
  75.  
  76.     // unordered_map
  77.     stringMap { {"a", "@"}, {"b", "8"}, {"c", "("}, {"d", "|)"}, {"e", "3"}
  78.                 {"f", "#"}, {"g", "6"}, {"h", "[-]"}, {"i", "|"},
  79.                 {"j", "_|"}, {"k", "|<"}, {"l", "1"}, {"m", "[]\\/[]"},
  80.                 {"n", "[]\\[]"}, {"o", "0"}, {"p", "|D"}, {"q", "(,)"},
  81.                 {"r", "|Z"}, {"s", "$"}, {"t", "']['"}, {"u", "|_|"},
  82.                 {"v", "\\/"}, {"w", "\\/\\/"}, {"x", "}{"}, {"y", "`/"},
  83.                 {"z", "2"} };
  84.    
  85.  
  86.     /*
  87.     int inputSize = userInput.size();
  88.  
  89.     for (int i = 0; i < inputSize; i++) {
  90.         std::cout << dictionary.find(userInput[i])
  91.         //if (userInput[i] ==
  92.     }
  93.     */
  94.  
  95.     // Need to update the return once done
  96.     return "0";
  97. }
  98.  
  99.  
  100. void test() {
  101.     assert(transToLower("THIS is a TEST") == "this is a test");
  102.     //assert();
  103.     //assert();
  104.     //assert();
  105.  
  106.     std::cout << "All test cases passed! \n";
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement