Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Mark the following statements as true or false. a. \(A\) function that changes the value of a reference parameter also changes the value of the actual parameter. b. \(A\) variable name cannot be passed to a value parameter. c. If a \(C++\) function does not use parameters, parentheses around the empty parameter list are still required. d. In \(C++,\) the names of the corresponding formal and actual parameters must be the same. e. Whenever the value of a reference parameter changes, the value of the actual parameter changes. f. In \(C++,\) function definitions can be nested; that is, the definition of one function can be enclosed in the body of another function. g. Using global variables in a program is a better programming style than using local variables, because extra variables can be avoided. h. In a program, global constants are as dangerous as global variables. i. The memory for a static variable remains allocated between function calls.

Problem 2

Identify the following items in the programming code shown below. a. Function prototype, function heading, function body, and function definitions b. Function call statements, formal parameters, and actual parameters c. Value parameters and reference parameters d. Local variables and global variables #include //Line 1 using namespace std; //Line 2 int one; //Line 3 void hello(int&, double, char); //Line 4 int main() //Line 5 { //Line 6 int x; //Line 7 double y; //Line 8 char z; //Line 9 . . . hello(x, y, z); //Line 10 . . . hello(x, y - 3.5, 'S'); //Line 11 . . . } //Line 12 void hello(int& first, double second, char ch) //Line 13 { //Line 14 int num; //Line 15 double y; //Line 16 int u ; //Line 17 . . . } //Line 18

Problem 3

a. Explain the difference between an actual and a formal parameter. b. Explain the difference between a value and a reference parameter. c. Explain the difference between a local and a global variable.

Problem 4

include using namespace std; void func1(); void func2(); int main() { int num; cout << "Enter 1 or 2: "; cin >> … # What is the output of the following program? #include using namespace std; void func1(); void func2(); int main() { int num; cout << "Enter 1 or 2: "; cin >> num; cout << endl; cout << "Take "; if (num == 1) func1(); else if (num == 2) func2(); else cout << "Invalid input. You must enter a 1 or 2" << endl; return 0; } void func1() { cout << "Programming I." <

Problem 5

Write the definition of a void function that takes as input a decimal number and as output 3 times the value of the decimal number. Format your output to two decimal places.

Problem 6

Write the definition of a void function that takes as input two decimal numbers. If the first number is nonzero, it outputs second number divided by the first number; otherwise, it outputs a message indicating that the second number cannot be divided by the first number because the first number is 0

Problem 7

Write the definition of a void function with three reference parameters of type int, double, and string. The function sets the values of the int and double variables to 0 and the value of the string variable to the empty string.

Problem 8

Write the definition of a void function that takes as input two parameters of type int, say sum and testscore. The function updates the value of sum by adding the value of testscore. The new value of sum is reflected in the calling environment.

Problem 9

include using namespace std; void find(int a, int& b, int& c,) int main() { int one, two, three; one = 5; two = … # What is the output of the following program? #include using namespace std; void find(int a, int& b, int& c,) int main() { int one, two, three; one = 5; two = 10; three = 15; find(one, two, three); cout << one << ", " << two << ", " << three << endl; find(two, one, three); cout << one << ", " << two << ", " << three << endl; find(three, two, one); cout << one << ", " << two << ", " << three << endl; find(two, three, one); cout << one << ", " << two << ", " << three << endl; return 0; } void find(int a, int& b, int& c) { int temp; c = a + b; temp = a; a = b; b = 2 * temp; }

Problem 10

include using namespace std; int x; void summer(int&, int); void fall(int, int&); int main() { int intNum1 = 2; … # What is the output of the following program? #include using namespace std; int x; void summer(int&, int); void fall(int, int&); int main() { int intNum1 = 2; int intNum2 = 5; x = 6; summer(intNum1, intNum2); cout << intNum1 << " " << intNum2 << " " << x << endl; fall(intNum1, intNum2); cout << intNum1 << " " << intNum2 << " " << x << endl; return 0; } void summer(int& a, int b) { int intNum1; intNum1 = b + 12; a = 2 * b + 5; b = intNum1 + 4; } void fall(int u, int& v) { int intNum2; intNum2= x; v = intNum2 * 4; x = u - v; }

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks