【发布时间】:2020-05-20 20:46:51
【问题描述】:
我再次求助于 Stackoverflow。以前在这里得到过帮助,我希望再次得到同样友好的接待。我有一个任务,我需要在 ADA 中绘制一面旗帜(包括围绕它的盒子状形状和中间的 V 形十字架)。我设法制造了盒子和大约一半的十字架。谁能告诉我如何用最简单的方法填充其余的十字架?
它应该是一个V形,像这样:
+ +
+ +
+
等
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure exercise2 is
subtype Cross_Rows is Integer range 2..80;
Rows : Cross_Rows;
Flag_Width : Cross_Rows;
Left : Positive;
Right : Positive;
procedure Row_Get (Rows: out Cross_Rows) is
begin
Put("Enter the number of cross rows (min is 3): ");
Get(Rows);
Skip_Line;
end Row_Get;
procedure Print_Top (Rows: in Cross_Rows) is
begin
Flag_Width := (Rows * 2) + 4;
Put("+");
for Col in 1..Flag_Width-3 loop
Put("-");
end loop;
Put("+");
New_Line;
end Print_Top;
procedure Print_Middle (Rows: in Cross_Rows) is
begin
Left := 1;
Right := Flag_Width - 5;
for R in 1..Rows loop
Put("! ");
for C in 1..Flag_Width - 4 loop
if C = Left or else C = Right then
Put("+");
else
Put(" ");
end if;
end loop;
Left := Left + 1;
Right := Right - 1;
Put_Line("!");
end loop;
end Print_Middle;
procedure Print_Bottom (Rows: in Cross_Rows) is
begin
Flag_Width := (Rows * 2) + 4;
Put("+");
for C in 1..Flag_Width-3 loop
Put("-");
end loop;
Put_Line("+");
end Print_Bottom;
begin
Row_Get(Rows);
Print_Top(Rows);
Print_Middle(Rows);
Print_Bottom(Rows);
end exercise2;
编辑:感谢 Jim Rogers,我设法编辑了我的程序来绘制旗帜。不幸的是,它并不完全是它的意思,因为顶部十字架应该接触侧面而不是像现在这样间隔开。另外,主程序和子程序都不允许超过 15 行,所以我把它们分开了。
最小的标志应该是这样的。我将尝试使用他的代码来实现这一目标。但任何帮助都是有价值的! :)
n=1
+---+
!+ +!
! + !
+---+
n=2
+-----+
!+ +!
! + + !
! + !
+-----+
【问题讨论】: