Lab 5 - Spring 2019

Sorting / More Practice with Lists

The main purpose of this lab is to have:

  • More practice with lists: lists of strings and lists of structures (posn's)
  • More practice with sorting
  • More practice designing programs with wish lists (helper functions)
  • More practice documenting functions with signature, purpose statement, examples, and check-expects

How to get started

  1. Use your CS account to login to one of the Linux workstations in the classroom.

  2. Open a browser and copy/paste this URL: https://classroom.github.com/a/Os--0xCq

  3. Login to Github and you will be prompted to accept this assignment
    • Note: this will create your own copy of Lab 5 for you to work on, but it's not on your Linux account yet

  4. Open a terminal window.

  5. Create a new directory for this lab in your cs101 directory by entering the following at the Linux prompt:

    cd cs101
    mkdir lab5
    cd lab5

  6. Type the following commands to pull down a copy of this lab from GitHub:
    $ git init
    $ git remote add origin https://github.com/Vassar-cs101-mlsmith-spr2019/lab-5-yourGitHubID
    $ git pull origin master



Now you are ready to write some functions using the Design Recipe!

Instructions

  1. Launch DrRacket and open your lab5.rkt file

  2. Fill in your name where <YOUR NAME> appears in the comments at the top of the program.

  3. Develop the functions for the Exercises as described below.
    • solve each exercise in order
    • follow the steps of the Design Recipe for each function (not all exercises require designing a function).
    • be sure your solution for each exercise includes all appropriate grading artifacts.

Exercises

  1. Design a function that sorts a list of strings in ascending order. It will be a lot like the function we designed in class this week that sorts a list of numbers. Be sure to follow the Design Recipe, and include hand-in artifacts:
    1. Data Definition for a list-of-string
      1. you will find it useful to define at least two lists of strings–one unsorted, one sorted in ascending order
    2. Template for a function that consumes a list-of-string
    3. Signature/Purpose Statement/Header
    4. Examples in the form of check-expects
    5. Only when all of the above is complete should you fill in the function body
      1. As was the case with the function that sorted a list of numbers, you will need a helper function that inserts a string into a sorted list of strings.
      2. Add it to your wish list, and develop it separately, using the Design Recipe
      3. For this helper function, you will find the built-in string comparison function
        string<=?

        to be helpful

  2. Design a function that sorts a list of posns in ascending order by the posns' x value. It, too, will be a lot like the function we designed in class this week that sorts a list of numbers. Be sure to follow the Design Recipe, and include hand-in artifacts:
    1. Data Definition for a list-of-posn
      1. you will find it useful to define at least two lists of posns–one unsorted, one sorted in ascending order by the posns' x value
    2. Template for a function that consumes a list-of-posn
    3. Signature/Purpose Statement/Header
    4. Examples in the form of check-expects
    5. Only when all of the above is complete should you fill in the function body
      1. As was the case with the function that sorted a list of numbers, you will need a helper function that inserts a posn into a sorted list of posns.
      2. Add it to your wish list, and develop it separately, using the Design Recipe
      3. For this helper function, you will to use an additional helper function. Call it
        posn-x<=?

        , and add it to your wish list

      4. Finally, use the Design Recipe to design the helper function that compares two posns by their x value, and produces #true if the first posn's x value is less than or equal to the second posn's x value.
        1. The signature for this function is:
          posn-x<=? : posn posn -> bool
        2. Your function should not contain a cond expression or an if expression–only a boolean expression is required.



Get checked off! Be sure Professor Smith or one of your coaches checks you off as having completed the lab before you submit your work electronically, and before you leave. We will look for correct program behavior, as well as well-documented code, including, for each function, a signature, purpose statement, examples, and check-expect statements.

Submitting your work

From a terminal window, type the following commands at the Linux prompt:

$ git commit -m "finished lab5" lab5.rkt
$ git push -u origin master



Log out

When you are done, close DrRacket and log out. Always remember to log out when you are done using the system, to ensure that no one else uses your account.