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
Software Engineering (10th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Starting Out With Visual Basic (7th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Concepts Of Programming Languages
- If a year has the digit 7 OR the digit 4 in it, then it is called a “Beautiful year”. For example, 2017, 2014, and 2072 are all beautiful years. If the year has BOTH 4 and 7 in it, then it's an “Amazing year”. For example, the years 2047 and 2074 are amazing years. All other years are “Ugly years”. You need to write a function that takes a year as an argument and return it's type. Then, finally print the returned values in the function call. ================================================ Sample Function Call 1: function_name(2470) Sample Output 1: Amazing year ================================================ Sample Function Call 2: function_name(2170) Sample Output 2: Beautiful year ================================================ Sample Function Call 3: function_name(2021) Sample Output 3: Ugly yeararrow_forwardGiven the following: printf ( “Enter your age in years: “ ); scanf ( “%d”, &age_in_years ); int is_voting_age = ( age_in_years >= 18 ); int is_drinking_age = ( age_in_years >= 21 ); int can_be_president = ( age_in_years >= 35 ); int is_senior_citizen = ( age_in_years >= 65 ); When the age entered is 33, what are the values of the variables above? When the age entered is 12, what are the values of the variables above? Write an IF statement in a function to print ‘Yes’ for each value above that is true.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
- If a function is supposed to just display a message, which is more appropriate to use--a value-returning function or a void function?explain pleasearrow_forwardPlease answer it in Python Write an average function that takes as an argument two notes, as well as an optional argument called bonus and whose default value is 0. The function must return the average of the student calculated as follows: first, we calculate the "normal" average between the two grades, then we add the bonus. Be careful, the average returned should not exceed 20, even if the calculation explained above gives a number strictly greater than 20. Examples:average(12,14) is 13.0 average (12,14,1) is 14.0 (because 13 + 1)average(18,19,2) is 20arrow_forwardWrite a function number_of_pennies() that returns the total number of pennies given a number of dollars and (optionally) a number of pennies.input: 5 6 4 Output: 506 400 My Code: def number_of_pennies(dollars=0, pennies=0): numer_of_pennies = (dollars * 100) + pennies return number_of_pennies print(number_of_pennies(int(input()), int(input()))) # Both dollars and penniesprint(number_of_pennies(int(input()))) # Dollars only However, this is the output that I am getting: <function number_of_pennies at 0x7f6a5e1d7e50> <function number_of_pennies at 0x7f6a5e1d7e50>arrow_forward
- This is what I have so far 1. Too many arguments. #include <stdio.h> Void simple(); Int main() { Int n; simple(1,2,3,4,5,6,7,8,9,10,11,12); Return0; } Void simple(int n){ printf(“%d”,n); } What does this do? This code prints the first argument passed to the simple function called. That is (1). Does the extra argument break the code? No, the extra argument does not break the code as the remaining argument are ignored by the function. Which argument(s) gets printed? The arguments are printed in the order they are called in the function. Here, the argument to be passed first is 1 and that is printed. The first argument is printed. Why? This is because the remaining arguments are evaluated by the function and then ignored. 2. Too few parameters #include <stdio.h> Void simple(); Int main() { Int n; simple(1,2,3,4,5,6,7,8,9,10,11,12); Return0; } Void simple(int n){ printf(“%d”,n); printf(%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d) } What…arrow_forwardThis is what I have so far 1. Too many arguments. #include <stdio.h> Void simple(); Int main() { Int n; simple(1,2,3,4,5,6,7,8,9,10,11,12); Return0; } Void simple(int n){ printf(“%d”,n); } What does this do? This code prints the first argument passed to the simple function called. That is (1). Does the extra argument break the code? No, the extra argument does not break the code as the remaining argument are ignored by the function. Which argument(s) gets printed? The arguments are printed in the order they are called in the function. Here, the argument to be passed first is 1 and that is printed. The first argument is printed. Why? This is because the remaining arguments are evaluated by the function and then ignored. 2. Too few parametersarrow_forward(Wattan Corporation) is an Internet service provider that charges customers a flat rate of $7.99 for up to 10 hours of connection time. Additional hours or partial hours are charged at $1.99 each.Write a function charges that computes the total charge for a customer based on the number of hours of connection time used in a month. The function should also calculate the average cost per hour of the time used (rounded to the nearest 0.01), so use two output parameters to send back these results.You should write a second functionround_money that takes a real number as an input argument and returns as the function value the number rounded to two decimal places. Write a main function that takes data from an input file usage.txt and produces an output file charges.txt. The data file format is as follows:Line 1: current month and year as two integersOther lines: customer number (a five-digit number) and number of hours usedHere is a sample data file and the corresponding output file:Data file…arrow_forward
- (Wattan Corporation) is an Internet service provider that charges customers a flat rate of $7.99 for up to 10 hours of connection time. Additional hours or partial hours are charged at $1.99 each. Write a function charges that computes the total charge for a customer based on the number of hours of connection time used in a month. The function should also calculate the average cost per hour of the time used (rounded to the nearest 0.01), so use two output parameters to send back these results. You should write a second function round_money that takes a real number as an input argument and returns as the function value the number rounded to two decimal places. Write a main function that takes data from an input file usage.txt and produces an output file charges.txt. The data file format is as follows: Line 1: current month and year as two integers Other lines: customer number (a five-digit number) and number of hours used Here is a sample data file and the corresponding output file:…arrow_forward(Wattan Corporation) is an Internet service provider that charges customers a flat rate of $7.99 for up to 10 hours of connection time. Additional hours or partial hours are charged at $1.99 each. Write a function charges that computes the total charge for a customer based on the number of hours of connection time used in a month. The function should also calculate the average cost per hour of the time used (rounded to the nearest 0.01), so use two output parameters to send back these results. You should write a second function round_money that takes a real number as an input argument and returns as the function value the number rounded to two decimal places. Write a main function that takes data from an input file usage.txt and produces an output file charges.txt. The data file format is as follows: Line 1: current month and year as two integers Other lines: customer number (a five-digit number) and number of hours used Here is a sample data file and the corresponding output file:…arrow_forwardWrite a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is: 0 or less, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2 dimes Your program must define and call the following function:void ExactChange(double userTotal, int& numDollars, int& numQuarters, int& numDimes, int& numNickels, int& numPennies)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education