Guest User

Untitled

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. 1: Ashley | 01033438392 | Wellington, New Zealand | 1987- 4-14
  2. 2: Aloha | 01087651234 | Hawaii, United States of America | 1988- 9-23
  3. 3: Jack | 01082840184 | Beijing, China | 1989- 6-19
  4.  
  5. printf("%10s | %11s | %20s | %4d-%2d-%2dn",name,phone,address,year,month,day);
  6.  
  7. package Integer_IO is new Ada.Text_IO.Integer_IO (Integer);
  8.  
  9. procedure Output_Date ( Day : in Integer; Month: in Integer; Year: in Integer) is
  10. begin
  11. Integer_IO.Put(Item => Day, Width => 2);
  12. Text_IO.Put("-");
  13. Integer_IO.Put(Item => Month, Width => 2);
  14. Text_IO.Put("-");
  15. Integer_IO.Put(Item => Year, Width => 4);
  16. end Output_Date;
  17.  
  18. procedure Output_String ( Item : in String;
  19. Width : in Integer;
  20. Separator : in String := "|";
  21. Truncate : Boolean := False) is
  22. Field_Index : Integer := Text_IO.Col;
  23. begin
  24. if Item'length > Width and Truncate then
  25. Text_IO.Put(Item(1..Width) & Separator);
  26. else
  27. Text_IO.Put(Item) & Separator;
  28. end if;
  29.  
  30. Text_IO.Set_Col ( Field_Index + Width + 1 );
  31. end Output_String;
  32.  
  33. Name : String := "Ashley"
  34. Phone : String := "01033438392"
  35. Address: String := "Wellington, New Zealand"
  36.  
  37. Day : Integer := 14;
  38. Month : Integer := 4;
  39. Year : Integer := 1987;
  40.  
  41. Output_String(Item=> Name, Width => 10);
  42. Output_String(Item=> Phone, Width => 11);
  43. Output_String(Item=> Address, Width => 20);
  44. Output_Date(Day,Month,Year);
  45.  
  46. Fill_Char : Character := ' ';
  47.  
  48. function Set_Fill (New_Fill : Character) return String is
  49. begin
  50. Fill_Char := New_Fill;
  51. return "";
  52. end Set_Fill;
  53.  
  54. --// Dumb tail-recursive implementation.
  55. function Set_Width(Source : in String; Width : in Positive) return String is
  56. begin
  57. if Width <= Source'length then --'
  58. return Source;
  59. else
  60. return Fill_Char & Set_Width(Source, Width - 1);
  61. end if;
  62. end Set_Width;
  63.  
  64. Unfilled_String : constant String := "123456";
  65. Filled_String : constant String := Set_Width(Unfilled_String & Set_Fill('0'), 8);
  66. --// The above string should end up being "00123456"
  67.  
  68. function Label (J : Integer) return String is
  69. use Ada.Strings; use Ada.Strings.Fixed;
  70. Lower : String := Integer'Image(J * Bin_Size);
  71. Upper : String := Integer'Image((J + 1) * Bin_Size);
  72. begin
  73. return Tail(Trim(Lower, Left), 4, '0') & "-" &
  74. Tail(Trim(Upper, Left), 4, '0') & " |*";
  75. end Label;
  76.  
  77. Distribution of lengths:
  78. 0000-0100 |**********
  79. 0100-0200 |*****************************
  80. 0200-0300 |**********************
  81. 0300-0400 |***************
  82. 0400-0500 |**********
  83. 0500-0600 |*******
  84. 0600-0700 |****
  85. 0700-0800 |****
  86. 0800-0900 |**
  87. 0900-1000 |**
  88. 1000-1100 |*
  89. 1100-1200 |*
  90.  
  91. Ashley--
  92. Aloha---
  93. Jack----
  94. --Ashley
  95. ---Aloha
  96. ----Jack
  97.  
  98. 95: Ashley | 0001033438392 | Wellington, New Zeal 2015- 5- 24
  99. 96: Aloha | 0001087651234 | Hawaii, United State 2015- 5- 27
  100. 97: Jack | 0001082840184 | Beijing, China 2015- 5- 30
  101. 1220: Ashley | 0001033438392 | Wellington, New Zeal 2015- 6- 2
  102. 1221: Aloha | 0001087651234 | Hawaii, United State 2015- 6- 5
  103. 1222: Jack | 0001082840184 | Beijing, China 2015- 6- 8
  104.  
  105. -- This package add support for formatted string as supported by C printf()
  106.  
  107. -- A simple usage is:
  108. --
  109. -- Put_Line (-(+"%s" & "a string"));
  110. --
  111. -- or with a constant for the format:
  112. --
  113. -- declare
  114. -- Format : constant Formatted_String := +"%s";
  115. -- begin
  116. -- Put_Line (-(Format & "a string"));
  117. -- end;
  118. --
  119. -- Finally a more complex example:
  120. --
  121. -- declare
  122. -- F : Formatted_String := +"['%c' ; %10d]";
  123. -- C : Character := 'v';
  124. -- I : Integer := 98;
  125. -- begin
  126. -- F := F & C & I;
  127. -- Put_Line (-F);
  128. -- end;
  129.  
  130. -- Which will display:
  131.  
  132. -- ['v' ; 98]
  133.  
  134. -- Each format specifier is: %[flags][width][.precision][length]specifier
  135.  
  136. -- Specifiers:
  137. -- d or i Signed decimal integer
  138. -- u Unsigned decimal integer
  139. -- o Unsigned octal
  140. -- x Unsigned hexadecimal integer
  141. -- X Unsigned hexadecimal integer (uppercase)
  142. -- f Decimal floating point, lowercase
  143. -- F Decimal floating point, uppercase
  144. -- e Scientific notation (mantissa/exponent), lowercase
  145. -- E Scientific notation (mantissa/exponent), uppercase
  146. -- g Use the shortest representation: %e or %f
  147. -- G Use the shortest representation: %E or %F
  148. -- c Character
  149. -- s String of characters
  150. -- p Pointer address
  151. -- % A % followed by another % character will write a single %
  152.  
  153. -- Flags:
  154.  
  155. -- - Left-justify within the given field width;
  156. -- Right justification is the default.
  157.  
  158. -- + Forces to preceed the result with a plus or minus sign (+ or -)
  159. -- even for positive numbers. By default, only negative numbers
  160. -- are preceded with a - sign.
  161.  
  162. -- (space) If no sign is going to be written, a blank space is inserted
  163. -- before the value.
  164.  
  165. -- # Used with o, x or X specifiers the value is preceeded with
  166. -- 0, 0x or 0X respectively for values different than zero.
  167. -- Used with a, A, e, E, f, F, g or G it forces the written
  168. -- output to contain a decimal point even if no more digits
  169. -- follow. By default, if no digits follow, no decimal point is
  170. -- written.
  171.  
  172. -- ~ As above, but using Ada style based <base>#<number>#
  173.  
  174. -- 0 Left-pads the number with zeroes (0) instead of spaces when
  175. -- padding is specified.
  176.  
  177. -- Width:
  178. -- number Minimum number of characters to be printed. If the value to
  179. -- be printed is shorter than this number, the result is padded
  180. -- with blank spaces. The value is not truncated even if the
  181. -- result is larger.
  182.  
  183. -- * The width is not specified in the format string, but as an
  184. -- additional integer value argument preceding the argument that
  185. -- has to be formatted.
  186. -- Precision:
  187. -- number For integer specifiers (d, i, o, u, x, X): precision specifies
  188. -- the minimum number of digits to be written. If the value to be
  189. -- written is shorter than this number, the result is padded with
  190. -- leading zeros. The value is not truncated even if the result
  191. -- is longer. A precision of 0 means that no character is written
  192. -- for the value 0.
  193.  
  194. -- For e, E, f and F specifiers: this is the number of digits to
  195. -- be printed after the decimal point (by default, this is 6).
  196. -- For g and G specifiers: This is the maximum number of
  197. -- significant digits to be printed.
  198.  
  199. -- For s: this is the maximum number of characters to be printed.
  200. -- By default all characters are printed until the ending null
  201. -- character is encountered.
  202.  
  203. -- If the period is specified without an explicit value for
  204. -- precision, 0 is assumed.
  205.  
  206. -- .* The precision is not specified in the format string, but as an
  207. -- additional integer value argument preceding the argument that
  208. -- has to be formatted.
Add Comment
Please, Sign In to add comment