2 Replies - 1391 Views - Last Post: 26 February 2013 - 02:09 PM Rate Topic: -----

#1 IGoBoom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-February 13

Ada95 - Accessing Information in Private Type

Posted 26 February 2013 - 01:05 PM

I need a little help being steered in the right direction on an assignment for my intro level programming course. The programming language we use is Ada95. In this exercise, I am to develop a package that works with another package to perform certain tasks on a list of books. Some of the types we are using are:
TYPE Book_Type IS
      RECORD
         Title,
         Author,
         Publisher : Title_Str;
         Year      : Year_Type;
         Edition   : Natural;
         Isbn      : Isbn_Type;
         Price     : Dollars;
         Stock     : Natural;
         Format    : Format_Type;
      END RECORD;

TYPE Book_Collection_Array IS ARRAY (1 .. 200) OF Book_Type;

TYPE Book_Collection IS
      RECORD
         Books        : Book_Collection_Array;
         Max_Size     : Integer;
         Current_Size : Integer;
      END RECORD;



Book_Type and Book_Collection are both private. One of the packages was provided to us, and has functions to access information in Book_Type. One of the procedures I need to write is a procedure to change the price of a book, if it is in the collection. I tried this:
PROCEDURE Change_Price (
         Collection : Book_Collection;
         ISBN       : Isbn_Type;
         Price      : Dollars) IS
      Seen_Book : Boolean := False;
   BEGIN
      FOR book IN Collection.Books'Range LOOP
         IF ISBN(Collection.Books(book)) = ISBN THEN
            Set_Price(Collection.Books(book), Price);
            Seen_Book := True;
         END IF;
      END LOOP;
      IF NOT Seen_Book THEN
         RAISE Book_Not_Found;
      END IF;
   END Change_Price;


ISBN is a provided function that takes book_type as a parameter and returns isbn_type. Set_Price is a procedure that takes Book_type and price, and sets the price in the collection. I am getting 2 errors:
1 - When I call the ISBN function, it is telling me that it is expecting an integer, not a book_type.
2 - When I call the Set_Price procedure, it is telling me that the actual for "Book" must be a variable.
I am still very new, and don't really understand this. Can anyone steer me in the right direction? Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Ada95 - Accessing Information in Private Type

#2 IGoBoom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-February 13

Re: Ada95 - Accessing Information in Private Type

Posted 26 February 2013 - 01:35 PM

I realized one of my mistakes, regarding error 2. Change_Price should have read:

PROCEDURE Change_Price (
         Collection : [b]in out[/b] Book_Collection;
         ISBN       : [b]in[/b] Isbn_Type;
         Price      : [b]in[/b] Dollars) IS
      Seen_Book : Boolean := False;
   BEGIN
      FOR book IN Collection.Books'Range LOOP
         IF ISBN(Collection.Books(book)) = ISBN THEN
            Set_Price(Collection.Books(book), Price);
            Seen_Book := True;
         END IF;
      END LOOP;
      IF NOT Seen_Book THEN
         RAISE Book_Not_Found;
      END IF;
   END Change_Price;



Stupid mistake, and I probably made another one regarding 1. I still can't figure out why the ISBN function is expecting an integer, though.
Was This Post Helpful? 0
  • +
  • -

#3 IGoBoom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-February 13

Re: Ada95 - Accessing Information in Private Type

Posted 26 February 2013 - 02:09 PM

I think I figured this one out. The ISBN function is in a separate package. by putting book_pack.isbn instead of just isbn, it compiles, hopefully meaning it will work when I finish.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1