Question: Writing Your Own Function that Returns an Integer Step 1: A function contains three parts: a header, a body, and a return statement. The first

Writing Your Own Function that Returns an Integer

Step 1:A function contains three parts: a header, a body, and a return statement. The first is a function header which specifies the data type of the value that is to be returned, the name of the function, and any parameter variables used by the function to accept arguments. The body is comprised of one or more statements that are executed when the function is called. In the following space, complete the following: (Reference: Writing Your Own Functions, page 225).

  • Write a function with the header namedaddTen.
  • The function will accept anInteger variable namednumber.
  • The function body will ask the user to enter a number and the add 10 to the number. The answer will be stored in thevariable number.
  • Thereturn statement will return the value ofnumber.

Function a.__________ b.____________ (c.______________)

Display "Enter a number:"

Input d._________________

Set e._____________ = number + 10

Return f.___________________

Step 2: In the following space, write a function call to your function from Step 1.

Set number =____________________ (__________________)

Writing Your Own Function that Returns a Boolean Value

Step 1:A Boolean function will either return a true or a false value.You can use these functions to test a condition. They are useful for simplifying complex conditions that are tested in decision and repetition structures. In the following space, complete the following: (Reference: Returning Boolean Values, page 238).

  • Write a function namedgender. The function accepts no arguments.
  • The function will declare a local Boolean variable namedanswer, and a localString variable namedtype.
  • The function body will ask the user to enter their gender, and store the user's input in thetype variable.
  • The function will determine whether the user entered "male" or "female" with anif statement.
  • Thereturn statement will return the value ofanswer.

Function a.__________ b.____________ ()

Declare Boolean answer

Declare String type

Display "Enter your gender (male or female):"

Input c._________________

If (d.___________ == "male") then

answer = False

Else

answer = True

End If

Return e.___________________

Step 2: In the following space, write a function call to your function from Step 1.

Set answer =____________________ ()

Using Mathematical Library Function:sqrt

Step 1:Thesqrt function accepts an argument and returns the square root of the argument. In the following space, complete the following: (Reference: The sqrt Function, page 240).

  1. Declare a variable namedmyNumber and a variable namedsquareRoot of the data typeReal.
  2. Ask the user to enter a number of which they want to find the square root. Store the input inmyNumber.
  3. Call thesqrt function to determine the square root ofmyNumber.
  4. Display the square root to the screen.

Declare Integer a.___________________

Declare Real b.______________________

Display "Enter a number:"

Input c._________________________

Set d.______________ = _______________________

Display "The square root is ", e.____________________

Using Formatting Functions

Step 1:Most languages provide one or more functions that format numbers in some way. A common use of formatting functions is to format numbers as currency amounts.While a specific programming language will have its own name for formatting currency, use the functioncurrencyFormat for pseudocode. In the following space, complete the following: (Reference: Formatting Functions, page 246).

  • Declare a variable namedsubtotal, a constant variable namedtax set to the rate of .06, and a variable namedtotal.
  • Ask the user to enter the subtotal. Store the input insubtotal.
  • Calculate the total assubtotal + subtotal * tax.
  • Make a call to thecurrencyFormat function and pass ittotal. Display the value that is returned from the function on the screen.

Declare Real a.___________________

Declare Constant Real b.______________________

Declare Real c.____________________________

Display "Enter the subtotal:"

Input d._________________________

Set e.______________ = _______________________

Display "The total is $", f.____________(________)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here are the answers to the programming exercises Writing Your Own Function that Returns an Integer ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!