home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 13 - Programming Exercise 2
- -- Chapter 13 - Program 5
- with Text_IO, Unchecked_Deallocation;
- use Text_IO;
-
- procedure Ch13_2c is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- type MY_RECORD is
- record
- Age : INTEGER;
- Initial : CHARACTER;
- Sex : CHARACTER;
- end record;
-
- type ACCESS_MY_DATA is access MY_RECORD;
-
- procedure Free is new
- Unchecked_Deallocation(MY_RECORD,ACCESS_MY_DATA);
-
- Myself : ACCESS_MY_DATA;
- Class : array(1..10) of ACCESS_MY_DATA;
-
- begin
- Myself := new MY_RECORD;
-
- Myself.Age := 34;
- Myself.Initial := 'D';
- Myself.Sex := 'M';
-
- for Index in 1..10 loop
- Class(Index) := new MY_RECORD;
- Class(Index).all := Myself.all;
- end loop;
-
- Class(3).Age := 30;
- Class(3).Initial := 'A';
- Class(5).Initial := 'Z';
- Class(8).Initial := 'R';
- Class(6).Sex := 'F';
- Class(7).Sex := 'F';
- Class(2).Sex := 'F';
-
- for Index in 1..10 loop
- Put("The class members age is");
- Put(Class(Index).Age,3);
- if Class(Index).Sex = 'M' then
- Put(" and his initial is ");
- else
- Put(" and her initial is ");
- end if;
- Put(Class(Index).Initial);
- New_Line;
- end loop;
-
- for Index in 1..10 loop
- Free(Class(Index));
- end loop;
- Free(Myself);
-
- end Ch13_2c;
-
-
-
-
- -- Result of execution
-
- -- The class members age is 34 and his initial is D
- -- The class members age is 34 and her initial is D
- -- The class members age is 30 and his initial is A
- -- The class members age is 34 and his initial is D
- -- The class members age is 34 and his initial is Z
- -- The class members age is 34 and her initial is D
- -- The class members age is 34 and her initial is D
- -- The class members age is 34 and his initial is R
- -- The class members age is 34 and his initial is D
- -- The class members age is 34 and his initial is D
-
-