提问人:juggernaut45 提问时间:11/1/2023 最后编辑:Chrisjuggernaut45 更新时间:11/4/2023 访问量:75
我正在尝试使用循环队列来实现这一点。我的程序执行,但在构建和运行时显示成功终止
I am trying to implement this using a circular queue. My program executes but says terminated succesfully when build&ran
问:
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;
main.adb 文件
procedure Main is
begin
null;
end Main;
纠结于我下一步应该做什么?我试图在main.adb文件中实现Ada.Text_IO中的所有内容,但发生了错误。我知道我需要将某些内容移动到主文件中,以便程序在构建后执行。输出语句应为 name、job type,然后对空格编号进行排序。
答:
4赞
Simon Wright
11/1/2023
#1
您已编写为库级子例程(也就是说,它将单独编译)。这适用于主程序,但是如果您希望程序调用它,则需要在文件中提供“规范”: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 中没有规则说你的主程序必须被调用 or ;你写它的方式将成为一个完美的主程序。一旦你构建了它,在Unix类型的计算机上,你会说,在Windows计算机上。main
Main
Linksort
./linksort
.\linksort
评论