This post is a follow-up of a previous post:
Ada: Understanding private types and understanding packaging
I am trying to create an object named Configuration, print it on the screen so that I can see its contents and also try to access the components of this created object. It is the last part that is giving me trouble. The codes are given next:
First the package specification Rectangular_Method.ads:
package Rectangular_Method is
type Rectangular is private;
function Construct(Horz, Vert : Long_Float) return Rectangular;
procedure Print(Configuration: in Rectangular);
procedure Vector_Basis_r (A : in Long_Float; D : out Rectangular);
function Get_Horz (R : Rectangular) return Long_Float;
function Get_Vert (R : Rectangular) return Long_Float;
private
type Rectangular is
record
Horz, Vert: Long_Float;
end record;
end Rectangular_Method;
Next, the package body Rectangular_Method.adb:
with Ada.Text_IO, Ada.Long_Float_Text_IO;
with Ada.Numerics.Long_Elementary_Functions;
use Ada.Numerics.Long_Elementary_Functions;
package body Rectangular_Method is
function Construct(Horz, Vert : Long_Float) return Rectangular is
begin
return(Horz, Vert);
end Construct;
procedure Print(Configuration: in Rectangular) is
use Ada.Text_IO, Ada.Long_Float_Text_IO;
begin
Put("(");
Put(Configuration.Horz, Fore => 2, Aft => 2, Exp => 0); Put(", ");
Put(Configuration.Vert, Fore => 2, Aft => 2, Exp => 0);
Put_Line(")");
end Print;
procedure Vector_Basis_r (A : in Long_Float; D : out Rectangular) is
begin
D.Horz := Cos (A, Cycle => 360.0);
D.Vert := Sin (A, Cycle => 360.0);
end Vector_Basis_R;
function Get_Horz (R : Rectangular) return Long_Float is
begin
return R.Horz;
end Get_Horz;
function Get_Vert (R : Rectangular) return Long_Float is
begin
return R.Vert;
end Get_Vert;
end Rectangular_Method;
And finally the test file test_rectangular_form.adb:
with Ada.Long_Float_Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
with Rectangular_Form;
use type Rectangular_Form.Rectangular;
procedure Test_Rectangular_Form is
Theta : Long_Float;
Basis_r : Rectangular_Form.Rectangular;
Configuration: Rectangular_Form.Rectangular;
begin
Ada.Text_IO.Put("Enter the angle ");
Ada.Long_Float_Text_IO.Get (Item => theta);
--Vector basis
Rectangular_Form.Vector_Basis_R (A => Theta, D => Basis_R);
Configuration := Rectangular_Form.Construct(Rectangular_Form.Get_Horz (Basis_R),Rectangular_Form.Get_Vert (Basis_R));
Ada.Text_IO.New_Line;
Rectangular_Form.Print(Configuration);
end Test_Rectangular_Form;
Now the question (based on test_rectangular_form.adb):
I have created an object Configuration as shown above holding the horizontal and vertical components of Basis_R. If I want to access say the horizontal component of Configuration, the following doesn’t work:
aa := Rectangular_Form.Configuration.Rectangular.Horz;
(after defining aa to be of type Long_Float)
I have tried various expressions to access the components of the object Configuration but in vain.
Any help would be most appreciated.
Thanks…
The purpose of your Get_Horz and Get_Vert functions is to retrieve the components of your Rectangular object: