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++
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
SURVEY OF OPERATING SYSTEMS
Concepts Of Programming Languages
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Mechanics of Materials (10th Edition)
- Write a program that generates random numbers between -25 and 25 by using the randint function. The program will add up the numbers and terminate when the sum of the values becomes zero. The program should contain the following functions: add() : add up the values main(): the function where the program execution should begin and end. randomgen(): a function that returns a number between -25 and 25 A global variable subsetsum that keeps track of the sum The program should output the count of the number of values generated before exiting saying that the subset sum was zero.arrow_forwardWrite a function count_evens() that has four integer parameters, and returns the count of parameters where the value is an even number (i.e. evenly divisible by 2). Ex: If the four parameters are: 1 22 11 40 then the returned count will be: 2 Hint: Use the modulo operator % to determine if each number is even or odd. Your program must define the function:count_evens(num1, num2, num3, num4) python # Define your function here if __name__ == '__main__': num1 = int(input()) num2 = int(input()) num3 = int(input()) num4 = int(input()) result = count_evens(num1, num2, num3, num4) print('Total evens:', result)arrow_forwardImplement a function named get_player_selection. This function has parameters for the players number (which will be either 1 or 2), and the number of sticks remaining on the board. For this function you will need to do the following: Use the input function to get the player to type in their selection. Validate the user’s input, printing out a message if they enter an invalid number and continually prompting them until they do enter a valid number. The user may enter any number between 1 and 3, unless there are fewer than 3 sticks remaining, in which case they can only enter between 1 and the number of sticks remaining. As in the example, the input prompt should list the valid range of numbers. Return the (validated) number as an integer (not a string). You should test that this function works by running it in the REPL. Make sure you try different scenarios, like the user entering an invalid number multiple times in a row. After you are done testing and fixing any errors you find,…arrow_forward
- A prime number is an integer value that is only divisible by 1 and itself. 2, 3, 5, 7, and 11 are examples of prime numbers. You have been provided with two function definitions: The is_prime () function takes an integer parameter number, and returns True if number is prime and False otherwise. The get_next_prime () function also takes a single integer parameter number, and returns the first prime number larger than it. You must not change the implementation of these 2 functions. Complete the get_primes_list() function that takes a single list of integers called numbers as parameter. You can assume that the integer items in this list will be non-negative. The function must update this list so that items that are not prime numbers are updated to the first prime number larger than them. To implement this function you must call both the is_prime () and get_next_prime () functions. Some examples of the function being called are shown below. Note: the get_primes_list() function does not…arrow_forwardWrite a function findFirstUpper() that takes a string as parameter, finds returns the index of the first uppercase letter in the string. If there is no uppercase letter in the string, then the function will return -1.Example: Function call findFirstUpper("best course is CS104!") will return 15 (index of the 'C').Example: Function call findFirstUpper("good morning!") will return -1 CODEE:PYTHONarrow_forwardWrite a function findFirstUpper() that takes a string as parameter, finds returns the index of the first uppercase letter in the string. If there is no uppercase letter in the string, then the function will return -1.Example: Function call findFirstUpper("best course is CS104!") will return 15 (index of the 'C').Example: Function call findFirstUpper("good morning!") will return -1. CODEEE:PYTHON PLEASEarrow_forward
- Some of the earliest computer games developed were Interactive Fiction games, in which the user’s environment is described in text, and the user makes choices using text commands. In this problem and the next one, we’ll be developing a very simple text-based adventure game. Every choice in this game will have exactly three options, so we can write a function that works for any of them. Write a function selection(text, optionA, optionB, optionC), that takes in four string values. text is a string representing a prompt in a text adventure game, and optionA, optionB, and optionC are strings representing the three possible options. The function should print out the text, and then print out the options (label them with A., B., and C.). Next, the input() function should be used to prompt the user to choose A, B, or C. Then the function should return (not print) the one character string that represents the user’s choice: 'A', 'B', or 'C'. If the user does not choose one of those…arrow_forwardpython Define stubs for the functions get_user_num() and compute_avg(). Each stub should print "FIXME: Finish function_name()" followed by a newline, and should return -1. Each stub must also contain the function's parameters.Sample output with two calls to get_user_num() and one call to compute_avg():FIXME: Finish get_user_num() FIXME: Finish get_user_num() FIXME: Finish compute_avg() Avg: -1 i keep getting errors on this onearrow_forwardWrite the convert_word code. convert_word is known as a function, which we will cover more in depth later. You are automatically given a parameter called word, which is a string that contains a single word. The return conv is how you will send data out of your function. The conv is a variable that hasn't been created yet, but it will be a string containing the converted hey. For example, if word="hey", then conv will be "heey". You are responsible for creating the variable conv, as the template has NOT done that for you. You need to use an if statement to see if the word starts with "he" and ends with "y". Since you don't know how many e's might be between the he and y, you have to do some math here. Recall that you can get the length of a string by using len(word) in the code above. You also know that h and y will be included. so, len(word) - 2 will be the number of e's in between the h and y. Create a string that contains the number of e's. This will be your conv variable. I would…arrow_forward
- Write a program that calculates the area of a 2D geometric shape. The program will read three values: first one is the shape's name (shapeName) as a char, second and third values are the dimensions of the shape (dimensionA, dimensionB) as two doubles. Then, your program MUST use a function named "getArea" to calculate the area of the given shape. The function will take 3 parameters, first parameter will be a char containing the first letter of the shape's name, second and third parameters will be doubles containing dimensions of the shape (i.e. radiuses of an ellipse or base and height lengths of a rectangle or triangle). The function should return the area of the shape as a double. After calling the function, your program should print out the area of the given shape as a double value. NOTE: For the area of ellipse, assume pi = 3.14. NOTE: shapeName van ONLY be 'E', T', or 'R', meaning ellipse, rectangle and triangle respectively. HINT: a h b Area - (b*h)2 Area = b*h Area = A xa×b…arrow_forwardgood stat ofl them ii days. You need to upload your solutions in a single python file (assl.py) to the link on MS Teams. Part 1 Add this comment: # Ass 1: Part 1 Write a program that declares a function called draw Star which receives an integer value as a parameter, and draws a number of stars equal to the received integer. Samplel: Please enter the number of stars: 5 The shape is: **** Sample2: Please enter the number of stars: 3 The shape 15 *** Part 2 Add this comment: Ass 1: Part 2 Write a program that summation of even ni "nd M then prints the 3.9 nclud d if were even of 3arrow_forwardComplete the function quarts_to_liters() that has one parameter as a volume in quarts. The function returns the volume converted to liters, given that 1 quart = 0.946353 liters. Ex: If the input is 69, then the output is: The number of liters is 65.298arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr