Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 3, Problem 14PP
Put this algorithm into a function and test it by using it to calculate the square root of several numbers. The function should return the square root as a double and also process the number n as a double.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Apply your knowledge about arrays and functions and write a program, which takes a positive integer
N from user, and prints the multiplication table of the size N by N. For Example, if the user enters 10
then your program should display the following table. Note: your program should have a function
naming "Multiplication" which should take size N as input argument. Output should be in this
format.
1 2 3 4 5 6 7 8 9 10
71
81
91
10 I
1 I
21
31
4 1
4
51
5
61 6 12
7
8 16 24
1
123
2
3
4 5
6 7
8 9
8 10 12
14
16
18
12 15 18
21 24 27
16
20
32
36
20
25
30 35 40
45
18 24 30
36
42
48
54
35
42 49 56
63 70
32 40 48
56
64
72
80
36
45
54
63 72 81
90
20 30 40
50
60 70 80 90 100
2
3
6
6
9
8 12
10
24
10 15
14 21 28
9 18 27
24 28
10
20
30
40
50
60
A pedometer treats walking 1 step as walking 2.5 feet. Define a function named feet_to_steps that takes a float as a parameter, representing the number of feet walked, and returns an integer that represents the number of steps walked. Then, write a main program that reads the number of feet walked as an input, calls function feet_to_steps() with the input as an argument, and outputs the number of steps.
Use floating-point arithmetic to perform the conversion.
Ex: If the input is:
150.5
the output is:
60
The program must define and call the following function:def feet_to_steps(user_feet)
# Define your function here
if __name__ == '__main__': # Type your code here.
python
A pedometer treats walking 1 step as walking 2.5 feet. Define a function named feet_to_steps that takes a float as a parameter, representing the number of feet walked, and returns an integer that represents the number of steps walked. Then, write a main program that reads the number of feet walked as an input, calls function feet_to_steps() with the input as an argument, and outputs the number of steps.
Use floating-point arithmetic to perform the conversion.
Ex: If the input is:
150.5
the output is:
60
The program must define and call the following function:def feet_to_steps(user_feet)
my code(python):
def feet_to_steps(user_feet): steps = user_feet / 2.5 return steps
if __name__ == '__main__': user_feet = float(input())print(round(feet_to_steps(user_feet)))
How do I pass the unit test?
Chapter 3 Solutions
Absolute C++
Ch. 3 - A liter is 0.264179 gallons. Write a program that...Ch. 3 - Write a program to gauge the rate of inflation for...Ch. 3 - Enhance your program from the previous exercise by...Ch. 3 - The gravitational attractive force between two...Ch. 3 - Write a program that asks for the users height,...Ch. 3 - Write a function that computes the average and...Ch. 3 - In cold weather, meteorologists report an index...Ch. 3 - Write a program that outputs all 99 stanzas of the...Ch. 3 - In the game of craps, a Pass Line bet proceeds as...Ch. 3 - One way to estimate the height of a child is to...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Fill in the blanks in each of the following: A(n) is not required if you always refer to a class its fully qual...
Java How To Program (Early Objects)
In Exercises 11 through 16, determine the errors. PrivateSubbtnOutputClick(...)HandlesbtnOutput.ClicktxtBox=Hel...
Introduction To Programming Using Visual Basic (11th Edition)
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (8th Edition)
Write an SQL statement to display the breed, type, and DOB of all pets having the type Dog.
Database Concepts (7th Edition)
How Many Calories? A bag of cookies holds 30 cookies. The calorie information on the bag claims there are 10 se...
Starting Out with C++ from Control Structures to Objects (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- USING C++ A pedometer treats walking 1 step as walking 2.5 feet. Define a function named FeetToSteps that takes a double as a parameter, representing the number of feet walked, and returns an integer that represents the number of steps walked. Then, write a main program that reads the number of feet walked as an input, calls the function FeetToSteps() with the input as an argument, and outputs the number of steps. Use floating-point arithmetic to perform the conversion. Ex: If the input is: 150.5 the output is: 60 The program must define and call a function:int FeetToSteps (double userFeet)arrow_forwardA company wants to transmit data over the telephone but is concerned that its phones may b tapped. It has asked you to write a program that will encrypt the data so that it may be transmitted more securely. All the data transmitted is 4 digit integers. Your program should read a four digit integer entered by the user and calls a function encrypt which takes four digits as arguments and encrypt it as follows . Replace each digit with the result of adding 4 to the digit and getting the remainder after dividing the new value by 10. . Calls another function swap which swaps the first digit with the third, and second digit with the fourth using pass by reference. Then it prints the encrypted integer.arrow_forward5. Write a python function that takes one integer parameter, makes sure it is an integer, prints sum of every two digits and return the sum of digits from the number entered by the user up to 1, using recursion. Sample input: 4 Sample output: 4+3 = 7 7+2 = 9 9+1 = 10arrow_forward
- In Python: can you this problem be solved without using "while" and "for". Write a function called is_prime that receives a single integer value between 1 and 50 determines whether or not the integer is a prime. To determine if a number less than 50 is prime, you only need to divide it by all prime numbers less than or equal to the square root of 50 (i.e., 2, 3, 5, and 7). If any of them are smaller than the number and evenly divide the number, then it is not prime. By definition, 1 is not prime. Your solution should use the guess-and-check pattern. Write a main() function in your file to exercise your function to show that it works correctly. Your test implementation should not rely on visual inspection to determine if the tests pass.arrow_forwardpython with a function “harmonic(n)” that computes the n-th harmonic number, write a function “harmonic_all(n)” that returns the number of values generated until all values are obtained as a function of the range of possible values n, then write a function “harmonic_sim(n)” that repeats “harmonic_all(n)” a total of n_sim = 100 times. function harmonic(n) is written: def harmonic(n) : harmonic = 1.00 for i in range(2, n + 1) : harmonic += 1 / i return round(harmonic,2) please help with harmonic_all and harmonic_simarrow_forwardA pedometer treats walking 1 step as walking 2.5 feet. Define a function named feet_to_steps that takes a float as a parameter, representing the number of feet walked, and returns an integer that represents the number of steps walked. Then, write a main program that reads the number of feet walked as an input, calls function feet_to_steps with the input as an argument, and outputs the number of steps as an integer. Use floating-point arithmetic to perform the conversion. Ex: If the input is: 150.5 the output is: 60 The program must define and call the following function: def feet_to_steps (user_feet) 461710.3116374.qx3zqy7 LAB ACTIVITY 7.10.1: LAB: Step counter 1 # Define your function here 3 if __name_ 4 '__main__': #Type your code here. main.py 0/10 Load default template...arrow_forward
- An integer n is passed as a parameter to a function. Write the function in python language such that it returns the number of zeroes at the end of factorial of number n. For n= 5,12,100 the output should be 1,2,24 respectively.arrow_forwardThe ceiling of a floating-point number x is the smallest integer that is still larger than or equal to x. Alternatively, the ceiling of a floating-point number x is what you get when you round x up to the nearest integer. For example, the ceiling of 2.1 is 3, the ceiling of 0.9 is 1, the ceiling of -4.5 is -4, etc. Write a function called ceiling() to compute the ceiling of a float input parameter that returns one integer value. You may not use python’s ceil() or floor() functions. Your function may use int()/float() functions, and the floor division operator (i.e., '//').arrow_forwardWrite a program that works with fractions. Your program should be able to add,subtract, multiply, and divide two fractions. Write a separate function for addition,subtraction, multiplication and division. Specifically, your program must request two fractions from the user, getting the numerator and denominator separately for each fraction, and the operation to perform (add, subtract, multiply, or divide).Your program will then compute the resulting fraction, keeping the numerator and denominator separate, and output the result.arrow_forward
- Python Programming- Computer-Assisted Instruction Part 1: Computer-Assisted Instruction (CAI) refers to the use of computers in education. Write a script to help an elementary school student learn multiplication. Create a function that randomly generates and returns a tuple of two positive one-digit integers. Use that function's result in your script to prompt the user with a question, such as: How much is 6 times 7? For a correct answer, display the message "Very good!" and ask another multiplication question. For an incorrect answer, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. Part 2: Varying the computer's responses can help hold the student's attention. Modify the program so that various comments are displayed for each answer. Possible responses to a correct answer should include 'Very good!' , 'Nice work!' and 'Keep up the good work!' Possible responses to an incorrect answer shojld…arrow_forwardplease code in python Here's an example created by rotating a square 9 times: Write a Python program that will produce our simplified "spirograph" images from squares. Your program should include a function: spiro(num, side) that takes two arguments: the number of squares to draw in one revolution, and the side length of each square in the figure. Remember: there are 360 degrees in a circle. Here is a function that demonstrates how to draw a randomly colored filled square. You’ll want to copy-paste this function into your program, and call this function from within a loop in your spirograph function, so that it draws multiple squares: import turtle, random turtle.speed(0) turtle.delay(0) def filled_square(side): r = random.random() g = random.random() b = random.random() turtle.color(r,g,b) turtle.begin_fill() for i in range(4): turtle.forward(side) turtle.left(90) turtle.end_fill()arrow_forwardWrite a python function that will have 2 parameters and the first one is the name of a student and the second one is n quiz marks out of 20 of the student as a list. If the student has given even number of quizzes then the function will return the average of best (n-2) quizzes and if the student has given odd number of quizzes then the function will return the average of best (n-1) quizzes. NB: You can not use the built in sort/sorted/max/min function. Function Call 1:Student(“Jim”,[18,20,15,12,19]) Sample Output 1:Average of Jim’s quiz marks: 18 Function Call 2:Student(“Yen”,[12 16 12 19 20 18]) Sample Output 2:Average of Yen’s quiz marks: 18.25arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Computer Programming for Beginners | Functions, Parameters & Arguments | Ep24; Author: Programming With Avelx;https://www.youtube.com/watch?v=VXlh-qJpfw0;License: Standard YouTube License, CC-BY