Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10) After a value is returned from a called function, program control reverts to

ID: 3775704 • Letter: 1

Question


10) After a value is returned from a called function, program control reverts to the ____. a. compiler c. in-line function b. called function d. calling function
The value returned by a called function is ____ converted to the data type declared in the function declaration. a. usually b. sometimes c. always d. never A local variable that is declared as ____ causes the program to keep the variable and its latest value, even when the function that declared it is finished executing.
11) Write a function called evens that receives an integer parameter and returns the sum of the even numbers up to that integer. Ex. evens(8 ) would return 20; 2+4+6+8 evens( 5 ) would return 6: 2+ 4 Give both the function header and function description as well as the complete function.
Write a complete program that asks the user to enter two integers. The program then calls a function called mods which uses the input numbers as arguments. The function doesn’t return a value but prints out the numbers that are odd. If neither is odd it prints NONE. Ex. mods(4, 7) prints 7 mods (5,9) prints 5 9 mods (2,4) prints NONE
What is produced as output for the following?
#include <iostream> using namespace std;
int w =5; int fct( int, int);
int main( ) { int n, k =3, m = -2;
n = fct(k, m);
cout << "n="<< n << endl;    cout << "k="<< k << endl;    cout << "m=" << m<<endl; cout << "w=" << w << endl ; n=3; k=-4; m= fct(k, n);
cout << "n="<< n << endl;    cout << "k="<< k << endl;    cout << "m=" << m<<endl; cout << "w=" << w << endl ; system("pause"); return 0; }
int fct (int s , int t) { s = s * 5; t = t+ 3 ; w = t-- + w; return t; }
10) After a value is returned from a called function, program control reverts to the ____. a. compiler c. in-line function b. called function d. calling function
The value returned by a called function is ____ converted to the data type declared in the function declaration. a. usually b. sometimes c. always d. never A local variable that is declared as ____ causes the program to keep the variable and its latest value, even when the function that declared it is finished executing.
11) Write a function called evens that receives an integer parameter and returns the sum of the even numbers up to that integer. Ex. evens(8 ) would return 20; 2+4+6+8 evens( 5 ) would return 6: 2+ 4 Give both the function header and function description as well as the complete function.
Write a complete program that asks the user to enter two integers. The program then calls a function called mods which uses the input numbers as arguments. The function doesn’t return a value but prints out the numbers that are odd. If neither is odd it prints NONE. Ex. mods(4, 7) prints 7 mods (5,9) prints 5 9 mods (2,4) prints NONE
What is produced as output for the following?
#include <iostream> using namespace std;
int w =5; int fct( int, int);
int main( ) { int n, k =3, m = -2;
n = fct(k, m);
cout << "n="<< n << endl;    cout << "k="<< k << endl;    cout << "m=" << m<<endl; cout << "w=" << w << endl ; n=3; k=-4; m= fct(k, n);
cout << "n="<< n << endl;    cout << "k="<< k << endl;    cout << "m=" << m<<endl; cout << "w=" << w << endl ; system("pause"); return 0; }
int fct (int s , int t) { s = s * 5; t = t+ 3 ; w = t-- + w; return t; }
10) After a value is returned from a called function, program control reverts to the ____. a. compiler c. in-line function b. called function d. calling function
The value returned by a called function is ____ converted to the data type declared in the function declaration. a. usually b. sometimes c. always d. never A local variable that is declared as ____ causes the program to keep the variable and its latest value, even when the function that declared it is finished executing.
11) Write a function called evens that receives an integer parameter and returns the sum of the even numbers up to that integer. Ex. evens(8 ) would return 20; 2+4+6+8 evens( 5 ) would return 6: 2+ 4 Give both the function header and function description as well as the complete function.
Write a complete program that asks the user to enter two integers. The program then calls a function called mods which uses the input numbers as arguments. The function doesn’t return a value but prints out the numbers that are odd. If neither is odd it prints NONE. Ex. mods(4, 7) prints 7 mods (5,9) prints 5 9 mods (2,4) prints NONE
What is produced as output for the following?
#include <iostream> using namespace std;
int w =5; int fct( int, int);
int main( ) { int n, k =3, m = -2;
n = fct(k, m);
cout << "n="<< n << endl;    cout << "k="<< k << endl;    cout << "m=" << m<<endl; cout << "w=" << w << endl ; n=3; k=-4; m= fct(k, n);
cout << "n="<< n << endl;    cout << "k="<< k << endl;    cout << "m=" << m<<endl; cout << "w=" << w << endl ; system("pause"); return 0; }
int fct (int s , int t) { s = s * 5; t = t+ 3 ; w = t-- + w; return t; }

Explanation / Answer

10) After a value is returned from a called function, program control reverts to the ____.

a. compiler c. in-line function b. called function d. calling function

Once the function is called, the control transfers from calling function to called function, and once done, the controls comes back to the calling function.

The value returned by a called function is ____ converted to the data type declared in the function declaration.

a. usually b. sometimes c. always d. never

A local variable that is declared as __static__ causes the program to keep the variable and its latest value, even when the function that declared it is finished executing.

11) Write a function called evens that receives an integer parameter and

returns the sum of the even numbers up to that integer.

Ex. evens(8 ) would return 20; 2+4+6+8

evens( 5 ) would return 6: 2+ 4

Give both the function header and function description as well as the complete function.

int evens(int); //Function header.

int evens(int num)

{

int sum = 0;

for(int i = 2; i <= num; i += 2)

sum += i;

return sum;

}