Write a function that determines if two strings are anagrams. The function should not be case sensitive and should disregard any punctuation or spaces. Two strings are anagrams if the letters can be rearranged to form each other. For example, “Eleven plus two” is an anagram of “Twelve plus one.” Each string contains one “v”, three “e’s”, two “l’s”, etc. Test your function with several strings that are anagrams and non-anagrams. You may use either the string class or a C-style string.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Database Concepts (7th Edition)
Computer Science: An Overview (12th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting out with Visual C# (4th Edition)
Database Concepts (8th Edition)
- Write a function that replaces a substring with a new string. Example: >>> replace('The quick brown fox jumps over the lazy dog', 'quick', 'slow') The slow brown fox jumps over the lazy dog The first parameter is the string, second is the substring to be replaced and the third is the string to replace the substring. If there are more than one occurrence of a substring, replace it all.arrow_forwardWrite a function validate_date(date_string) which takes in a datestring and checks if the datestring is valid. If the string is valid, we want to return a tuple containing True and the date_string itself. If the string is invalid for a specific reason, we want to return a tuple containing False and the error code explaining what was wrong with the date string passed in. Below is the error codes for reasons why a string can be invalid (based on criteria on validity, read above): -1 --> date_string does not separate the day, month, and year with slashes. -2 --> day, month, or year are not numeric. -3 --> month out of range (not between 1 and 12) -4 --> day is out of range (not between 1 and last day of the month) For instance, if validate_date(date_string) is called with "01/12/2022" as the argument, the return value is (True, "01/12/2022") because "01/12/2022" is a valid string. If validate_date(date_string) is called with "01/44/2022" as the argument, the return value is…arrow_forwardWrite a function that converts a phrase into pig Latin. A word is convertedto pig Latin by removing the first character of the word, placing it at theback of the word, and adding the characters “ay” to the word. For example,“hello world” in pig Latin is “ellohay orldway.” Your function can assumethat each word consists of at least two letters and that each word is separatedby one space, with no punctuation marks.arrow_forward
- Write a function that receives 3 assignment grades, a1, a2, a3, and a final grade, f, for a student and returns the corresponding letter grade of the student. The weights for the assignments and the final are 0.2, 0.2, 0.2, and 0.4, respectively. You can use the following table for matching grades to letters: 95-100 -> A1 90-94 -> A2 85-89 -> A3 80-84 -> B1 75-79 -> B2 70-74 -> B3 65-69 -> C1 60-64 -> C2 55-59 -> C3 40-54 -> D 0-39 -> F For example, compute_letter(80, 60, 40, 70) returns "C2" because 80 * 0.2 + 50 * 0.2 + 40 * 0.2 + 70 * 0.4 = 62 and 62 corresponds to C2. Note that, you are expected to do rounding. For example, 39.4 is F, whereas 39.5 is D. You can use the builtin round() function for this. Please google this function and learn how to use it. """arrow_forwardTo translate a sentence into pig Latin, create a function. When a word is written in pig Latin, its first character is dropped, shifted to the word's tail, and the letters "ay" are added. For instance, "hello world" would be "ellohay orldway" in pig Latin. Your function can be written to assume that each word has at least two characters, is separated by a space, and is free of punctuation.arrow_forwardIn Kotlin, write a higher-order function with an expression body that takes an int n and a function f from int to int and returns the result of calling f(f(n)). For example if you call the function with n = -5 anda function that calculates absolute value, your function will return 5, and if you send the value 2 and a function that calculates the sqaure of an int, the function will return 16. in addition to the function, write the syntax to call it with:a. a function name as the function arguementb. some lambda expression as the function argumentarrow_forward
- please code in python Write a function that receives a string as an input and returns the most frequent letter from the given string. Your solution should be case insensitive, so a capital letter (like A) and its non-capital version (a) should be counted as the same letter. In the given string there can be spaces as well, but your solution shouldn’t count spaces. If there are multiple letters with the same occurrence, you can decide which one to return.arrow_forwardIn C, write a function that gets two ints a and b. If a>b the function returns a^3 + b^2, and otherwise it returns a^2 + b^3. int square_cube (int a, int b); For example: square_cube (1,2) should return 1 + 8 = 9. square_cube (10, 3) should return 1000 + 9 = 1009. square_cube (2, -1) should return 8 + 1 = 9. square_cube (-2, -1) should return 4 - 1 = 3.arrow_forwardWrite a function named sumDigits which takes three parameters: f, t and x. sumDigits, then, finds the smallest integer between f and t (both inclusive) whose sum of digits is x, and returns that integer.arrow_forward
- Before class, we'd like you to define a function that takes one string as input and returns the string repeated. For example, if the input is 'cat', the function should return 'catcat'. Hint: Be sure to read the pre-reading about defining functions! If your solution doesn't say def somewhere in it, you're not defining a function, but there's more to it than just saying def. Write a line of code that calls your function with the input 'cat' and assigns the result to a variable named repeated_strarrow_forwardWrite a function that counts and returns the number of vowels in the string. (For the purposes of this exercise, we are talking about the standard 5 vowels -- A, E, I, O, U). Write a function that counts and returns the number of consonants in the string. Write a function that converts the string to all lowercase. Write a function that converts the string to all uppercase. Write the following functions. Each of these functions should have a single parameter -- accepting a c-style string as an argument. The function should only do what is specified (note that none of these functions do any output to the screen). Your functions should use const in the prototype wherever it is appropriate: Write the main function that offers a menu and allows the user to test the functions you have implemented. Program C++, must use c- stylearrow_forwardWrite a function that takes in input as a string. For all characters which are numeric, double its value and, if it istwo digits, then replace it with the sum of its digits (e.g., 6 12 3 whereas 3 6). For all characters which arein uppercase, replace it with lowercase. For all characters which are in lowercase, replace it with (e.g.,m M and N n). The program should keep asking the user to enter strings until they either enter 'q' orarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning