Strongly typed language
Colors
Goal: create a package to represent HTML colors in hexadecimal form and its corresponding names.
Steps:
Implement the
Color_Types
package.
Declare the
HTML_Color
enumerationDeclare the
Basic_HTML_Color
enumeration.Implement the
To_Integer
function.Implement the
To_HTML_Color
function.
Requirements:
Enumeration
HTML_Color
has the following colors:
Salmon
Firebrick
Red
Darkred
Lime
Forestgreen
Green
Darkgreen
Blue
Mediumblue
Darkblue
Enumeration
Basic_HTML_Color
has the following colors: Red, Green, Blue.Function
To_Integer
converts from theHTML_Color
type to the HTML color code — as integer values in hexadecimal notation.
You can find the HTML color codes in the table below.
Function
To_HTML_Color
converts fromBasic_HTML_Color
toHTML_Color
.This is the table to convert from an HTML color to a HTML color code in hexadecimal notation:
Color
HTML color code (hexa)
Salmon
#FA8072
Firebrick
#B22222
Red
#FF0000
Darkred
#8B0000
Lime
#00FF00
Forestgreen
#228B22
Green
#008000
Darkgreen
#006400
Blue
#0000FF
Mediumblue
#0000CD
Darkblue
#00008B
Remarks:
In order to express the hexadecimal values above in Ada, use the following syntax:
16#<hex_value>#
(e.g.:16#FFFFFF#
).For function
To_Integer
, you may use acase
for this.
Integers
Goal: implement a package with various integer types.
Steps:
Implement the
Int_Types
package.
Declare the integer type
I_100
.Declare the modular type
U_100
.Implement the
To_I_100
function to convert from theU_100
type.Implement the
To_U_100
function to convert from theI_100
type.Declare the derived type
D_50
.Declare the subtype
S_50
.Implement the
To_D_50
function to convert from theI_100
type.Implement the
To_S_50
function to convert from theI_100
type.Implement the
To_I_100
function to convert from theD_50
type.
Requirements:
Types
I_100
andU_100
have values between 0 and 100.
Type
I_100
is an integer type.Type
U_100
is a modular type.Function
To_I_100
converts from theU_100
type to theI_100
type.Function
To_U_100
converts from theI_100
type to theU_100
type.Types
D_50
andS_50
have values between 10 and 50 and useI_100
as a base type.
D_50
is a derived type.
S_50
is a subtype.Function
To_D_50
converts from theI_100
type to theD_50
type.Function
To_S_50
converts from theI_100
type to theS_50
type.Functions
To_D_50
andTo_S_50
saturate the input values if they are out of range.
If the input is less than 10 the output should be 10.
If the input is greater than 50 the output should be 50.
Function
To_I_100
converts from theD_50
type to theI_100
type.
Remarks:
For the implementation of functions
To_D_50
andTo_S_50
, you may use the type attributesD_50'First
andD_50'Last
:D_50'First
indicates the minimum value of theD_50
type.D_50'Last
indicates the maximum value of theD_50
type.The same attributes are available for the
S_50
type (S_50'First
andS_50'Last
).
We could have implement a function
To_I_100
as well to convert fromS_100
toI_100
. However, we skip this here because explicit conversions are not needed for subtypes.
Temperatures
Goal: create a package to handle temperatures in Celsius and Kelvin.
Steps:
Implement the
Temperature_Types
package.
Declare the
Celsius
type.Declare the
Int_Celsius
type.Implement the
To_Celsius
function.Implement the
To_Int_Celsius
function.Declare the
Kelvin
typeImplement the
To_Celsius
function to convert from theKelvin
type.Implement the
To_Kelvin
function.
Requirements:
The custom floating-point types declared in
Temperature_Types
must use a precision of six digits.Types
Celsius
andInt_Celsius
are used for temperatures in Celsius:
Celsius
is a floating-point type with a range between -273.15 and 5504.85
Int_Celsius
is an integer type with a range between -273 and 5505.Functions
To_Celsius
andTo_Int_Celsius
are used for type conversion:
To_Celsius
converts fromInt_Celsius
toCelsius
type.
To_Int_Celsius
converts fromCelsius
andInt_Celsius
types:
Kelvin
is a floating-point type for temperatures in Kelvin using a range between 0.0 and 5778.0.The functions
To_Celsius
andTo_Kelvin
are used to convert between temperatures inKelvin
andCelsius
.
In order to convert temperatures in Celsius to Kelvin, you must use the formula \(K = C + 273.15\), where:
K is the temperature in Kelvin, and
C is the temperature in Celsius.
Remarks:
When implementing the
To_Celsius
function for theInt_Celsius
:You'll need to check for the minimum and maximum values of the input values because of the slightly different ranges.
You may use variables of floating-point type (
Float
) for intermediate values.
For the implementation of the functions
To_Celsius
andTo_Kelvin
(used for converting betweenKelvin
andCelsius
), you may use a variable of floating-point type (Float
) for intermediate values.