DOC PREVIEW
Stanford CS 106A - Practice Final Examination -1

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Eric Roberts Handout #63CS 106A March 5, 2010Practice Final Examination #1Review session: Sunday, March 14, 7:00–9:00P.M. (Hewlett 201)Scheduled finals: Monday, March 15, 12:15–3:15P.M. (Hewlett 200)Friday, March 19, 12:15–3:15P.M. (Hewlett 200)This handout is intended to give you practice solving problems that are comparable informat and difficulty to those which will appear on the final examination. A solution setto this practice examination will be handed out at the optional class on Monday.(CS 106A does not hold required classes during Dead Week.)Time of the examThe final exam is scheduled at two different times during exam period, as shown at thetop of this handout. Both finals are in the regular classroom. You may take the exam ateither of the two scheduled times and need not give advance notice of which exam youplan to take. If you are unable to take the exam at either of the scheduled times, pleasesend an e-mail message to eroberts@cs stating the following:• The reason you cannot take the exam at the scheduled time.• A three-hour period on Monday or Tuesday of exam week at which youcould take the exam. This time must be during the regular working dayand must therefore start between 8:30 and 2:00.In order to take an alternate exam, I must receive this message from you by 5:00P.M. onWednesday, March 10. Replies will be sent by electronic mail on Friday, March 12.Review sessionSeveral section leaders will conduct a review session on Sunday evening from 7:00 to9:00P.M. in Hewlett 201. We’ll will announce the winners of the Adventure Contest andhold the random grand-prize drawing at the beginning of the review session.CoverageThe exam covers the material presented in class through today, which means that you areresponsible for the material in Chapters 1 through 13 of The Art and Science of Java, withthe following exceptions:• Chapter 7. There will not be any questions on the low-level representation of data asbits or any problems involving heap-stack diagrams.• Chapter 10. In this chapter, you are responsible for the material in sections 10.1, 10.2,10.3, 10.5, and 10.6. The only Swing interactors you will be expected to use are theones from FacePamphlet: JLabel, JButton, and JTextField.• Chapter 11. You are responsible for all the material in this chapter except for the bit-manipulation operators in section 11.7. Image-manipulation problems that use no bitoperations (such as the FlipHorizontal problem from Section #6) are fair game.• Chapter 12. You are responsible for the general idea of searching and sorting, aspresented in sections 12.1 and 12.2, including the binary search and selection sortalgorithms. The coverage of data files will be limited to reading a file line by line.• Chapter 13. You should understand how to use the ArrayList, HashMap, andTreeMap classes, but need not understand their implementation.– 2 –General instructionsThe instructions that will be used for the actual final look like this:Answer each of the questions given below. Write all of your answers directly onthe examination paper, including any work that you wish to be considered forpartial credit.Each question is marked with the number of points assigned to that problem. Thetotal number of points is 90. We intend that the number of points be roughlyequivalent to the number of minutes someone who is completely on top of thematerial would spend on that problem. Even so, we realize that some of you willstill feel time pressure. If you find yourself spending a lot more time on aquestion than its point value suggests, you might move on to another question tomake sure that you don’t run out of time before you’ve had a chance to work onall of them.In all questions, you may include methods or definitions that have been developedin the course, either by writing the import line for the appropriate package or bygiving the name of the method and the handout or chapter number in which thatdefinition appears.The examination is open-book, and you may make use of any texts, handouts, orcourse notes. You may not, however, use a computer of any kind.Note: To conserve trees, I have cut back on answer space for the practice exams. Theactual final will have much more room for your answers and for any scratch work.Please remember that the final is open-book.Monday, March 15, 12:15–3:15p.m. (Hewlett 200)Friday, March 19, 12:15–3:15p.m. (Hewlett 200)– 3 –Problem 1—Short answer (10 points)1a) Suppose that the integer array list has been declared and initialized as follows:private int[] list = { 10, 20, 30, 40, 50 };This declaration sets up an array of five elements with the initial values shown in thediagram below:list10 20 30 40 50 Given this array, what is the effect of calling the methodmystery(list);if mystery is defined as:private void mystery(int[] array) {int tmp = array[array.length - 1];for (int i = 1; i < array.length; i++) {array[i] = array[i - 1];}array[0] = tmp;}Work through the method carefully and indicate your answer by filling in the boxesbelow to show the final contents of list:list– 4 –1b) Suppose that you have been assigned to take over a project from another programmerwho has just been dismissed for writing buggy code. One of the methods you havebeen asked to rewrite has the following comment and prototype:/* Method: insertValue(value, array) *//** * Inserts a new value into a sorted array of integers by * creating a new array that is one element larger than the * original array and then copying the old elements into the * new array, inserting the specified value at its proper * position. * * @param value The value to be inserted into the array * @param array An array sorted in ascending order * @return A newly allocated array with value inserted in order */private int[] insertValue(int value, int[] array) {int[] result = new int[array.length + 1];for (int i = 0; i < result.length; i++) {result[i] = array[i];}int pos = 0;for (int i = 0; i < array.length; i++) {if (value > array[i]) {pos = i;break;}}for (int i = result.length; i >= pos; i--) {result[i] = result[i - 1];}result[pos] = value;return result;}Unfortunately, the code contains several bugs. Circle the bugs in the implementationand write a short sentence explaining the precise nature of each problem youidentify.– 5 –Problem 2—Using the acm.graphics library (15 points)Although the definition of filling for an arc (see page 314 in the text) is not necessarilywhat you would


View Full Document

Stanford CS 106A - Practice Final Examination -1

Download Practice Final Examination -1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Practice Final Examination -1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Practice Final Examination -1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?