在V形(ADA)中绘制带有对角十字的标记 [英] Drawing a flag with diagonal crosses in a V-Shape (ADA)

查看:125
本文介绍了在V形(ADA)中绘制带有对角十字的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次转向Stackoverflow。以前曾在这里获得帮助,希望再次得到同样的友好。我有一个作业,需要在ADA中绘制一个标志(包括它周围的盒形形状和中间的V形十字架)。我成功地制造了盒子和大约一半的十字架。有人能告诉我最简单的方法是如何填补其余的十字架吗?

I turn to Stackoverflow yet again. having gotten help here previously I hope to be received equally friendly once more. I have an assignment where I need to draw a flag (including a box-like shape around it and a V-shape of crosses in its midst) in ADA. Ive managed to make the box and roughly half of the crosses. can anyone clue me in as to how one easiest fills in the remainder of the crosses?

它应该是V形的,像这样:

Its supposed to be a V-shape, like this:

+   +
 + +
  + 

etc

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,我得以编辑程序来画出国旗。不幸的是,它并没有完全按照原本的方式使用,因为顶部的十字架应该碰到侧面并且没有像现在这样间隔开。另外,主程序和子程序arent各自允许超过15行,所以我将它们分隔开。

Thanks to Jim Rogers I managed to edit my program to draw the flag. Unfortunately its not exactly the way its meant to be as the top crosses are supposed to touch the sides and not be spaced like they are now. Additionally the Main program and the subprograms arent allowed to be more than 15 lines each so I compartmentalized them.

最小的标志应该看起来像这样。我将尝试使用他的代码来实现这一目标。但是任何帮助都是有价值的! :)

The smallest flag is supposed to look like this. I'll try to work with his code to achieve this. But any help is of value! :)

n=1
+---+
!+ +!
! + !
+---+

n=2
+-----+
!+   +!
! + + !
!  +  !
+-----+


推荐答案

您需要跟踪 +字符的左右列,在每次循环打印十字时增加左列位置和减小右列位置。
以下程序适用于从3到80的任意数量的十字架。

You need to keep track of the left and right columns for the '+' characters, increasing the left column position and decreasing the right column position with each iteration of your loop for printing the crosses. The following program works for any number of rows of crosses from 3 to 80.

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Main is
   subtype Cross_Rows is Integer range 3..80;
   Rows       : Cross_Rows;
   Flag_Width : Cross_Rows;
   Left       : Positive;
   Right      : Positive;

begin
   Put("Enter the number of cross rows (minimum is 3): ");
   Get(Rows);
   Skip_Line;
   Flag_Width := (Rows  * 2) + 4;
   -- Print top row of flag boundary
   for Col in 1..Flag_Width loop
      Put("-");
   end loop;
   Put("-");
   New_Line;
   -- Print empty row below top flag boundary
   Put("-  ");
   for C in 3..Flag_Width - 2 loop
      Put(" ");
   end loop;
   Put_Line(" -");

   -- Print crosses
   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;
   -- Print bottom flag rows
   Put("-  ");
   for C in 3..Flag_Width - 2 loop
      Put(" ");
   end loop;
   Put_Line(" -");
   for C in 1..Flag_Width loop
      Put("-");
   end loop;
   Put_Line("-");
end Main;

示例输出为:

Enter the number of cross rows (minimum is 3): 7
-------------------
-                 -
-  +           +  -
-   +         +   -
-    +       +    -
-     +     +     -
-      +   +      -
-       + +       -
-        +        -
-                 -
-------------------

这篇关于在V形(ADA)中绘制带有对角十字的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆