CSci 370 Homework #1

Due: Wednesday, September 20, 2016

The Written Problems section is due in class on the due date.
The Programming Problems section is due to me by e-mail no later than 11:59 pm - see the Deliverables section below.
This assignment is worth 34 points.

Reading.  King: Skim through Chapters 7-9 (arrays and functions) to make sure you have the idea. Then study Chapters 11 and 13 in depth. 

Written Problems (18 points).

  1. (2+2 points) King, page 121: Exercises 2 and 8

  2. (2+3 points) King, page 157: Exercises 4 and 13
  3. (4 points) King, page 255: Exercise 2 but omit part (e)
  4. (3 points) King, page 255: Exercise 3. Assume the formal parameters given are declared correctly.

  5. (2 points) We said in class that C does not check the bounds of arrays, so the programmer has to remember to do that.  The function getline1 (attached) reads a line of input and stores it in the array str. This function is considered safe because it stops reading characters when the array is full.  Briefly explain how the function does this, showing the line of code where the check occurs.

Programming Programs (16 points).

  1. (4 points) Use printf and scanf to write a program that accepts as input a date of the form mm/dd/yyyy. Use three integers to hold each part of the date. Now display it in the ISO Standard Format for dates: yyyy-mm-dd. Ensure that the output date uses exactly 2 characters to display the month and day. An example run (user input is underlined):

    Enter a date (mm/dd/yyyy): 2/3/2011
    You entered the date 2011-02-03

  2. (6 points) Write a program which prompts the user for a number of two-dimensional points to enter, and then in a loop, prompt for the label and X and Y coordinates of that number of points. For example, if the user enters 6 as the number of points, your input loop will execute six times. The points will go into an array of struct Point.

    After entering the points, your program will compute the distance between each pair of points. Output the two closest points, the two points that are farthest apart, along with their distances.  Make use of point.h and point.c from HW 0.
  3. (6 points) King, page 122: Programming Project 1. Use an array.


  1. Combine your source code and screenshots only into a zip file.  No executable or objects files, please!
  2. E-mail your zip file to the instructor as an attachment for testing
  3. Turn in a printout of the source code in class or in the box outside my office door