Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 7, Problem 6E
Program Plan Intro
- Include required header files
- Give the function prototype
- Define the main function
- Call the function “squareRoot()” by passing different values.
- Definition for the function “absoluteValue(double x)”
- Check “x” is less than “0”.
- Assign “-x” to x“.
- Return the value of “x”.
- Definition for the function “squareRoot(double x)”
- Assign “epsilon” to “0.00001”
- Declare the variable “guess” as “float”
- Call the function “absoluteValue()”.
- Compute the value of guess.
- Return the value of guess.
- Assign “epsilon” to “0.00001”
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a function which will swap its arguments if the first argument is greater than its second argument,but will not interchange them if the first argument is smaller than or equal to the second argument. Thefunction should return 1 if a swap was made, and 0 otherwise.(Hint: Make sure to use call by reference.)Write also a short test driver(i.e. a main() invoking your function).
C++
IN C++
The text file is the 5 lines below
1 1 1
1.2 -2.3 0.4
-2 -3 -4
+0 -2 8.85
2.345
Write a function to read one set of values from the file. Use reference parameters (NOT anarray!) to get the values out of the function and the function’s return value to indicate whether ornot the function was able to correctly read three values. Return the 'stop' code on end-of-filebefore reading the third value. The only data error you must deal with here is too few values onthe line, e.g., the line has a and b values only but no c value. You may assume that the last linein the file is the only one with an error (if any error exists), and your function should return acode to make the program stop processing after this error. This restriction allows you to usestream extraction to read the file, rather than reading lines and parsing them yourself. Thisfunction MAY NOT try to read all the lines in the file, just read one line per call to the function.
Write a Convert() function that casts the parameter from a double to an integer and returns the result.Note that the main() function prints out the returned value of the Convert() function.
Ex: If the double value is 19.9, then the output is:
19
Ex: If the double value is 3.1, then the output is:
3
Chapter 7 Solutions
Programming in C
Ch. 7 - Type in and run the 17 programs presented in this...Ch. 7 - Prob. 2ECh. 7 - Modify Program 7.8 so that the value of e is...Ch. 7 - Modify Program 7.8 so that the value of g is...Ch. 7 - Prob. 6ECh. 7 - Write a function that raises an integer to a...Ch. 7 - Prob. 8ECh. 7 - The least common multiple (1cm) of two positive...Ch. 7 - Prob. 10ECh. 7 - Write a function called a that takes two...
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 Haskell.) One common misconception is that prime numbers are those that are not divisible by 2, 3, 5, 7 and 9. To dispel this myth, write a function fakePrimes that returns all numbers that are not divisible by 2, 3, 5, 7 and 9, and are not prime. For example, taking the first number out of this function we get [121].arrow_forward3. Write a function which will swap its arguments if the first argument is greater than its second argument, but will not interchange them if the first argument is smaller than or equal to the second argument. The function should return 1 if a swap was made, and 0 otherwise. (Hint: Make sure to use call by reference.) Write also a short test driver(i.e. a main() invoking your function).arrow_forwardWrite a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order.def swap_values(user_val1, user_val2) I get all tests passed except one.: the one in the bold. It puts parentheses around the answer instead of what they want for output. 0 / 2 Output differs. See highlights below. Input 4 5 Your output (5, 4) Expected output 5 4 2: Unit testkeyboard_arrow_up 2 / 2 swap_values(-1, 10) Your output swap_values(-1, 10) correctly returned 10 -1 3: Unit testkeyboard_arrow_up 3 / 3 swap_values(9, 0) Your output swap_values(9, 0) correctly returned 0 9 4: Unit testkeyboard_arrow_up 3 / 3 swap_values(11, 11) Your output swap_values(11, 11) correctly returned 11 11arrow_forward
- 5. 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_forwardModify the program so that it does the following: Performs a function that gets the area of a rectangle. The function must receive two parameters (decimal numbers) that represent the base and height of the rectangle and must return the calculated value (decimal number). Perform a second function that obtains the total area of a rectangular prism with a rectangular base. The total area of such a prism is equal to the sum of the areas of each of its faces. It uses calls to the previous function for this calculation. Call this last function in the main with user data. Execution example Give me the base: 21.3 Give me the height: 10 Give me the depth: 2.0 The total area of the prism is: 551.2arrow_forwardIn C++, there is an equation, please read this problem carefully. 2. Write a program to declare an integer array A of size 5 and assign its content (elements) through user input from the screen. Then call a function called "Max" that will calculate z using the equation given below and return and print the value of z from the main function. Note that you can call the function and return the z value using the call-by-reference or call-by-value method. z=4. Σε 14.arrow_forward
- Write a function that takes one argument, an integer, and returns the value of the following 1.1.1.7 2488 0,875 Στη functionyin) - 8.g. for m3, the function's value is Then, write a complete program that repeatedly prompts a user to enter a number, calls and print the value of the above-mentioned function. The program ends when the user enters 0. Use try/except to detect any mistake of non-numeric input and skip to the next input.arrow_forwardI need some help with a C++ arrays task. Provide the working code and make explanations using // . The initial code is provided in the photograph. The park is illuminated by n (1 <n <100) lights. Each of them shines all night or not. Of course, which lights were on the first night and which were not. Every other night the condition of the lamps shall be determined by the following rules: * The lamp will not illuminate if both of its neighbors were lit last night; * The lamp shall illuminate if one of its neighbors was illuminated last night and the other was not; ** if neither of the first two rules applies to the lamp, it will illuminate when the night is even and will not illuminate when the night is odd. Make a program to determine which lights are on and which will not be lit when k (1 <k <100) nights have elapsed, and to find which night the most lights were lit and which the least. If there are several identical nights with the most or least lights lit, the night…arrow_forwardIn C++, there is an equation, please read this problem carefully. 2. Write a program to declare an integer array A of size 5 and assign its content(elements) through user input from the screen. Then call a function called "Max" that will calculate z using the equation given below and return and print the value of z from the main function. Note that you can call the function and return the z value using the call-by-reference or call-by-value method. z = 4 Σ=1 Aiarrow_forward
- In this challenge, the task is to debug the existing code to successfully execute all provided test files. Python supports a useful concept of default argument values. For each keyword argument of a function, we can assign a default value which is going to be used as the value of said argument if the function is called without it. For example, consider the following increment function: defincrement_by(n,increment=1):returnn+increment The functions works like this: >>>increment_by(5,2)7>>>increment_by(4)5>>> Debug the given function print_from_stream using the default value of one of its arguments. The function has the following signature: defprint_from_stream(n,stream) This function should print the first values returned by get_next() method of stream object provided as an argument. Each of these values should be printed in a separate line. Whenever the function is called without the stream argument, it should use an instance of EvenStream class defined in…arrow_forward- Highlight Draw 1 #include \\ function 3 int main () { int a = 3; 6. float b = 4.5; %3D int c = 5.25; %3D 8. float sum; 9. 10 sum = a + b + c 11 12 printf("The sum of a, b, and c is 8f.", sum); 13 return 0; 14 A function written in C++ is shown in the box above.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_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