/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Problem 11 Perform the task specified by ea... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

Perform the task specified by each of the following statements: a. Write the function header for function zero that takes a long integer array parameter bigIntegers and does not return a value. b. Write the function prototype for the function in part (a). c. Write the function header for function add1AndSum that takes an integer array parameter oneTooSmall and returns an integer. d. Write the function prototype for the function described in part (c)

Short Answer

Expert verified
a. `void zero(long bigIntegers[])` b. `void zero(long bigIntegers[]);` c. `int add1AndSum(int oneTooSmall[])` d. `int add1AndSum(int oneTooSmall[]);`

Step by step solution

01

Function Header for 'zero'

To write the function header for function 'zero', identify that it takes a parameter called `bigIntegers` of type `long integer array` and does not return any value. A function that does not return any value in C++ uses the `void` keyword. ```cpp void zero(long bigIntegers[]) ```
02

Function Prototype for 'zero'

A function prototype is a declaration of the function that specifies its name, parameters, and return type. It's essential before defining or calling a function in C++ if the definition happens after the call. ```cpp void zero(long bigIntegers[]); ```
03

Function Header for 'add1AndSum'

This function header defines a function `add1AndSum` that takes an `integer array` named `oneTooSmall` and returns an `integer`. The return type `int` is specified at the beginning of the function header. ```cpp int add1AndSum(int oneTooSmall[]) ```
04

Function Prototype for 'add1AndSum'

A function prototype for `add1AndSum` is similar to its header but includes a semicolon at the end. It's used to inform the compiler about the function's presence and is critical if the definition appears after its usage. ```cpp int add1AndSum(int oneTooSmall[]); ```

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 91Ó°ÊÓ!

Key Concepts

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

Function Prototype
In C++, a function prototype serves as a blueprint for a function, informing the compiler about the function's name, return type, and parameters. Essentially, it is a function declaration without the body. A function prototype is particularly useful because it allows the compiler to perform type checking on function calls, ensuring that the correct arguments are passed and reducing errors.

For example, if you have a function that doesn't return any value and takes a long integer array as a parameter named `bigIntegers`, the function prototype would look like this:
  • For a void function, you start with the keyword `void`.
  • Specify the function name followed by its parameters in parentheses.
  • End the prototype with a semicolon.
Example: ```cpp void zero(long bigIntegers[]); ``` This simple declaration is enough to inform the compiler that a function named `zero` exists and takes a long integer array as an argument.
Parameter Passing
Parameter passing in C++ involves providing input values to functions. Parameters allow functions to operate on different data each time they are called. The two common ways of passing parameters in C++ are by value and by reference.

  • By Value: When parameters are passed by value, the function creates a copy of the argument values. Changes to these parameters inside the function do not affect the original arguments outside the function. This is useful when you want to keep the original data intact.
  • By Reference: Parameters passed by reference allow the function to modify the original data since it receives the location of the actual arguments. It's beneficial when working with large data structures like arrays or when the function needs to alter the argument values.

In the context of arrays, even though the syntax might not explicitly show it, arrays are always passed by reference. This means when you pass an array to a function, modifications within the function affect the original array.
Void Functions
Void functions in C++ are specific types of functions that do not return any value. Instead, they simply perform an action or a series of actions. The `void` keyword is used to denote the absence of return value.

They are especially useful when you need to execute code repeatedly across different parts of a program. For example, if you want a function to print data to the screen or modify objects or variables in place, using a void function can be quite effective.

When defining a void function, remember to:
  • Use the `void` keyword at the start of the function declaration and definition.
  • Focus on side effects like printing output or modifying global variables.

Here’s an example of a void function that takes a long integer array as a parameter: ```cpp void zero(long bigIntegers[]) ``` This function does not return any data but might perform operations on the `bigIntegers` array.
Integer Arrays
Arrays are fundamental data structures in C++ used to store a fixed-size sequential collection of elements of the same type. Integer arrays specifically store integers and can be very useful in situations where you need to handle a list of integer values.

When passing an integer array to a function, it is important to understand that the array itself is passed by reference. It means any modifications inside the function will affect the original array outside the function.

To declare an integer array in C++, you can use this syntax: ```cpp int myArray[10]; ```
  • Here `int` signifies an array that holds integer values.
  • `myArray` is the name of the array, and `[10]` denotes its size, indicating that it can hold 10 integer elements.

When using functions to manipulate arrays, the function needs to know the array's size, as C++ functions can't inherently determine the size of arrays passed to them.

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

Perform the task specified by each of the following statements: a. Write the function header for a function called exchange that takes two pointers to double-precision, floating-point numbers x and y as parameters and does not return a value. b. Write the function prototype for the function in part (a). c. Write the function header for a function called evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns an integer. d. Write the function prototype for the function in part (c). e. Write two statements that each initialize character array vowel with the string of vowels, "AEIOU".

(Check Protection) Computers are frequently employed in check-writing systems such as payroll and accounts-payable applications. Many strange stories circulate regarding weekly paychecks being printed (by mistake) for amounts in excess of \(1 million. Weird amounts are printed by computerized check-writing systems, because of human error or machine failure. Systems designers build controls into their systems to prevent such erroneous checks from being issued. Another serious problem is the intentional alteration of a check amount by someone who intends to cash a check fraudulently. To prevent a dollar amount from being altered, most computerized check-writing systems employ a technique called check protection. Checks designed for imprinting by computer contain a fixed number of spaces in which the computer may print an amount. Suppose that a paycheck contains eight blank spaces in which the computer is supposed to print the amount of a weekly paycheck. If the amount is large, then all eight of those spaces will be filled, for example, 12345678 (position numbers) On the other hand, if the amount is less than \)1000, then several of the spaces would ordinarily be left blank. For example, 99.87 \-------- 12345678 contains three blank spaces. If a check is printed with blank spaces, it is easier for someone to alter the amount of the check. To prevent a check from being altered, many check-writing systems insert leading asterisks to protect the amount as follows: ***99.87 \-------- 12345678 Write a program that inputs a dollar amount to be printed on a check and then prints the amount in check-protected format with leading asterisks if necessary. Assume that nine spaces are available for printing an amount.

State whether the following are true or false. If the answer is false, explain why. a. The address operator & can be applied only to constants and to expressions. b. A pointer that is declared to be of type void * can be dereferenced. c. Pointers of different types can never be assigned to one another without a cast operation.

Write two versions of each string-comparison function in Fig. 8.30. The first version should use array subscripting, and the second should use pointers and pointer arithmetic.

Write two versions of each string copy and string-concatenation function in Fig. 8.30. The first version should use array subscripting, and the second should use pointers and pointer arithmetic.

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.