C++ More Functions Stuff Test #2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Variables declared inside main() cannot be accessed/used inside functions defined below the main() function. T or F

True

What is the last value printed by the following code? -------------------------------------------------------------------- using namespace std; double AddPayroll (double ); int main () { for (int i = 1; i < 5; i++) cout << AddPayroll( i*10 ) <<endl; return 0; } double AddPayroll(double pay) { static double total = 0; total += pay; return total; } ------------------------------------------------------------- Did you notice the static keyword? (1) 100.0 (2) 100 (3) 100.0000 (4) 100. (5) 100.00 (7) 100.000

(1) 100.0

What is the output of the following code? Your output must be exact! Enter "nothing" if it produces no output. ----------------------------------------------------------- int foo(); int main() { int x, a =0; cout << foo() << endl; x = a; return 0; } int foo() { int a,b,x; a = 10; b = 100; x = a*b; return x; }

1000

What number is output for the last value of B in the following code? Enter "nothing" if it produces no output. ------------------------------------------------------------- #include <iostream> using namespace std; void TestA (int &Y, int Z) { Y++; Z++; return; } void TestB (int Y, int& Z) { Y *= 2; Z *= 2; return; } void TestC (int &Y, int& Z) { Y++; Z++; return; } int main () { int A=5, B=7 TestA(A, B); cout<< "Line 1: " << A << ", " << B << endl; TestB(A, B); cout<< "Line 2: " << A << ", " << B << endl; TestC(A, B); cout<< "Line 3: " << A << ", " << B << endl; return 0; }

15

Which of the following are true for global variables? (Even though you are never supposed to use global variables!!!) (pick 4) (1) Group of answer choices (2) can only be used inside main() (3) cannot be of type string (4) retains their values after the program end (5) scan be used in all of the code that is after it in the program (6) can be initialized when it is declared (7) are declared outside of any function (8) can only be type int (9) are declared inside main() (10) are EVIL! You should never use them for this course, and it is unlikely that you should ever use them, ever.

2 4 5 10

What is the last number output by the following code? Enter "nothing" if it produces no output. --------------------------------------------------------- #include <iostream> using namespace std; const int NUM = 10; void food_on_table() { static int food = NUM; food--; cout << food << endl; return; } int main () { for (int i = 0; i < 5; i++) food_on_table(); return 0; ;

5

Actual parameters (arguments) and formal parameters should have the same name to avoid confusion. T or F

False

In pass by reference, a copy of the parameter value is passed into the function, and when the function returns the orginal value passed in is restored. T or F

False

Parameter names in the prototype must be the same as formal parameter names. T or F

False

Any parameter that passes in data to the called function and passes data back out to the calling funciton is a ______________ parameter.

reference


Kaugnay na mga set ng pag-aaral

Chapter 4: Disability Income & Related Insurance

View Set

Mr. Perez World Civilizations Exam 1

View Set

Tutorialspoint: Data Structure and Algorithms Interview Questions

View Set

(18) Non-Governmental Organizations

View Set

MKTG CH 12 TRUE OR FALSE, Marketing Study Questions, ch 13, Chapter 11, Marketing 351 Ole Miss Cousley Chapters 13 (Shuffle to avoid repeating of the same topics), chp 6 mktg, chp 6 mktg, Marketing Ch.6, Marketing Chapter 8, MKTG test 2 ch 6, MKTG ch...

View Set