我正在尝试使用循环队列来实现这一点。我的程序执行但在构建和运行时显示已成功终止

问题描述 投票:0回答:1

LinkSort.adb 文件

with Ada.Text_IO; use Ada.Text_IO;

procedure LinkSort is

  type JobType is (Accountant, Analysist, Manager, Manufacturing, Programmer, Inventory, Sales, SoftwareEnginner);
  package JobTypeIO is new Ada.Text_IO.Enumeration_IO(JobType); use JobTypeIO;

  type EmpName is (Ben, Betty, Bob, Damon, Darlene, David, Desire, Donald, Dustin, Jerry, Kevin, Mary, Marty, Sable, Sam, Sara, Teddy, Tom);
  package EmpNameIO is new Ada.Text_IO.Enumeration_IO(EmpName); use EmpNameIO;

  type LegalResponce is (yup, y, yes, affirmative, nope, no, n, negative);
  subtype PositiveResponce is LegalResponce range yup..affirmative;
  package LegalIO is new Ada.Text_IO.Enumeration_IO(LegalResponce); use LegalIO;

  package IntIO is new Ada.Text_IO.Integer_IO(Integer); use IntIO;

  type Emp is record
    Name: EmpName;
    Job: JobType;
    age: integer;
  end record;

  SortByJob: Array(JobType) of integer := (others =\> 0);

  SortSpace: Array(1..200) of Emp;
  Avail: integer := 1; -- Dynamic storage allocator.
  Pt: integer;

  Again: LegalResponce := affirmative;

begin

  while (Again in PositiveResponce) loop
    put("Enter name: "); get(SortSpace(Avail).Name); --Get emp info.
    put("Enter Job type: "); get(SortSpace(Avail).Job);
    
    -- Insert in appropriate list (by job).
    SortSpace(Avail).Next := SortByJob(SortSpace(Avail).Job);
    SortByJob(SortSpace(Avail).Job) := Avail;
    
    -- Prepare for next dynamically allocated node.
    Avail := Avail + 1; --Using static array allocation as opposed dynamic linked list.
    
    put("Enter another name (yup or nope): "); get(Again);
  end loop;

  -- Sort by job type.

  for I in JobType loop
    new_line; put("Job Type = "); put (I); new_line;
    
    Pt := SortByJob(I); -- Point to first node in job list.
    
    while Pt /= 0 loop
      put(SortSpace(Pt).Name); put(" "); put(SortSpace(Pt).Job);
      put(" link = "); put(SortSpace(Pt).Next,4); new_line;
    
      Pt := SortSpace(Pt).Next; -- Move down list.
    end loop;
  end loop;

end LinkSort;

主.adb文件

procedure Main is
begin
  null;
end Main;

不知道下一步应该做什么?我尝试在 main.adb 文件中实现 Ada.Text_IO 中的所有内容,但发生了错误。我知道我需要将某些内容移至主文件中,以便程序在构建后执行。输出语句应该是名称、工作类型然后排序空间编号。

loops ada io-redirection circular-queue
1个回答
2
投票

您已将

Linksort
编写为库级子例程(也就是说,它将单独编译)。这对于主程序来说效果很好,但是如果您希望您的
Main
程序调用它,您需要在文件
linksort.ads
:

中提供“规范”
procedure Linksort;

然后

with Linksort;   -- the same way as you 'with' Ada.Text_IO
procedure Main is
begin
   Linksort;
end Main;

但是!
Ada 中没有规定主程序必须命名为

main
Main
;按照你写的方式
Linksort
它将成为一个完美的主程序。一旦你构建完成,在 Unix 类型的计算机上你会说
./linksort
,在 Windows 计算机上
.\linksort

© www.soinside.com 2019 - 2024. All rights reserved.