CSCI 130 Principles of Programming I

CSCI 130 Principles of Programming I

<p>CSCI 130 Principles of Programming I Final Exam, Fall 2002 Name: ______</p><p>1. (1) In C++, a function definition may have another function definition nested within it. A) True B) False</p><p>2. (1) With argument passage by reference, the address of the caller's argument is sent to the function. A) True B) False</p><p>3. (1) Which of the following is not a reason why programmers write their own functions? A) to help organize and clarify programs B) to make programs execute faster than they would with sequential flow of control C) to allow the reuse of the same code (function) within the same program D) to allow the reuse of the same code (function) within another program 4. (1) When arguments are passed between the calling code and the called function, parameters and their corresponding arguments are matched by: A) their data types B) their relative positions in the parameter and argument lists C) their names D) whether they are inputs to or outputs from the function </p><p>5. (1) Given the function prototype</p><p> void Fix( int&, float );</p><p> which of the following is an appropriate function call? (someInt is of type int, and someFloat is of type float.) A) Fix(24, 6.85); B) someFloat = 0.3 * Fix(someInt, 6.85); C) Fix(someInt + 5, someFloat); D) a and c above E) none of the above </p><p>6. (1) The scope of an identifier does not include any nested block that contains a locally declared identifier with the same name. A) True B) False</p><p>7. (4) Explain the following: Global Variables:</p><p>Advantage/Disadvantage of Global Variables:</p><p>Local Variables:</p><p>Advantage/Disadvantage of Local variables 8. (1) The body of a Do-While loop will always execute at least once, whereas the body of a For loop may never execute. A) True B) False</p><p>9. (1) What is the output of the following code fragment? (beta is of type int.)</p><p> beta = 5; do { switch (beta) { case 1 : cout << 'R'; break; case 2 : case 4 : cout << 'O'; break; case 5 : cout << 'L'; } beta--; } while (beta > 1); cout << 'X'; A) X B) ROOLX C) LOOX D) LOORX E) ROOX </p><p>10. (1) What is the output of the following code fragment? (loopCount is of type int.)</p><p> for (loopCount = 1; loopCount > 3; loopCount++) cout << loopCount << ' '; cout << "Done" << endl; A) Done B) 1 Done C) 1 2 Done D) 1 2 3 Done E) 1 2 3 4 Done </p><p>11. (1) What is the output of the following code fragment? (All variables are of type int.)</p><p> n = 2; for (loopCount = 1; loopCount <= 3; loopCount++) while (n <= 4) n = 2 * n; cout << n << endl; A) 4 B) 8 C) 16 D) 32 E) 64 12. (1) Alphanumeric characters are stored in the computer as integers. A) True B) False</p><p>13. (1) Because of representational error, two floating-point numbers should not be compared for exact equality. A) True B) False</p><p>14. (1) Which of the following stores into min the smaller of alpha and beta? A) if (alpha < beta) min = alpha; else min = beta; B) min = (alpha < beta) ? beta : alpha; C) min = (alpha < beta) ? alpha : beta; D) a and b above E) a and c above </p><p>15. (1) Given the declarations</p><p> enum Days {YESTERDAY, TODAY, TOMORROW}; days day = TODAY;</p><p> what is the value of the expression int(day) ? A) TODAY D) 2 B) 1 E) none of the above C) TOMORROW </p><p>16. (1) Assume you have the following declarations:</p><p> enum StudentType {MARY, JANE, BILL}; StudentType oneStudent;</p><p> and that oneStudent has been assigned some value. Which of the following outputs Jane's name if oneStudent contains the value JANE? A) if (oneStudent == JANE) cout << oneStudent; B) if (oneStudent == "JANE") cout << StudentType(oneStudent); C) if (oneStudent == JANE) cout << JANE; D) if (oneStudent == "JANE") cout << "JANE"; E) if (oneStudent == JANE) cout << "JANE"; </p><p>17. (1) You have created some useful type declarations and constant declarations and have stored them into a file named mystuff.h. Which of the following would you use to insert the contents of this file into a program? A) #include <mystuff.h> B) #include "mystuff.h" C) #include mystuff.h D) #insert mystuff.h 18. (8) Write a program to read in the number of students in public colleges and private colleges from the standard input, and display the percentage of college students attending public colleges. Write the following functions: 1. A void function that gets the data from the user. 2. A value returning function to calculate the percentage. 3. A void function that prints the answer. Do not use global variables.</p><p>19. (7) Write a program that requests a number and displays a hollow rectangle of asterisks with each outer row and column having that many stars.</p><p>For example, the user types in 5, your program prints out:</p><p>***** Remember this is a sample, if your program only prints out a box with sides of 5 stars * * you won’t receive any credit. * * * * ***** Answers:</p><p>1. B 2. A 3. B 4. B 5. E 6. False 8. A 9. C 10. A 11. B 12. A 13. A 14. E 15. B 16. E 17. B</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us