This project depends upon Chapters 1-5, and provides experience with writing loops, and with file redirection.
Write a Spider program Checker_Board, which causes the spider to draw a checkboard pattern on the screen, like
X X X X X X X X X X X X X X X X
Use loops wherever appropriate.
This part returns to calendar dates. You are to develop a program that reads a series of dates from a disk file, and, as each one is read, displays the day of the week on which that date occurs (e.g. SEPTEMBER 24, 1992 is on a THURSDAY).
In the info directory is a file called dates.dat that contains a set of dates, one per line. The first item in the file is an integer indicating how many dates are following. Here is an example of such a file:
5 Sep 1 1990 Dec 25 1987 Mar 3 1997 Feb 28 1997 Jan 1 2000
The month appears as a 3-letter enumeration literal (Jan, Feb, etc). The day appears as an integer in the predefined subtype Ada.Calendar.Day_Number; the year appears as an integer in the predefined subtype Ada.Calendar.Year_Number. In this project, you can assume that all the input is valid. That is, all the file entries are valid dates and the first item in the file states correctly how many dates are following.
To find the day of the week, use the package DayWeek in the programs directory. Here is the specification:
WITH Ada.Calendar;
PACKAGE DayWeek IS
-------------------------------------------------------------------------
--| Finds the day of the week on which a given date falls.
--| Created by Jason Guthrie 4/18/92
--| modified by Michael Feldman 4/28/92 and 9/30/96
--| The formula allows for dates within the range of package Ada.Calendar
-------------------------------------------------------------------------
SUBTYPE DaysOfWeek IS Integer RANGE 0..6;
-- numerical code for days of the week:
-- Monday = 0, Tuesday = 1, etc.
FUNCTION DayOfWeek (Month: Ada.Calendar.Month_Number;
Day : Ada.Calendar.Day_Number;
Year : Ada.Calendar.Year_Number) RETURN DaysOfWeek;
-- Pre: Month, Day, and Year are defined
-- Post: returns the day of the week corresponding to the given
-- month, day, and year. No check is made to insure that the
-- month/day/year combination form a valid date.
END DayWeek;
This package is not in the textbook. A simple demonstration program, DayTest, is in daytest.adb.
In this program, you are not reading any user input from the keyboard; rather, your program gets its input by file redirection:
gexecute find_days.exe <dates.dat
You can use ordinary Get calls to read the parts of the date; redirection instructs the input system to use the file instead of the keyboard as its input source.
This program will be much easier to do correctly if you design the algorithm carefully before starting to code!
As usual, submit the Case Study document, a printout of the
listing file, and a test run executed with turnin.