Computer Science 15-110, Fall 2010
Class Notes: Midterm1 Review
Midterm1 Review: Sample Problems
First: Study all the notes, the hw's, and the quizzes!!!!
Solve these as many different ways as possible, including (when applicable):
- with and without conditionals (for numeric problems, especially)
- iteratively, only using "while" loops
- iteratively, only using "for" loops
- recursively
- recursively while printing stack trace
Suggested problems:
- remainder(n, r)
This
is a replacement for the % operator (which of course you may not use
here), though you may assume n and r are positive. So:
remainder(33, 7) returns 5
- nearestBusStop(street)
Returns
the nearest bus stop to the given street, where buses stop every 8th
street, including street 0, and ties go to the lower street, so:
nearestBusStop(12) returns 8
nearestBusStop(13) returns 16
- everyOtherChar(string)
Returns a string composed of every other character of the original string, so:
everyOtherChar("abcde") returns "ace"
- everyKthChar(string, k)
Returns a string composed of every kth character of the original string, or "" if k<1, so:
everyKthChar("abcdefgh", 3) returns "cf"
- everyKthLetter(string, k)
Returns a string composed of every kth letter (A-Z,a-z) of the original string, or "" if k<1, so:
everyKthLetter("a1b2c3d4e5f6g7h", 3) returns "cf"
- toInt(string)
This
is a replacement for the int function (which of course you may not use
here). It returns the int value of the string. You may
assume the string only contains digits. So:
toInt("-1234") returns -1234
- toString(n)
This
is a replacement for the str function (which of course you may not use
here) over int values. It returns the string value of the integer
parameter. So:
toString(-1234) returns "-1234"
- More ideas:
carpe diem -
carpe diem - carpe diem - carpe diem
- carpe diem - carpe diem -
carpe diem - carpe diem - carpe
diem