
C8-1
Algorithm
1. Use a subtype to represent the numbers for months
2. Use an enumeration to represent the named months
3. Use an enumeration to represent the roman months
4. Get the inputs from the user
5. Convert the month into roman and named formats using
a. New_Type_Package’Val(Month_Type’Pos(Month) –1);
6. Display the months in all three formats to the user.
Note: The enumerations range from 0 to (number_of_elements_in_Enumeration –1).
Code Listing
Compiling: c:/docume~2/jk/desktop/16070/codeso~1/translate_dates.adb (source file time stamp: 2003-09-
24 01:35:00)
1. --------------------------------------------------------------------
2. -- Program to accept different date formats
3. -- Programmer : Jayakanth Srinivasan
4. -- Date Last Modified : 09-23-2003
5. --------------------------------------------------------------------
6.
7. with Ada.Text_Io;
8. with Ada.Integer_Text_Io;
9.
10. procedure Translate_Dates is
11. --use a subtype to limit the date to be between 1 and 31.
12. subtype Date_Type is Integer range 1..31;
13. -- use a subtype to limit the month to be between 1 and 12
14. subtype Month_Type is Integer range 1..12;
15.
16. -- define an enumeration type for roman months
17. type Roman_Month_Type is
18. (I,
19. Ii,
20. Iii,
21. Iv,
22. V,
23. Vi,
24. Vii,
25. Viii,
26. Ix,
27. X,
28. Xi,
29. Xii);
30.
31. -- define an enumeration type for names of months
32. type Named_Month_Type is