answersLogoWhite

0


Best Answer

You design it as an inline function with a constant unsigned reference parameter. Since there are 12 inches to the foot, the return value is the product of the parameter and 12. However, you must also ensure the return type has enough bits to store the result.

C++ example:

inline unsigned int feetToinches( const unsigned int & feet ){

return( feet < 357913941 ? feet * 12 : 0 ); }

The above example assumes an int is 32-bits wide. If the input is larger than 357913941 (feet) then there won't be enough bits to store the result, so zero is returned instead. If the input is non-zero and the return is zero, you know the conversion failed.

We use unsigned data types because you cannot have a negative unit of distance. We use a reference parameter to prevent the parameter from being copied (not strictly necessary if the type will fit within a pointer variable, but good practice nonetheless). The parameter is constant because the function does not need to modify the parameter. It is inline because the code is not complicated and is a prime candidate for inline expansion, thus eliminating the need for a function call altogether.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you design a function named feetToinches that accepts a number of feet as an argument and returns the number of inches in that many feet?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you Write a function prototype for a function named printStars that accepts no arguments and returns no data?

void printStarts (void);


How would you write a function prototype for a function named calcAreaReact that accepts two arguments width and length and returns the area.?

double calcAreaRect (double a, double b);


What is a variable that is used within a function?

If the variable is declared within the function body, it is a local variable, one that is local to the function. Local variables fall from scope when the function returns, they are only accessible within the function. However, local variables can be returned by value, which creates an automatic variable that is returned to the caller. If the caller does not store the return value, the automatic variable falls from scope when the expression containing the function call ends. However, the expression may evaluate the return value without storing it. Note that functions cannot return local variables by reference since the local variable falls from scope when the function returns. If the variable is passed as an argument to the function, then the variable is a parameter of the function. Arguments may be passed by value or by reference, depending upon the function signature. Passing by value means the function parameter is a copy of the argument (if the argument is an object, the object's copy constructor is invoked automatically). Thus any changes made to the parameter within the function are not reflected in the argument that was originally passed, and the parameter will fall from scope when the function returns. However, the value of the parameter can be returned as previously explained. Passing by reference means the function parameter refers directly to the argument that was passed. Thus any changes made to the parameter are reflected in the argument. Parameters that are declared as constant references assure the caller that the reference's immutable members will not be altered by the function. If the parameter is a non-const reference but the caller does not wish changes to be reflected in the argument, the caller should pass a copy of the argument instead.


Describe a chicken using a programming language?

chicken is a function which takes argument as grain type and returns egg. egg chicken(grain x);


Difference between sizeof and strlen?

The sizeof operator returns the total size, in bytes, of the given operand, whereas the strlen function returns the number of characters in the argument up to but not including the first null-terminator.Consider a character buffer allocated 50 bytes to which you assign the string "Hello world". The sizeof operator will return 50, but the strlen function returns 11.

Related questions

A function prime that returns if its argument is a prime no or returns zero?

prime number


How do you Write a function prototype for a function named printStars that accepts no arguments and returns no data?

void printStarts (void);


How would you write a function prototype for a function named calcAreaReact that accepts two arguments width and length and returns the area.?

double calcAreaRect (double a, double b);


Write a function prototype named test that accepts two parameters an integer and character and returns a float?

float test(int, char);


What are the conditional logic functions in computer applications?

Not sure what you are asking here, but here is my best guess.COMPUTER PROGRAMMING APPLICATIONS:IF - If a condition exists, do something, if not, do something else.CASE - If a condition equals CASE1 do this; if CASE2 do this; etc.WHILE - If a condition remains, keep doing something until the condition changes.EXCEL:AND(logical1,logical2,...) - tests whether the logical arguments are TRUE or FALSE. If they are all TRUE, the AND function returns TRUE to the cell. If any are FALSE, the AND function returns FALSE.IF(logical_test,value_if_true,value_if_false) - tests whether the logical_test expression is TRUE or FALSE. If TRUE, the IF function returns the value_if_true argument. If FALSE, the IF function returns the value_if_false argument.IFERROR(value,value_if_error) - tests whether the value expression is an error. IFERROR returns value_if_error if the expression is an error, or value of the expression if it is not an error.NOT(logical) - tests whether the logical argument is TRUE or FALSE. If TRUE, the NOT function returns FALSE. If FALSE, the NOT function returns TRUE.OR(logical1,logical2,...) - tests whether the logical arguments are TRUE or FALSE. If any are TRUE, the OR function returns TRUE. If all are FALSE, the OR function returns FALSE.FALSE() - takes no argument and simply enters logical FALSE in its cell.TRUE() - takes no argument and simply enters logical TRUE in its cell.


Write a function prime that return 1 if its argument is a prime and returns 0 otherwise?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt;main() { }


What is a variable that is used within a function?

If the variable is declared within the function body, it is a local variable, one that is local to the function. Local variables fall from scope when the function returns, they are only accessible within the function. However, local variables can be returned by value, which creates an automatic variable that is returned to the caller. If the caller does not store the return value, the automatic variable falls from scope when the expression containing the function call ends. However, the expression may evaluate the return value without storing it. Note that functions cannot return local variables by reference since the local variable falls from scope when the function returns. If the variable is passed as an argument to the function, then the variable is a parameter of the function. Arguments may be passed by value or by reference, depending upon the function signature. Passing by value means the function parameter is a copy of the argument (if the argument is an object, the object's copy constructor is invoked automatically). Thus any changes made to the parameter within the function are not reflected in the argument that was originally passed, and the parameter will fall from scope when the function returns. However, the value of the parameter can be returned as previously explained. Passing by reference means the function parameter refers directly to the argument that was passed. Thus any changes made to the parameter are reflected in the argument. Parameters that are declared as constant references assure the caller that the reference's immutable members will not be altered by the function. If the parameter is a non-const reference but the caller does not wish changes to be reflected in the argument, the caller should pass a copy of the argument instead.


Describe a chicken using a programming language?

chicken is a function which takes argument as grain type and returns egg. egg chicken(grain x);


An argument takes a value or values and performs an operation?

In programming, an argument takes a value or vales and performs an operation is called a function or method. If a method does not return a value, it is described as 'void'.


Does a function that takes a value or values and performs an operation return a result to the caller?

Not necessarily. A function that accepts one or more arguments may process those arguments but need not return any value to the caller. In this case the function simply returns void.


Difference between sizeof and strlen?

The sizeof operator returns the total size, in bytes, of the given operand, whereas the strlen function returns the number of characters in the argument up to but not including the first null-terminator.Consider a character buffer allocated 50 bytes to which you assign the string "Hello world". The sizeof operator will return 50, but the strlen function returns 11.


A function takes the exponential function's output and returns the exponential function's input?

A __________ function takes the exponential function's output and returns the exponential function's input.