Concept explainers
The following function is supposed to take as arguments a length expressed in feet and inches and return the total number of inches in that many feet and inches. For example, total_inches(1,2) is supposed to return 14, because 1 foot and 2 inches is the same as 14 inches. Will the following function perform correctly? If not, why not?
double total_inches(int feet, int inches)
{
inches = 12 * feet + inches;
return inches;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Introduction To Programming Using Visual Basic (11th Edition)
Modern Database Management
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- An automated donation machine accepts donations via 10 or 20 bills to a maximum of $990. The machine needs to print a receipt with the donation amount in English, rather than numerically. Complete the following function which converts any number between 10 to 990 dollars to English.NOTE: You may define and use another function if necessary.NOTE: You should use arrays for this task. Use of switch statements or very long if/else if statements for printing is not allowed. However, using if/else if/else statements for the logic of your algorithm is permitted.NOTE: This function returns the result, and does not print it. Make sure the result is not lost when you return. Example function input and output (donation is 110):Input: 110Output: “one hundred ten dollars” string convertToEnglish (int donation); in C++ #include <iostream>#include <string>using namespace std; string convertToEnglish (int donation); int main() {int donation;cin>>donation;…arrow_forwardThe following formula can be used to determine the distance an object falls due to gravity in a specific time period: d = 1⁄2 gt2The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the time in seconds that the object has been falling. Write a function named fallingDistance that accepts an object’s falling time (in seconds) as an argument. The function should return the distance, in meters, that the object has fallen during that time interval. Write a program that demonstrates the function by calling it in a loop that passes the values 1 through 10 as arguments and displays the return value.arrow_forwardWhat is the return value of the given function below when the data passed to it is 4? int function(int x) { int y; } y=x++; return y; Select one: O a. 6 O b. 7 O c. 5 O d. 4arrow_forward
- C languagearrow_forwardWrite a function that asks the user for their birthday month and day and then the function should call a nested function to find out the person’s zodiac sign. Test your program with some user input. Aries: March 21 - April 19 Taurus: April 20 – May 20 Gemini: May 21- June 21 Cancer: June 22- July 22 Leo: July 23 – August 22 Virgo: August 23 – September 22 Libra: September 23 – October 23 Scorpio: October 24 – November 21 Sagittarius: November 22 – December 21 Capricorn: December 22 – January 19 Aquarius: January 20 – February 18 Pisces: February 19 – March 20arrow_forwardWrite a function that checks whether an integer is an even digit or an odd digit integer using the following header: int getType(int n)arrow_forward
- Problem 2: Write a function called digitMatch. The function has three integer parameters first , second and third that are positive and have the same number of digits. It returns the number of positions where their digits match. For example, if the function was applied to 17345, 97813 and 17313 it would return 1 because only the 2nd digits match. If parameters have illegal values your function can operate however you choose. For example, a program that uses the function follows. int main() { cout <« digitMatch(168, 567, 767) « endl; // prints 1 cout <« digitMatch(143, 243, 343) « endl; // prints 2 return 0; }arrow_forwardthat takes 3 integers as an input from the user and display them in ascending order (slai y ). For example, if the input is 2, 3 and 1, this program should display 1, 2 and Write program a 3. To resolve this problem, you should write 3 void functions: inputNumbers, sortNumber and displayNumbers. inputNumbers : the aim of this function to read 3 numbers from the user. sortNumber : the aim of this function to sort three numbers. displayNumbers : print the results. easy codearrow_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
- Given person_is_old(age) which returns True or False based on the incoming age as an integer. Write a function that uses the one mentioned above so that it prints “Go to work!” if the person is not old and “You deserved to have a long vacation” otherwise. Your function must also accept the age as its argument. My code def funct2(age): flag = old_person(age) if(flag): print("You deserved to have a long vacation") else: print("Go to work!")arrow_forwardWrite definitions for the following two functions:sumN (n) returns the sum of the first n natural numbers.sumNCubes (n) returns the sum of the cubes of the first n natural numbers.Then use these functions in a program that prompts a user for an n andprints out the sum of the first n natural numbers and the sum of the cubesof the first n natural numbers.arrow_forwardThis is the second lab for the Unit 4 zyBooks materials. Coding hints: def lapstomiles(user_laps): return user_laps / 4.00 #Please note that one mile is equal to four laps … print(f'{num_miles:.2f}') #We are formatting the laps into two decimal places. One lap around a standard high-school running track is exactly 0.25 miles. Define a function named laps_to_miles that takes a number of laps as a parameter, and returns the number of miles. Then, write a main program that takes a number of laps as an input, calls function laps_to_miles() to calculate the number of miles, and outputs the number of miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print(f'{your_value:.2f}') Ex: If the input is: 7.6 the output is: 1.90 Ex: If the input is: 2.2 the output is: 0.55 The program must define and call the following function:def laps_to_miles(user_laps) # Define your function here if __name__ == '__main__': user_laps =…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr