CSC 161 Grinnell College Spring, 2010
 
Imperative Problem Solving and Data Structures
 

Laboratory Exercise on Conditionals in C

Goals

This laboratory exercise provides practice with conditional (if) constructs in C.

The VIM Editor

When you started C in this course, we introduced the the Emacs Text Editor. In this lab, you are asked to use the the VIM editor for your work.

After this lab, you are free to use whatever editor you wish for writing your C programs. However, you are strongly encouraged to use either emacs or VIM, since these have powerful capabilities that can help with C programming.

Steps for this Lab

  1. Do King, Exercise 5.1 (page 93).

  2. Do King, Exercise 5.3 (page 94).

  3. Do King, Exercise 5.5 (page 94). (Be sure you can explain your answer!)

  4. Do one of the following:
    1. Do King, Programming Project 5.5 (page 96).

    2. Do King, Programming Project 5.9 (page 97).

  5. Classifying Triangles:
    [This problem is based on an exercise by Darrah Chavey, Beloit College.]

    Write a C program that reads the lengths of three sides of a triangle and prints out the classification of the triangle as follows:

    In this problem, you should assume that the input values are all numbers, although error checking may indicate some numbers are negative or zero.

  6. (Challenge Problem — Optional)
    A Baby Sitting Problem: A baby sitter charges $1.50 per hour until 9:00 pm (while the kids are still up), $1.00 per hour between 9:00 pm and midnight, and $1.25 per hour after midnight (since late night baby sitting interferes with morning classes).

    Write a program that reads the sitter's starting time in hours and minutes and the ending time in hours and minutes and then computes the sitter's fee. Assume all times are between 6:00 pm and 6:00 am, and hours should be entered as being between 0 and 12 (inclusive). Hours outside the range of 0 to 12 should be considered invalid.

    The following table may clarify allowed time values for this problem.

    Starting Starting Ending Ending StartingEnding
    Hour Minutes Hour Minutes Time time
    8 0 3 30 8:00pm 3:30am
    6 0 0 45 6:00pm 12:45am
    12 0 6 0 12:00am (midnight) 6:00am

    Additional Notes:

    1. As illustrated in this table, an hour of 0 or 12 is interpreted the same, as midnight.
    2. You may not use a 24 hour clock for this problem.
    3. Times must be given in hours and minutes (as two nonnegative integer values).


This document is available on the World Wide Web as

     http://www.cs.grinnell.edu/~walker/courses/161.sp10/lab-if-c.shtml

created 31 August 1998
last revised 6 February 2010
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.