Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Give the function header for each of the following functions: a) Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result. b) Function smallest that takes three integers, x, y and z, and returns an integer. c) Function instructions that does not receive any arguments and does not return a value. [Note: Such functions are commonly used to display instructions to a user.] d) Function intToDouble that takes an integer argument, number, and returns a double- precision, floating-point result.

Short Answer

Expert verified
a) double hypotenuse(double side1, double side2) b) int smallest(int x, int y, int z) c) void instructions() d) double intToDouble(int number)

Step by step solution

01

Function hypotenuse

To create the function header for the hypotenuse function, identify the return type, function name, and parameter types. The return type is a double-precision floating-point number. The name of the function is 'hypotenuse'. It takes two double-precision floating-point numbers as parameters. So, the header will be 'double hypotenuse(double side1, double side2)'.
02

Function smallest

For the smallest function, recognize the return type and the parameter types. Here, the function returns an integer, and it also takes three integers as parameters. The name of the function is 'smallest'. Therefore, the function header will be 'int smallest(int x, int y, int z)'.
03

Function instructions

The instructions function does not take any arguments and also does not return anything, hence 'void' is used as the return type to specify that no value will be returned. The header will simply be 'void instructions()'. This is typical for a function meant to display information.
04

Function intToDouble

The intToDouble function header needs a return type that is a double-precision floating-point number and one integer parameter. This tells us that the header will be 'double intToDouble(int number)'.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

Function Prototypes
To understand how C++ function prototypes work, let's think of them as a sneak peek or a summary of what a function can do without actually seeing its inner workings. Similar to the contents page in a book, function prototypes give both the coder and the compiler a quick glimpse into the function's functionality. In essence, a function prototype outlines the function's name, its return type, and the parameters (or 'arguments') it takes, along with their data types.

For example, according to the textbook exercise, the function prototype for 'hypotenuse' is declared as 'double hypotenuse(double side1, double side2);'. This indicates to the compiler that there's a function called 'hypotenuse', it expects two double arguments, and it will return a double value. Prototypes are crucial in C++ programming because they inform the compiler about function calls before the actual function definition is encountered during the linking phase, thereby preventing any 'implicit declaration' errors.
Data Types
C++ is a strongly-typed language, which means that every variable and expression has a type, and that type is known at compile time. Data types in C++ define the type of data a variable can hold, such as integer, floating-point numbers, or characters, and also determine the kind of operations that can be performed on that data. The importance of data types is demonstrated in the step by step solutions where the 'smallest' function returns an integer and takes three integers as parameters, represented as 'int smallest(int x, int y, int z);'. The correct usage of data types is essential for the correctness, efficiency, and clarity of the code. It’s akin to choosing the right kind of storage container; choosing wrongly could either waste space (memory) or lead to content (data) spillage (errors or unintended behavior).
Function Declaration
When we define a function declaration, or more commonly 'function header', we're making a promise to the compiler about how a function will look and behave. This acts as a contract—or in programming terms, a prototype—that must be fulfilled later when the function is actually defined with the code that implements its behavior. The declaration includes the function's name, its return type, and the types of any parameters it accepts. Take 'void instructions()' as an example. Here, 'void' signifies that this function doesn't deliver a return value, and the empty parentheses indicate it doesn’t require any input parameters. To summarize, a function declaration is like an advertisement for a movie: It tells you the title and what to expect, but not the whole story—that’s reserved for the function's definition where the full code is written.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

(Multiples) Write a function multiple that determines for a pair of integers whether the second is a multiple of the first. The function should take two integer arguments and return true if the second is a multiple of the first, false otherwise. Use this function in a program that inputs a series of pairs of integers.

The use of computers in education is referred to as \(\mathrm{com}\) puter- assisted instruction \((\mathrm{CAI})\). Write a program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times \(7 ?\) The student then inputs the answer. Next, the program checks the student's answer. If it's correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly.

Implement the following integer functions: a) Function Celsius returns the Celsius equivalent of a Fahrenheit temperature. b) Function Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature. c) Use these functions to write a program that prints charts showing the Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees, and the Celsius equivalents of all Fahrenheit temperatures from 32 to 212 degrees. Print the outputs in a neat tabular format that minimizes the number of lines of output while remaining readable.

A parking garage charges a \$2.00 minimum fee to park for up to three hours. The garage charges an additional \$0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is \$10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function calculate Charges to determine the charge for each customer. Your outputs should appear in the following format: $$\begin{array}{lrr} \text { Car } & \text { Hours } & \text { Charge } \\ 1 & 1.5 & 2.00 \\ 2 & 4.0 & 2.50 \\ 3 & 24.0 & 10.00 \\ \text { TOTAL } & 29.5 & 14.50 \end{array}$$

Write a program that plays the game of "guess the number" as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to \(1000 .\) The program then displays the following: I have a number between 1 and 1000 . Can you guess my number? Please type your first guess. The player then types a first guess. The program responds with one of the following: 1\. Excellent! You guessed the number! Would you like to play again (y or n)? \(2 .\) Too 7 ow. Try again. 3\. Too high. Try again. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program should keep telling the player Too high or Too low to help the player "zero in" on the correct answer.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free