Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ftoc_-_a_fahrenheit_to_celsius_converter [2011/12/16 22:18]
thomaslocke
ftoc_-_a_fahrenheit_to_celsius_converter [2012/03/06 22:20] (current)
cvanvliet fixed a few grammar erros
Line 192: Line 192:
 That right there is one of the biggest selling points of Ada: The ability to create your own types, with your own constraints. It might not seem like a big deal but, believe me, it is. In this case we've created a new [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-2-2.html|subtype]] of the built-in subtype [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-5-4.html|Natural]]. We've constrained the type's range to //0 .. 212//, meaning that objects declared as a //​Fahrenheit_Degree_Range//​ can **never** go below 0 or above 212. If a value outside this range is assigned to an object of the //​Fahrenheit_Degree_Range//​ type, a //​Constraint_Error//​ exception is raised. That right there is one of the biggest selling points of Ada: The ability to create your own types, with your own constraints. It might not seem like a big deal but, believe me, it is. In this case we've created a new [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-2-2.html|subtype]] of the built-in subtype [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-5-4.html|Natural]]. We've constrained the type's range to //0 .. 212//, meaning that objects declared as a //​Fahrenheit_Degree_Range//​ can **never** go below 0 or above 212. If a value outside this range is assigned to an object of the //​Fahrenheit_Degree_Range//​ type, a //​Constraint_Error//​ exception is raised.
  
-With the //​Fahrenheit_Degree_Range//​ type in place, we direct our attention to the declaration and assignment of the //Fahr// variable. If you've never seen this syntax before or it makes no sense to you, please read the [[Variables|and Constants]] article on this Wiki, and then return here.+With the //​Fahrenheit_Degree_Range//​ type in place, we direct our attention to the declaration and assignment of the //Fahr// variable. If you've never seen this syntax before or it makes no sense to you, please read the [[Variables and Constants]] article on this Wiki, and then return here.
  
 The //Fahr// variable is of the //​Fahrenheit_Degree_Range//​ type and it's initial value is 0. Why 0? Because we assign it the value //​Fahrenheit_Degree_Range'​First//,​ and the //'​First//​ part equals the first value in the range constraint of the type, in this case 0. Consequently the value for //​Fahrenheit_Degree_Range'​Last//​ is 212. The //Fahr// variable is of the //​Fahrenheit_Degree_Range//​ type and it's initial value is 0. Why 0? Because we assign it the value //​Fahrenheit_Degree_Range'​First//,​ and the //'​First//​ part equals the first value in the range constraint of the type, in this case 0. Consequently the value for //​Fahrenheit_Degree_Range'​Last//​ is 212.
  
-Lets take a look at the final three object declarations:​+Let'​s ​take a look at the final three object declarations:​
  
 <code ada> <code ada>
Line 233: Line 233:
 <code ada> <code ada>
 loop loop
-   some statements+   --  ​some statements
 end loop; end loop;
 </​code>​ </​code>​
Line 241: Line 241:
 <code ada> <code ada>
 loop loop
-   some statements+   --  ​some statements
    if X = Y then    if X = Y then
       exit;       exit;
Line 252: Line 252:
 <code ada> <code ada>
 loop loop
-   some statements+   --  ​some statements
    exit when X = Y;    exit when X = Y;
 end loop; end loop;
Line 272: Line 272:
 The //'​Width//​ attribute returns the maximum width of the type, so if we change the //​Fahrenheit_Degree_Range//​ later on, we wouldn'​t have to do a single thing about this call to //Put//; it would simply adjust itself accordingly. The //'​Width//​ attribute returns the maximum width of the type, so if we change the //​Fahrenheit_Degree_Range//​ later on, we wouldn'​t have to do a single thing about this call to //Put//; it would simply adjust itself accordingly.
  
-Lets do some tests with various //Width// parameters:+Let'​s ​do some tests with various //Width// parameters:
  
 <code ada> <code ada>
Line 329: Line 329:
   102  38.89   102  38.89
   103  39.44   103  39.44
- ...+  ​...
  
 As you can see, the single digit values are right-justified and padded with 1 space, the two-digit values come out even, but the rest of the results are expanded to hold the third character. As you can see, the single digit values are right-justified and padded with 1 space, the two-digit values come out even, but the rest of the results are expanded to hold the third character.
Line 347: Line 347:
 The //Fore// parameter gives the minimum character count necessary to output the value preceding the decimal point. As with //Width// for the integer types, //Fore// will automatically expand if necessary. //Aft// sets the precision after the decimal point, in this case 2. And finally //Exp// sets the exponent field size. A value of //Exp => 0// signifies that no exponent will be output. Anything other than zero will output the exponent symbol "​E",​ a +/-, and the digit(s) of the exponent. Note: The value of //Exp// should not be less than zero! The //Fore// parameter gives the minimum character count necessary to output the value preceding the decimal point. As with //Width// for the integer types, //Fore// will automatically expand if necessary. //Aft// sets the precision after the decimal point, in this case 2. And finally //Exp// sets the exponent field size. A value of //Exp => 0// signifies that no exponent will be output. Anything other than zero will output the exponent symbol "​E",​ a +/-, and the digit(s) of the exponent. Note: The value of //Exp// should not be less than zero!
  
-Lets try a few different combinations:​+Let'​s ​try a few different combinations:​
  
 <code ada> <code ada>
Line 450: Line 450:
 <code ada> <code ada>
 New_Line (5); New_Line (5);
-</codee>+</code>
  
 We've already discussed the //exit when// method of [[FtoC_-_A_Fahrenheit_to_Celsius_converter#​The_loop|terminating a loop]], and the final statement is merely a simple counter. The value of //Fahr// is incremented with //Step// on each iteration of the loop. When //Fahr// equals //​Fahrenheit_Degree_Range'​Last//,​ the loop is terminated. We've already discussed the //exit when// method of [[FtoC_-_A_Fahrenheit_to_Celsius_converter#​The_loop|terminating a loop]], and the final statement is merely a simple counter. The value of //Fahr// is incremented with //Step// on each iteration of the loop. When //Fahr// equals //​Fahrenheit_Degree_Range'​Last//,​ the loop is terminated.

Navigation