CS35: Project 2

CS35: Programming and Problem Solving
Ray Ontko
Department of Computer Science
Earlham College

Due Friday, 1999/10/08

Choose one of the following programming projects. Write a program which implements the described functionality, and test it on one or more input files of your choosing. Turn in a print-out of the working program, a print-out of the input file, and a print-out of the output of your program (or, you can send all three to me in an e-mail).

  1. Imagine that you work in the data center for the Peace Corps. You are in charge of cleaning up some of the data entered on web pages by people interested in volunteering or who need to be called back for one reason or another. Unfortunately, the telephone numbers are entered any-which-way.

    You have been given a file containing phone numbers, one per line, some of which are all numeric (e.g., "9354283"), some of which include punctuation (e.g., "(765)935-4283"), and some of which even include letters (e.g., "1-800-Eat-Dirt"). Your job is to clean these up and translate them into their "digits only" representation (e.g., "9354283", "7659354283", and "18003283478"). You need a program to help.

    Write a program which reads character input and prints the character if it is a digit or newline, translates letters (upper or lowercase) to print the appropriate digit according to the table below, and ignores all other characters (including Q, Z, and punctuation).

    A B C D E F G H I J K L M N O P R S T U V W X Y
    2 3 4 5 6 7 8 9

    The dialogue from your program should look something like this:

    $ ./fix_phone < phones.txt
    9354283
    7659354283
    18003283478
    

    Of course, you will need to create your own data file to test the various inputs.

  2. Imagine you are doing some demographics research and the Office of the Clerk of Wayne County has prepared a file containing all the dates on which marriages have occurred between January 1, 1901 and September 11, 1999. As you review the file, you notice that some of the dates are dubious (e.g., "13/15/1958"). You wonder, how many of the dates are bad? You need a program to help.

    Write a program which reads a file and counts the number of dates which have invalid month numbers (i.e., not 1..12), invalid days numbers (i.e., less than 1 or more than the number of days in the month (be sure to account for leap years)), or a year which is less than 1901 or more than 1999. If a date is invalid for any reason, it should be printed.

    The dialogue from your program should look something like this:

    $ ./check_dates < marriages.dat
    13/15/1958
    2/29/1959
    
    2 bad dates found.
    

    You may find this scanf statement handy:

    scanf("%d/%d/%d", &month , &day , &year )
    

    Of course, you will need to create your own data file to test the various inputs.

Copyright © 1999, Ray Ontko (rayo@ontko.com).