Function name: quick_maths()
Parameters: a number (float), a number (float), an operation (string)
Returns: a float
Description: You’re trying to do your math homework, and you realized that you can
write a program to do all the simple operations! The five possible operations are “+”, “-”,
“*”, “/”, and “%”. Based on the operation that is passed in, perform the operation on the
two numerical parameters. The first parameter should always go first in the operation.
Return the result of the operation rounded to two decimal places. If the operation is not
one of the five listed above, return “That operation does not exist!”
Since you have not mentioned the language of your preference, I am providing the code in C++.
CODE
===============
string quick_maths(float a, float b, string operation) {
float result = 0;
switch(operation[0]) {
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
if (b != 0) {
result = a / b;
}
break;
case '%':
result = a - b;
break;
default:
return "That operation does not exist!";
}
return to_string(result);
}
Function name: quick_maths() Parameters: a number (float), a number (float), an operation (string) Returns: a float...
Function name : contains_substring Parameters : string (string), substring (string) Returns: bool Description : If the substring is entirely contained within the string, then return True, otherwise return False. An empty substring will always return False. The substring may be longer than the string. You are not allowed to just write “if substring in string”.
Function name : give_fortune() Parameters : mood (a string), age (int), name (string), year in school (int) Returns: a fortune (string) Description : Now that you have your magic number, the fortune teller is going to tell you your fortune! Call the magic_ball() function using the age, name, and year in school parameters given in give_fortune(). Based on the fortune teller’s mood and the magic number, you will return a fortune. If the mood is “happy” and the magic number...
help ASAP
3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...
Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that takes an input string, and returns a the unscrambled version of the argument. To unscramble the string: When the string has an odd number of characters, middle character is the first character in the unscrambled result Pairs of remaining characters are added to the result, proceeding left to right from inner-most to outer-most characters. Example Call: unscramble('3cis1') Expected result: ics31 Example Call: unscramble('ocicssol') Expected...
USE PYTHON / RECURSION METHOD
Fibonacci Dictionary Function Name: fibtionary Parameters: num (int) Returns: dictionary (key: int, value: int) Description: You're done with stats, but you still have other math homework to go! You're currently learning about the Fibonacci sequence in math class. The Fibonacci sequence is a series of numbers in the pattern 112 3 5 8 13 21 ..., where the next number is found by adding up the two numbers before it. Write a function that takes...
Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...
python: def functionSolver(function: callable)->str You will be given a function as a parameter, the function you are given only accepts two number parameters and produces a float value. It is your job to figure out what mathematical operation the function you are given is performing by passing it many different parameters. The possible operations the function can perform are: add, subtract, multiply, and divide. The given function will only perform a single operation, it will not change after consecutive invocations....
Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...
C++ Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a...
Function name: triangular Parameters: integer Returns: a list Description: Write a function called triangular that accepts one integer parameter that returns a list with the same number of terms as the value of the parameter. If the parameter is zero or a negative number, you should return an empty list A triangular number is the sum of a positive integer and all the integers before it. The series is as follows: 1, 3, 6, 10, 15, 21,