finalfall2006 - Final CS100J Fall 2006 NAME NET ID page 1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Final CS100J, Fall 2006 NAME NET ID page 1 Grades for the final will be posted on the CMS tomorrow night, late. Grades for the course will take a few days more. You can look at your final when you return in the Spring. Thanks for taking the course. HAVE A NICE WINTER BREAK! You have 2.5 hours to complete the questions in this exam, which are numbered 0. .7. Please glance through the whole exam before starting. The exam is worth 100 points. Question 0 (1 point). Print your name and net id at the top of each page. Please make them legible. Question 1 (12 points). Algorithms. Write algorithm partition as a function, complete with method header (giving the parameters, for example) and a suitable specification —a precondition and a postcondition. Remember that the function has to return an int . You may give the pre- and post-conditions as formulas or as pictures. You must write an invariant, and the loop you write must be developed from the invariant and pre- and post-conditions. If you have to swap two variables x and y (say), just write “swap x and y”; you need not write the se- quence of three statements to swap them. Question 0. _________ (out of 01) Question 1. _________ (out of 12) Question 2. _________ (out of 12) Question 3. _________ (out of 15) Question 4. _________ (out of 12) Question 5. _________ (out of 24) Question 6. _________ (out of 12) Question 7. _________ (out of 12) Total ___________ (out of 100)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Final CS100J, Fall 2006 NAME NET ID page 2 Question 2 (12 points). Loops. Write a single loop (with initialization) to remove even integers from int array segment b[h. .k], as indicated by the following precondition and postcondition. For example, for b[h. .k] = {1, 7, 6, 8, 3, 2, 5} , execution of the algorithm sets p t o h+4 (because there are 4 odd values) and changes b[h. .k] to this: {1, 7, 3, 5, 3, 2, 5} . The first four values in b[h. .k] are the elements of the original b[h. .k] but with the even integers removed. The last part b[p. .k] is unchanged. Write one loop (with initialization) that performs the task. Do not declare any variables; assume they are all declared. You must use the invariant shown below. Do not use any variables (except those shown in the invariant) outside the loop. Read the invariant carefully before proceeding. Note that we are not ask- ing for a method, so do not write return statements. Follow the four loopy questions, and you will do well
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2008 for the course ENGRI 1101 taught by Professor Trotter during the Spring '05 term at Cornell.

Page1 / 8

finalfall2006 - Final CS100J Fall 2006 NAME NET ID page 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online