Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:51:23+00:00 2026-06-03T05:51:23+00:00

I am trying to learn how to use private declarations in Ada and also

  • 0

I am trying to learn how to use private declarations in Ada and also to understand packaging. I have tried to keep my codes as short as possible.

We start with the main file rectangular_Form.ads

with Rectangular_Method_1;
package Rectangular_Form renames Rectangular_Method_1;
-- with Rectangular_Method_2;
-- package Rectangular_Form renames Rectangular_Method_2;

This tells us that we can have two implementations and that for now Rectangular_Method_1 has been chosen.

Then we have the specifications file Rectangular_Method_1.ads:

package Rectangular_Method_1 is
   type Rectangular is private;

   procedure Vector_Basis_r (A : in Long_Float; D : out Rectangular);
   procedure Set_Horz (R : in out Rectangular; H : Long_Float);
   function Get_Horz (R : Rectangular) return Long_Float;

 private
   type Rectangular is
        record
             Horz, Vert: Long_Float;
        end record;
end Rectangular_Method_1;

and its body Rectangular_Method_1.adb:

with Ada.Numerics.Long_Elementary_Functions;
use  Ada.Numerics.Long_Elementary_Functions;

package body Rectangular_Method_1 is
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;

procedure Set_Horz (R : in out Rectangular; H : Long_Float) is
begin
  R.Horz := H;
end Set_Horz;

function Get_Horz (R : Rectangular) return Long_Float is
begin
  return R.Horz;
end Get_Horz;

end Rectangular_Method_1;

and finally the test script: 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
Component_Horz, Component_Vert, Theta  : Long_Float;
Basis_r                                : 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);
  Ada.Text_IO.New_Line;

  Ada.Text_IO.Put("rhat_min_theta = ");
  Ada.Long_Float_Text_IO.Put (Item => Rectangular_Form.Get_Horz (Basis_r), Fore => 3, Aft  => 5, Exp  => 0);
  Ada.Text_IO.Put(" ihat + ");
  Ada.Long_Float_Text_IO.Put (Item => Rectangular_Form.Get_Vert (Basis_r), Fore => 3, Aft  => 5, Exp  => 0);
  Ada.Text_IO.Put (" jhat ");
end Test_Rectangular_Form;

Question (applied to test_rectangular_form.adb):

I am getting the components A.Horz and A.Vert directly using

    Rectangular_Form.Vector_Basis_r (A => Theta, D => Basis_r);

and accessing the horizontal and vertical components later on by just using

    Rectangular_Form.Get_Horz (Basis_r)

and

    Rectangular_Form.Get_Vert (Basis_r)

This seems OK as I am using the methods Get_Horz and Get_Vert to access the private Rectangular horizontal and vertical components. However I am reading the variable Theta directly from the command line and finding its horizontal and vertical components using

    Rectangular_Form.Vector_Basis_r (A => Theta, D => Basis_r);

If the Rectangular components A.Horz and A.Vert are private as I have defined them, why do not I have to use the methods set_Horz(A) and set_Vert(A) prior to issuing the command

    Rectangular_Form.Vector_Basis_r (A => Theta, D => Basis_r);

PS: The functions for Set_Vert and Get_Vert were omitted to keep the codes short.

Thanks a lot…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:51:24+00:00Added an answer on June 3, 2026 at 5:51 am

    why do not I have to use the methods set_Horz(A) and set_Vert(A) prior
    to issuing the command

    Because you’re setting the fields of your private record by executing:

    Rectangular_Form.Vector_Basis_r (A => Theta, D => Basis_r);

    (Review the implementation of Vector_Basis_r.)

    — EXPANDED Answer

    When you declare the Basis_r variable in your Test_Rectangular_Form procedure, the memory for that “Rectangular” variable is allocated. At this point the Horz and Vert fields in the private type are present, but unset (they could contain anything).

    When you call Rectangular_Form.Vector_Basis_r, its implementation sets the values of those private fields. Maybe this is what’s confusing you: the body of the package in which a private type is declared has direct access to those fields. This is exactly the aspect that Vector_Basis_r is exploiting when setting their values (as well as Set_Vert and Set_Horz).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn how to use oop in php. I'm also fairly new
I'm trying to learn how to use actionscript over mxml for flexibility. I have
I am trying to learn and use an SDK for a vendor's product. Unfortunately,
I am trying to learn to use buffer overflow attack in Ubuntu. Unfortunately, I
I am trying to learn to use the wx packages to make GUI programs
I am relatively new to programming, and I am trying to learn to use
I'm trying to learn how to use lift. I can create project skeleton by
I'm trying to learn how to use the UITableView in conjunction with a SQLite
I'm trying to learn how to use keys and to break the habit of
I'm trying to learn how to use WinForms databinding, but one thing that's confusing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.