Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Program: ANewAlphabet.cpp
- Author: Piggy
- Program Information:
- This program will replace normal letters of the alphabet with
- new characters (can range from 1-6 chars per letter).
- Algorithm Steps:
- 1. Ask user to input a string.
- 2. Convert string to lowercase so it is NOT caSe-SeNSiTiVe.
- 3. call checkDict() function which will compare all of the characters
- in the string to those in the dictionary. Then will convert them to
- their translated form and return those.
- - Set up contents of unordered map in checkDict() function.
- 4. Output newly translated info.
- 5. Add assert() test cases (at least 3)
- 6. Review instructions to make sure I didn't forget anything.
- - Also comment out cout << "Please input a string: "; etc..
- */
- #include <iostream>
- #include <string>
- #include <unordered_map>
- #include <algorithm> // for transform()
- #include <assert.h>
- // Will only be using this for map related stuff because
- // I'm new to it and this makes it easier to learn.
- using namespace std;
- void test();
- std::string transToLower(std::string uIn);
- std::string checkMap(std::string userInput);
- int main() {
- // Declaring variables
- std::string uInput, lowerUInput, result;
- // Automatically testing program:
- test();
- // Asks for user input and stores information into uInput
- std::cout << "Please input a string: ";
- std::getline(std::cin, uInput);
- // Makes user input all lowercase so checkDict() works properly.
- uInput = transToLower(uInput);
- //std::cout << "[Debug] uInput = " << uInput << "\n";
- // Checks unordered_map for each character in string
- // then returns translated values.
- result = checkMap(uInput);
- // Outputs result
- std::cout << result << "\n";
- return 0;
- }
- // Converts user input string to lowercase.
- std::string transToLower(std::string uIn) {
- std::transform(uIn.begin(), uIn.end(), uIn.begin(), ::tolower);
- return uIn;
- }
- // Checks dictionary for each character in string then returns translated values.
- std::string checkMap(std::string userInput) {
- // Declares an unordered map of type <string, string> called stringMap.
- // AKA <key in map, mapped value>. Example: {"a", "@"}
- unordered_map<string, string> stringMap;
- const typedef unordered_map<string, string> stringMap;
- // unordered_map
- stringMap { {"a", "@"}, {"b", "8"}, {"c", "("}, {"d", "|)"}, {"e", "3"}
- {"f", "#"}, {"g", "6"}, {"h", "[-]"}, {"i", "|"},
- {"j", "_|"}, {"k", "|<"}, {"l", "1"}, {"m", "[]\\/[]"},
- {"n", "[]\\[]"}, {"o", "0"}, {"p", "|D"}, {"q", "(,)"},
- {"r", "|Z"}, {"s", "$"}, {"t", "']['"}, {"u", "|_|"},
- {"v", "\\/"}, {"w", "\\/\\/"}, {"x", "}{"}, {"y", "`/"},
- {"z", "2"} };
- /*
- int inputSize = userInput.size();
- for (int i = 0; i < inputSize; i++) {
- std::cout << dictionary.find(userInput[i])
- //if (userInput[i] ==
- }
- */
- // Need to update the return once done
- return "0";
- }
- void test() {
- assert(transToLower("THIS is a TEST") == "this is a test");
- //assert();
- //assert();
- //assert();
- std::cout << "All test cases passed! \n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement