Write a function named convertToLowestTerms that inputs two integer parameters by reference named numerator and denominator. The function should treat these variables as a fraction and reduce them to lowest terms. For example, if numerator is 20 and denominator is 60, then the function should change the variables to 1 and 3, respectively. This will require finding the greatest common divisor for the numerator and denominator then dividing both variables by that number. If the denominator is zero, the function should return false, otherwise the function should return true. Write a test
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Absolute C++, Student Value Edition, 6/e
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting out with Visual C# (4th Edition)
C Programming Language
C How to Program (8th Edition)
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
- in Java script: // Write a standard function definition that takes 1 parameter. The parameter is a number and the function should return the sum of that number and all of the numbers greater than 0 below it. Example - if it was 3, it should add 3, to 1 + 2 because those are all of the numbers between 0 and 3. Therefore it should return 6. // EXAMPLE: // console.log(sum(4));// should give you the following output in your console...// 10arrow_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_forwardWrite a program in python that prints a pyramid made of letters in the middle of the screen. Use functions with parameters for this assignment. The base width of the pyramid is determined by a character the user enters. If the user enters the letter o, the following pyramid will be printed. It can be assumed that the screen width is 80 characters. a aba abcba abcdcba abcdedcba abcdefedcba abcdefgfedcba abcdefghgfedcba…arrow_forward
- Write a function called extractor() that takes a name as a parameter and counts every vowel present in it. The function should also identify and contact the consonants in another string. Finally, RETURN the total number of total vowels present in the name and the consonant string.Note: The name could be a mixture of uppercase & lowercase letters.Sample Input 1:MuhaiminulFunction call 1:extractor("Muhaiminul")Sample Output 1:(5, 'mhmnl')Explanation 1:Here, in the given name, we have 5 vowels (uaiiu). That's why 5 in the output. 'mhmnl' are the consonants present in the name.Sample Input 2:iLiyanaFunction call 2:extractor("iLiyana")Sample Output 2:(4, 'lyn')Explanation 2:Here, in the given name, we have 4 vowels (iiaa). That's why 4 in the output. 'lyn' are the consonants present in the name.arrow_forwardWrite a function, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed. For example, reverseDigit(12345) returns 54321, reverseDigit(2300) returns 32, and reverseDigit(-324) returns -423.arrow_forwardWrite a function called cap_ends() that takes a string parameter called sentence as the input parameter. This parameter may contain any number of words (one or more letters separated by spaces) and the following three punctuation marks '!' ';' '.' . For example, sentence = "here are some words." or another_sentence = "wow!" Your function must extract each word from the sentence, remove the punctuation marks if there is any, and make the first and the last letters of that word uppercase. For example, "here" will be "HerE", "some" will be "SomE", "wow" will be "WoW" etc. Finally, your function must return a dictionary, where keys of this dictionary are the words of the sentence capitalized as above. For each key (i.e., word) the value should be the length of that word. You are not allowed to use the built-in string.title() method or any negative indexing. You may use any other string methods in your solution. Sample outputs: >>> d = cap_ends("here are some words.")…arrow_forward
- Write a function, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverseDigit(12345) is 54321; the value of reverseDigit(5600) is 65; the value of reverseDigit(7008) is 8007; and the value of reverseDigit(-532) is -235.arrow_forwardIn python Write a function max_magnitude() with two integer input parameters that returns the largest magnitude value. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value. Ex: If the inputs are: 5 7 the function returns: 7 Ex: If the inputs are: -8 -2 the function returns: -8 Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the built-in absolute value function to determine the max magnitude, but you must still output the input number (Ex: Output -8, not 8). Your program must define and call the following function:def max_magnitude(user_val1, user_val2)arrow_forwardWrite a program that calculates the area (a) of a triangle given two values b (base) and h (height) and using the formula area = (base * height) / 2 .The program should include a function called calculate_area which has two input parameters(b and h) and one output parameter (a).The user is prompted to enter two input values that will be used as base (b) and height (h) thenthe function calculate_area uses those two values as input parameters returns the calculatedarea (a) as an output parameter. After using the function calculate_area the program shoulddisplay the calculated area (a).Hint: use a pointer for the output parametearrow_forward
- ***python only*** Write a function votes_by_race() which takes a list of dicts as a parameter and returns a dict. For example, given the following list: votes = [{'for': 'A, 'age': 35, 'race': 'w'}, {'for': 'B', 'age': 40, 'race': 'b'}, {'for': 'B', 'age': 20, 'race': 'b'}, {'for': 'A', 'age': 30, 'race': 'a'}, {'for': 'A', 'age': 41, 'race': 'w'}, ] The call votes_by_race(votes) should return the following dict:{"White": 2, 'Black': 2, 'Asian': 1, "Hispanic': 0}arrow_forwardWrite a C++ console application to find out a number is prime or non-prime. According to mathematics: “A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself”. You should define a function which takes an integer as a parameter and returns it as a prime or not. Sample input: 13 Output: Prime 27 Output: Non- primearrow_forward2. David is used to doing programming in Python and since the print() function in Python by default prints a newline after printing the string passed to the print() function. But in his current project, he is using PHP programming language and the echo function does not print a newline by default after the end of the string. So, he often misses giving a newline after printing a message. Help David by writing a function myecho() that takes a string as a parameter and also prints a newline after printing the string.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning