Records
Directions
Goal: create a package that handles directions and geometric angles.
Steps:
Implement the
Directions
package.
Declare the
Ext_Angle
record.Implement the
Display
procedure.Implement the
To_Ext_Angle
function.
Requirements:
Record
Ext_Angle
stores information about the extended angle (see remark about extended angles below).Procedure
Display
displays information about the extended angle.
You should use the implementation that has been commented out (see code below) as a starting point.
Function
To_Ext_Angle
converts a simple angle value to an extended angle (Ext_Angle
type)
Remarks:
We make use of the algorithm implemented in the
Check_Direction
procedure (chapter on imperative language).For the sake of this exercise, we use the concept of extended angles. This includes the actual geometric angle and the corresponding direction (North, South, Northwest, and so on).
Colors
Goal: create a package to represent HTML colors in RGB format using the hexadecimal form.
Steps:
Implement the
Color_Types
package.
Declare the
RGB
record.Implement the
To_RGB
function.Implement the
Image
function for theRGB
type.
Requirements:
The following table contains the HTML colors and the corresponding value in hexadecimal form for each color element:
Color
Red
Green
Blue
Salmon
#FA
#80
#72
Firebrick
#B2
#22
#22
Red
#FF
#00
#00
Darkred
#8B
#00
#00
Lime
#00
#FF
#00
Forestgreen
#22
#8B
#22
Green
#00
#80
#00
Darkgreen
#00
#64
#00
Blue
#00
#00
#FF
Mediumblue
#00
#00
#CD
Darkblue
#00
#00
#8B
The hexadecimal information of each HTML color can be mapped to three color elements: red, green and blue.
Each color element has a value between 0 and 255, or
00
andFF
in hexadecimal.For example, for the color salmon, the hexadecimal value of the color elements are:
red =
FA
,green =
80
, andblue =
72
.Record
RGB
stores information about HTML colors in RGB format, so that we can retrieve the individual color elements.Function
To_RGB
converts from theHTML_Color
enumeration to theRGB
type based on the information from the table above.Function
Image
returns a string representation of theRGB
type in this format:
"(Red => 16#..#, Green => 16#...#, Blue => 16#...# )"
Remarks:
We use the exercise on HTML colors from the previous lab on Strongly typed language as a starting point.
Inventory
Goal: create a simplified inventory system for a store to enter items and keep track of assets.
Steps:
Implement the
Inventory_Pkg
package.
Declare the
Item
record.Implement the
Init
function.Implement the
Add
procedure.
Requirements:
Record
Item
collects information about products from the store.
To keep it simple, this record only contains the name, quantity and price of each item.
The record components are:
Name
ofItem_Name
type;
Quantity
ofNatural
type;
Price
ofFloat
type.Function
Init
returns an initialized item (ofItem
type).
Function
Init
must also display the item name by calling theTo_String
function for theItem_Name
type.
This is already implemented in the code below.
Procedure
Add
adds an item to the assets.
Since we want to keep track of the assets, the implementation must accumulate the total value of each item's inventory, the result of multiplying the item quantity and its price.