Example 1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter. Example 2: Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which.  Example 3: Construct a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 9SA
icon
Related questions
Question

Example 1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter.

Example 2: Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which. 

Example 3: Construct a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.

Example 4: Construct a function that takes an argument. Give the function parameter a unique name. Show what happens when you try to use that parameter name outside the function. Explain the results.

Example 5: Show what happens when a variable defined outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the program runs.

The code and its output must be explained technically whenever asked. The explanation can be provided before or after the code, or in the form of code comments within the code. For any descriptive type question, Your answer must be at least 150 words.

End your discussion post with one question related to programming fundamentals learned in this unit from which your colleagues can formulate a response or generate further discussion.

Expert Solution
Step 1

“Since you have posted a question with multiple sub-parts, we will solve the first three sub-parts for you. To get the remaining sub-part solved please repost the complete question and mention the sub-parts to be solved.”

Example 1:

Algorithm steps for the given problem:

  1. Start
  2. Define a function printFunction(n1, n2)
  3. Declare a variable n3 and set it equal to n1 + n2 # 3. Return the value of n3
  4. Call the function printFunction(2, 3)
  5. Print the value of x which is the return value of printFunction(2, 3)
  6. Stop.
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 9 steps with 6 images

Blurred answer
Knowledge Booster
Events
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr