CS 1101: Lab 1

Lab Motivation and Goals

By the end of this lab, you should be able to:

Exercises

The registrar keeps information on various categories of students. Specifically, the school has graduate, undergraduate, and non-degree students. The registrar records a name for every student. For undergraduates, it also records their expected graduation year, major, and units completed. For graduates, it also records which degree they are seeking (MS or PhD), their department, and the number of credits they've earned. For non-degree students, it records the number of courses they have taken.

  1. Develop a data definition for (the general category of) students. Support all of the types of students and corresponding information described above. Give several examples of students.

  2. Write the template over students.

  3. Write a function update-completed that consumes a student and the number of courses they have finished (for the term or semester) and produces a student. The output student should have the same data as the original except for the number of units, credits, or courses completed (which should be added to the newly completed work). Undergraduates receive 1/3 unit per course finished, graduates receive 3 credits per course finished.

  4. Write a function ready-to-graduate? that consumes a student and produces a boolean indicating whether that student is ready to graduate. Undergraduates need 15 units. Graduates need 33 credits if they are seeking an MS degree and 90 credits if they are seeking a PhD. Non-degree students are never ready to graduate.

    Everyone should be able to finish up to this point.

  5. Write a function graduate-if-finish-all? that consumes a student and the number of courses the student is currently taking and produces a boolean indicating whether the student will be ready to graduate after finishing the given number of courses.

Now we are going to define data models and programs for geometric shapes on a coordinate plane. Start with a set of shapes containing circles and rectangles. A circle needs a center point and a radius; a rectangle needs the point at the top-left corner, a width, and a height.

DrScheme provides a built-in define-struct for coordinates:

                  (define-struct posn (x y))

Do not type this into your definitions window -- it is built in! You should use posns to capture coordinates in the following exercises.

  1. Develop a data definition for shapes. Write down any define-structs necessary to support your definitions.

  2. Write a program area which consumes a shape and produces a number (the area of the shape). Be sure to test your program on both circles and rectangles.

  3. Write a program move-shape which consumes a shape and two numbers and produces a shape. The first number is the amount to move the shape along the x-axis and the second number is the amount to move the shape along the y-axis.

  4. Drawing packages usually allow you to glue several shapes together so they can be manipulated as one shape. Add a compound-shape type to your list of shapes, where a compound-shape glues two existing shapes together. Add the appropriate data definitions and modify your existing data definitions accordingly. Then modify your move-shape function to also handle compound-shapes.


Back to the Labs page