Algorithm For Displaying Date Month Year-Computer Programming-Assignment Solution, Exercises of Aeronautical Engineering

This is solution to assignment for Aeronautical Engineering and Computer Programming course. It was submitted to Prof. Chitraksh Gavde at Biju Patnaik University of Technology, Rourkela. It includes: Display, Algorithm, Subtype, Code, Month, Date, Roman, Enumeration, Ada, Boolean, Character

Typology: Exercises

2011/2012

Uploaded on 07/20/2012

savitri_122
savitri_122 🇮🇳

4.6

(14)

184 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
docsity.com
pf3

Partial preview of the text

Download Algorithm For Displaying Date Month Year-Computer Programming-Assignment Solution and more Exercises Aeronautical Engineering in PDF only on Docsity!

C8-

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. -- Program to accept different date formats
  2. -- Programmer : Jayakanth Srinivasan
  3. -- Date Last Modified : 09-23-

  4. with Ada.Text_Io;
  5. with Ada.Integer_Text_Io;
  6. procedure Translate_Dates is
  7. --use a subtype to limit the date to be between 1 and 31.
  8. subtype Date_Type is Integer range 1..31;
  9. -- use a subtype to limit the month to be between 1 and 12
  10. subtype Month_Type is Integer range 1..12;
  11. -- define an enumeration type for roman months
  12. type Roman_Month_Type is
  13. (I,
  14. Ii,
  15. Iii,
  16. Iv,
  17. V,
  18. Vi,
  19. Vii,
  20. Viii,
  21. Ix,
  22. X,
  23. Xi,
  24. Xii);
  25. -- define an enumeration type for names of months
  26. type Named_Month_Type is
  1. (January,
  2. February,
  3. March,
  4. April,
  5. May,
  6. June,
  7. July,
  8. August,
  9. September,
  10. October,
  11. November,
  12. December);
  13. -- create a package that can print the month in roman numerals
  14. package Roman_Month_Io is new Ada.Text_Io.Enumeration_Io(Enum => Roman_Month_Type);
  15. -- create a package that can print the month's name
  16. package Named_Month_Io is new Ada.Text_Io.Enumeration_Io(Enum => Named_Month_Type);
  17. Year : Integer;
  18. Date : Date_Type;
  19. Month : Month_Type;
  20. Roman_Month : Roman_Month_Type;
  21. Named_Month : Named_Month_Type;
  22. begin
  23. Ada.Text_Io.Put("Please Enter the Date 1..31 : ");
  24. Ada.Integer_Text_Io.Get(Date);
  25. Ada.Text_Io.New_Line;
  26. Ada.Text_Io.Put("PLease Enter the Month 1 ..12 : ");
  27. Ada.Integer_Text_Io.Get(Month);
  28. Ada.Text_Io.New_Line;
  29. Ada.Text_Io.Put("PLease Enter the Year: ");
  30. Ada.Integer_Text_Io.Get(Year);
  31. Ada.Text_Io.New_Line;
  32. -- convert the month into roman month
  33. Roman_Month := Roman_Month_Type'Val(Month_Type'Pos(Month)-1);
  34. -- convert the month into the name
  35. Named_Month := Named_Month_Type'Val(Month_Type'Pos(Month)-1);
  36. -- display the dates in regular format
  37. Ada.Text_Io.Put(" i. ");
  38. Ada.Integer_Text_Io.Put(Date);
  39. Ada.Text_Io.Put(" / ");
  40. Ada.Integer_Text_Io.Put(Month);
  41. Ada.Text_Io.Put(" / ");
  42. Ada.Integer_Text_Io.Put(Year);
  43. Ada.Text_Io.New_Line;
  44. -- display the date in named format
  45. Ada.Text_Io.Put(" ii. ");
  46. Ada.Integer_Text_Io.Put(Date);
  47. Ada.Text_Io.Put(" ");
  48. Named_Month_Io.Put(Named_Month);