SE Projects Lab #3: Package Clock_Times

Reading: On the AdaCore learning site, look over the sections on subprograms and packages. The section on record types might also be interesting. In my tutorial read sections 1.4 (subprograms) and 1.6 (packages).

In this lab you will get some practice creating an Ada package. There are no starter files for this lab, since creating the necessary files and filling them in is part of the lab experience. Follow the instructions below.

  1. Switch back to the master branch of the samples repository and then pull all available updates from GitHub into that branch. Create a new branch for Lab #3 from that point (e.g., called "lab-03"). Note: If you have uncommitted changes in the branch for the previous lab, commit those changes to the lab branch before you switch back to master.

  2. Review the files calendar_dates.ads, calendar_dates.adb, and calendar_dates_demo.adb. These files were developed during the lecture. You will be creating a new package following a similar approach.

  3. The goal will be to create a package for manipulating clock times in a manner similar to the calendar dates example. Start by creating an empty file (File > New File in GNATstudio) to hold the specification of package Clock_Times. Save this file as clock_times.ads.

  4. Fill in the specification file with the following things:

  5. Create another new file to hold the body of the package and save that file as clock_times.adb.

  6. In the body, implement the three functions declared in the specification.

  7. In the provided file clock_times_demo.adb write a main program that initializes a Clock_Time variable to 23:00:00, adds 7200 seconds to it, verifies that the new value comes before the original (due to wrap-around), and then compute the number of seconds between the two times (which should be 79200).

For this lab, zip together your specification and body of package Clock_Times, and your modified clock_times_demo.adb file, and submit the zip archive to Canvas.


Last Revised: 2022-02-03
© Copyright 2022 by Peter C. Chapin <pchapin@vtc.edu>