Finalspring2003 - NAME NET ID page 1 Final CS100J 09:0011:30 Barton Hall East 8 May 2003 The results of this Final will be posted on CMS as soon as

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

View Full Document Right Arrow Icon
NAME _____________________________________ NET ID ______________________ page 1 Final CS100J 09:00–11:30 Barton Hall East 8 May 2003 The results of this Final will be posted on CMS as soon as it is graded, hopefully this evening. Grades for the course may be available Friday, but it may be Monday. Please submit any regrade requests using CMS where where possible (or by emailing [email protected] where it is not possible) BEFORE 6PM TONIGHT. THIS FINAL EXAMINATION You have 2.5 hours to complete the questions in this exam. The questions are numbered 0. .8. Please glance through the whole exam before starting. The exam is worth a total of 100 points. Question 0 (1 point). Print your name and net id at the top of each page. Please make them legible. Question 1 (10 points). Algorithms. Write the loga- rithmic algorithm to store a b (a multiplied by itself b times) in int variable z. Assume all variables are int var- iables and that b 0. DON’T write a method. Just write the statements that perform the task. You are expected to write the loop invariant first and then to develop the loop from the invariant. Question 2 (10 points). Strings and methods. A palindrome is a string that reads the same backward and forward. Here are examples of palindromes: “a”, “aa”, “aba”, “abba”. This string is not a palindrome: “abb”. Note that if a palindrome is not empty, its first and last characters are the same. Write a function that has a String parameter c and returns the ( boolean ) value of the sentence “c is a palindrome”. Do not write a function that reverses a string (or anything like that). If you write a loop, it will help you (and us) if you write the invariant of the loop, but you don’t have to. Question 3 (10 points). Arrays and methods. An array b of type int [][] is rectangular if all its rows have the same number of elements and square if the number of elements in each row is the same as the number of rows. Thus, a square array is also rectangular. Note that an array with 0 rows is square. Write a method that has b as a parameter and returns 2 if b is square, 1 if b is rectangular but not square, and 0 otherwise. If you write a loop, it will help you (and us) if you write the invariant of the loop, but you don’t have to. Question 4 (09 points). Loops and invariants
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/01/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

Page1 / 4

Finalspring2003 - NAME NET ID page 1 Final CS100J 09:0011:30 Barton Hall East 8 May 2003 The results of this Final will be posted on CMS as soon as

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

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