CS 1323 Section 30, Spring 1997

Individual Project 2
Shifts and Penultimates

Due Wednesday, Jan 29, 4:29pm

- late papers penalized one grade per day or part of day, beginning 4:30pm Jan29 -
Caution: It is unwise wait until after 1:00pm on the due date to print the copy of your script that you plan to turn in.
Things often go wrong that you can't anticipate.

Ground Rules What to Hand In (see also: example project solution)

Project 2A

Define a function called "nextToLast" that delivers the next to last element of a sequence (assuming the sequence has at least two elements - your function needn't work if the sequence has one element or none).

Your definition of nextToLast may use the function rightCircularShift, whose properties are described in Project 2C. To test your definition of nextToLast, download the file Project2ABS, pport.lhs from Supplied Software, and put following directive at the beginning of your Haskell script:

     import Project2ABS, pport(rightCircularShift)
This will give your program access to the rightCircularShift function.

Project 2B

Define a function called "thirdFromLast" that delivers the third from last element of a sequence (assuming the sequence has at least three elements - your function needn't work if the sequence has two or fewer elements).

Your definition of thirdFromLast may use the function rightCircularShift, whose properties are described in Project 2C. To test your definition of thirdFromLast, download Project2ABS, pport.lhs and import the function rightCircularShift, as described in Project 2A.

Project 2C

Define a function called "rightCircularShift" that delivers a sequence like its argument, except that all of the elements are shifted one place toward the end of the sequence and the last element is rotated to the beginning. That is,
rightCircularShift[a, b, c, ..., x, y, z] = [z, a, b, c, ..., x, y]

Your definition may use the function leftCircularShift, which rotates a sequence in the other direction: what was the second element becomes the first, what was third becomes second, etc. ... and what was first becomes last. That is,

leftCircularShift[a, b, c, ..., x, y, z] = [b, c, ..., x, y, z, a]

To test your definition of rightCircularShift, download the file Project2CSupport.lhs from Supplied Software, and put following directive at the beginning of your Haskell script:

     import Project2CSupport(leftCircularShift)
This will give your program access to the leftCircularShift function.

You may not use the definition of rightCircularShift supplied for the people doing Projects 2A and 2B. That definition uses aspects of Haskell that are off limits for this project because they are not covered in Lessons 1-6.


CS 1323 Section 30 - Fundamentals of Computer Programming - Spring 1997
Instructor: Rex Page (Email: page@ou.edu)
Up to: Welcome Page ~~~ Up to: University of Oklahoma ~~~ Go to: Next Semester ~~~ Go to: Previous Semester