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
- Three projects are described below, a different one for each
team member. Team members listed first or fourth on
their team's roster
must do Project 2A; those listed second or fifth,
Project 2B; third or sixth, Project 2C.
- In addition to aspects of Haskell discussed in
Lessons 1-6 of the Haskell text, you may, if you find
it convenient, use the intrinsic
"++"
operator, which builds a sequence by concatenating its
right-hand operand onto the end of its left-hand operand:
[a, b, c, ..., x, y, z] ++ [u, v, w, ...] =
[a, b, c, ..., x, y, z, u, v, w, ...]
You may also use the intrinsic function "head", which delivers
the first element of its argument, which must be a non-empty
sequence:
head[a, b, c, ...] = a
You will also need to use import directives (as described
in each project) to get access to
software supplied for this project.
You must not use any
other aspects of Haskell not discussed in Lessons 1-6 of
the Haskell textbook.
- Read the
Code of Conduct
for ground rules that apply to all
projects.
- Re-read the
Project Style Guide
to learn about new
requirements for session transcripts.
What to Hand In (see also:
example project solution)
- Turn in a
listing
of the Haskell script you write for your
project, following the required
standards.
- Turn in a
session transcript
in which you show
that your function operates correctly on arguments
chosen to demonstrate the function's capabilities.
- Explain (handwritten on the transcript) what
aspects of the function's behavior are illustrated by each of
your choices of
demonstration examples.
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