- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在解决一个问题,我需要根据输入的数字制作一组框,其中每个框都有一个唯一的名称。我已经设法创建了这些盒子,但我只设法在所有盒子上插入一个名字,因为我的名字在名字收集过程中被覆盖了。
这是代码 https://pastebin.com/FBMvvrn4
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure exercise is
N : Integer;
Names : String(1..10);
L : Integer;
procedure Objectcatcha (N: out Integer) is
begin
Put("Enter amount of objects: ");
Get(N);
end Objectcatcha;
procedure Namescatcha (Names: out string; L: out integer) is
begin
for I in 1..N loop
Get_Line(Names, L);
end loop;
end Namescatcha;
procedure SpaceBox(Names: in String; L: in Integer; N : in integer) is
begin
for I in 1..N loop
Put("+-----------+ ");
end loop;
New_Line;
for I in 1..N loop
Put("! ");
Put(Names(1..L));
for J in (L+1)..10 loop
Put(" ");
end loop;
Put("!");
if I = N then
Put("");
else
Put("<>---");
end if;
end loop;
New_Line;
for I in 1..N loop
Put("+-----------+ ");
end loop;
end SpaceBox;
begin
Objectcatcha(N);
Put("Enter the name of the objects: ");
Namescatcha(Names, L);
SpaceBox(Names,L, N);
end exercise;
我在这方面坐了很久,如果有人能帮我找到一种方法来单独命名每个盒子,我会很高兴。
提前致谢!
最佳答案
只要你可以,(你可以在这里),只需声明一个精确大小的变量来保存你正在使用的名称。这可以通过将其声明为不定数组并使用正确的名称对其进行初始化来完成。
所以你的主程序可能是:
Objectcatcha(N);
For I in 1 to N loop
Put("Enter the name of the next object: ");
Declare
Name : String := Namescatcha;
Begin
SpaceBox(Name, Name'Length, N);
End;
End loop;
Namescatcha 现在是一个返回正确大小的字符串的函数:
function Namescatcha return String is
begin
return Getline;
end Namescatcha;
你可能应该重写没有 L 的 Spacebox(你总是可以使用 Name'Length 来查看 Name 的长度)
关于string - 存储和使用变长字符串 (ADA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61719343/
如何在过程中编写迭代器?对不起我的转储问题,我是新手。感谢您的回答。 最佳答案 这完全取决于您需要迭代的内容。 数组?使用loop : plain, for, or while. predefined
我现在知道很多编程语言。回到我 18 岁的时候,我几乎加入了美国空军,并且对 Ada 进行了测试。那是十多年前的事了。 Ada 编程语言在军队中是否仍然像以前一样重要? 我想知道新的军事软件项目是否仍
在 Java 或 C# 中,您经常会拥有 final 的类成员。或 readonly - 它们设置一次,然后再也不碰。它们可以为类的不同实例保存不同的值。 艾达有没有类似的东西?我试图在 Ada 中创
即使使用这个简单的示例,我也无法让动态调度正常工作。我相信问题在于我如何设置类型和方法,但看不到在哪里! with Ada.Text_Io; procedure Simple is type A
我目前正在自学 Ada,尽管我可以从解决一些更传统的问题开始。 更具体地说,我尝试计算阶乘 n!,而 n>100。到目前为止,我的实现是: with Ada.Text_IO; with Ada.Int
目前正在学习 Ada 并真正享受它,有一件事情困扰着我:什么是 tagged类型?根据 John Barnes 的 Programming in Ada 2012,它表示实例化的对象在运行时带有标签。
你好 我正在尝试我在 Ada 中创建单人骰子游戏的第一个程序。 但面临着保持球员得分的问题。 目标:每个玩家有 10 个回合,如果 2 次掷骰总数为 7,则获得 10 分 问题:每次总分被重置并且 1
您可以通过让函数返回一个值来分配给变量: My_Int : Integer := My_Math_Func [(optional params)]; 或者你可以用一个过程来做到这一点(假设 My_In
我试图在 Ada 中将字符转换为整数,似乎没有任何效果,到目前为止我已经能够从 ASCII 返回 DEC,但我想返回 0(整数)。 Character'Pos('0'); 返回 48 --我希望它返回
假设我有以下常量来定义一个只接受其范围定义内的有效值的子类型: type Unsigned_4_T is mod 2**4; valid_1 : constant Unsigned_4_T :=
我正在尝试创建一个 tree-sitter解析器,以便 IDE(在本例中为 Vim)可以解析 Ada 程序文本并进行更高级的操作,例如 extract-subprogram 和 rename-vari
我正在写一篇关于 Ada 83 的论文。我们有一个作业,列出了论文的各个部分(历史、设计目标、语法等)。讲师提到我们中的一些人将有一些部分简单地说“此语言不支持此功能。” 其中两个部分是数据类型和
假设我有以下常量来定义一个只接受其范围定义内的有效值的子类型: type Unsigned_4_T is mod 2**4; valid_1 : constant Unsigned_4_T :=
我正在尝试创建一个 tree-sitter解析器,以便 IDE(在本例中为 Vim)可以解析 Ada 程序文本并进行更高级的操作,例如 extract-subprogram 和 rename-vari
我想声明一个元素类型为变体记录的数组。像这样: type myStruct (theType : vehicleType) is record ... when car => numOfWheels
我正在实例化一个带有枚举的通用包,以访问多个值之一并在子程序重载中使用。我想要一组定义明确、编译时检查过的值,我可以使用和查找。 generic -- Different types beca
我有以下包: ------------------- -- File: father.ads ------------------- package Father with SPARK_Mode =>
对于最后的程序,我从 gnat 收到以下错误消息: test2.adb:23:61: error: invalid operand types for operator "-" test2.adb:2
我编写了一个加密文件的 Ada 程序。它逐 block 读取它们以节省目标机器上的内存。不幸的是,Ada 的目录库读取 Long_Integer 中的文件大小,将读取限制为近 2GB 文件。尝试读取超
我想打印访问变量(指针)的地址以进行调试。 type Node is private; type Node_Ptr is access Node; procedure foo(n: in out No
我是一名优秀的程序员,十分优秀!