CS 172 Lab 4: Using and designing subprograms
In this lab you will use existing subprograms and write your own given a
specification. If you look carefully, you may find code in this lab
that will be particularly relevant to your first standalone
programming assignment. Reading chapters 3 through 6 will help with
the unfamiliar Ada concepts you might encounter in this lab. (Note
the rapid increase in the speed at which we are covering material. . .)
- Launch Windows Explorer. Remember
to set the View Options so that known file extensions are NOT
hidden. View your Y:\Ada subdirectory.
- Save the following link:
CalendarLab.adb
Save the file as Y:\Ada\CalendarLab.adb
View the directory
listing in Windows NT Explorer to confirm that the file is now in
your Y:\Ada subdirectory.
- Launch AdaGIDE. Open the file you just created,
Y:\Ada\CalendarLab.adb.
- The code is an Ada program that has comments that indicate
what its functionality should be. This program gets a date from the
user, as well as a non-negative number of days. It outputs the date
that results from adding the number of days to the original date.
- You need to extend and complete this program by:
- Completing the MonthLength function to return the correct number
of days given a particular month number (1 to 12). You can always
return 28 for February.
- Complete the GetValidDate procedure by asking the user for a day,
month and year, then using the ValidDate function to make sure that
the entered date is valid. If it is, exit the loop, otherwise ask
the user to try again.
- Given an example of its invocation in the main program,
implement from scratch the OutputDate procedure. This procedure
should output the given date to the screen in a readable format.
- You will also find it to your advantage to try to understand how
the rest of this program works, particularly the ValidDate function.
This function is not exactly what is required for your first program,
but it is pretty close. You should be able to understand the AddDays
procedure as well. What kind of loop does it use?
- When you are ready you should bring me:
- a printout of your program listing and
- upload your source code