Name: _______________________Section: ____ ID: _________________
A function calling statement must supply arguments that
Which of the following appear in a function header?
How does a function report its answer back to its calling (or boss) function?
A function prototype does not have to __________.
What will be displayed by the following code?
int main() { int num = 3; fn(num); cout << num; return 0; } int fn( int n ) { n++; }
When the body of a function begins to execute what is true of its arguments?
A variable called score is declared in main(). main() calls a function UpdateScore to update the score. UpdateScore also has a variable called score. When a value is added to score in UpdateScore, the value of score in main() is also changed.
Prototype statements are placed before int main().
The function header and the calling statement must contain the name and the data type of the arguments.
The statement int main() means that main is a function that takes no arguments, and returns an integer.
What is the subscript of the last element in the array Table if it is defined as follows?
float Table[30];
Which of the following statements (a-d) about Table is true?
float Table[] = { 0.9, 0.8, 0.7, 0.6 };
Which of the following "chunks" of C++ code will print the contents of an array called ar that has been defined to hold 25 integer values and has been initialized with 25 integer values?
int i;
cout << ar[];
for( i = 0; i == 25; i++ ) cout << ar[i] << " ";
for( i = 0; i < 25; i++ ) cout << ar[i] << " ";
for( i = 0; i < 25; i++ ); cout << ar[i] << " ";
The following is a valid array definition.
int ar[];
What will be displayed by the following code?
int main() { int num[5] = { 2, 4, 6, 8, 10 }; int i; fn(num); for( i = 0; i < 5; i++ ) cout << num[i] << ' '; return 0; } int fn( int n[] ) { n[3] = n[3] + 1; }
We call the pieces of information that are passed to a function, which it then uses to do its task a/an ___________.
A function may return __________ or __________ result(s). It may take __________ to __________ arguments.
List two differences between a function prototype and a function header:
___________________________________________________________
___________________________________________________________
Function prototypes are located ________________________________.
If a function does not return anything, then the return type on the function prototype and function header is _____________.
Consider the following program:
int main() int abc(int m) float xyz(float v, int k) { { { int a = 3, b; int i, j = 1; int i; float x = 2.0, y; float w = 1.0; b = abc(a); for(i=1; i<=m; i++) for(i=1; i<=k; i++, w *= v); y = xyz(x, a); j = j * i; return 0; } return j; return (w); } }
When the program is completed, the value of b is __________ and the value of y is __________.
Complete the following sentence: If you declare an array to hold N values, legal subscripts run from _____ to ______.
Complete the following sentence: the unsubscripted name of an array is _______________________________.
Write a function that takes a real number of ounces (representing the weight of a letter) and returns an integer number of cents which represents the cost of mailing the letter. The rules for calculating the cost are as follows:
Write a function (call it getAns()) that prompts the user to enter a single letter from "a" to "d". It will return that letter to the calling function. It will not return anything but "a" through "d". If the user enters anything else, it will display an error message and ask the user to re-enter until they enter a value between "a" through "d".
Write a single statement that will both call getAns() and display the value returned.
Write a function called GetIntegerInRange() that gets an integer value from the user that is between 0 and an upperbound. It takes 1 argument:
It returns an integer: the value that is between 0 and the upperbound.
The function should prompt the user to enter a value between 0 and the passed in high value. As long as the user enters an an invalid value (i.e. smaller then 0 or greater then the high value), display an error message and have the user try again. Once the user has entered a valid value, it should be returned.
Example: assuming the user passes in the value 120. The output should closely resemble:
Enter a number (0 to quit) between 0 and 120:
NOTE: You may assume that the passed in high value is greater than 0.
Write a COMPLETE program that uses GetIntegerInRange() to accept temperatures from the user in the range of 0 to 120. The value of 0 serves as an exit signal.
After all the temperatures have been entered, the program should display the following with brief labels:
You may assume that at least one temperature above 32 is entered and that one temperature below 32 is entered.
Assume an array called AR contains 45 integers. Write a loop to print out the values of every other integer starting from subscript 0.
Assume an array called AR contains 10 integers. Write code to swap the very first and the very last values in the array.
Declare an array to hold 500 integers. In the declaration statement, initialize the array so the very first value is 2, the second is 4, and all the rest are 0.
Write a function to cube the first N elements in an array of doubles. The function should be passed the array and the number of elements to be cubed. It returns nothing.
Write a function to return the sum of the first N elements in an array of doubles. The function can assume N >= 0. The function should be passed the array and the number of elements to be added together.