Im stuck in Ada. I'm supposed to create a package with a specific Flag_Type that can be written to and read in order to print a simple flag. Id like to think Ive managed to make the package ads and the package body adb right but I struggle with the commands for the main program.
First is first, the output is supposed to look like this:
Enter the flag name: Italys flag
Enter the flag height: 2
Enter the stripes width: 3
Enter the flags colors: GWR
Italys flag
+---------+
|GGGWWWRRR|
|GGGWWWRRR|
+---------+
now, my package ADS looks like this:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
package Flagdrawer is
type Flag_Type is private;
procedure Get(Item: out Flag_Type);
procedure Put(Item: in Flag_Type);
private
type Flag_Type is
record
Flag_Name: String(1..20);
L : Integer;
Flag_Height : Integer;
Flag_Width : Integer;
Flag_Colors : String(1..3);
end record;
end Flagdrawer;
My package body looks like this:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Flagdrawer; use Flagdrawer;
package body Flagdrawer is
procedure Get(Item: out Flag_Type) is
begin
Get_Line(Item.Flag_Name, Item.L);
Get(Item.Flag_Height);
Get(Item.Flag_Width);
Get(Item.Flag_Colors);
end Get;
procedure Put(Item: in Flag_Type) is
Real_Width : Integer;
begin
Real_Width := Item.Flag_Width *3;
Put(Item.Flag_Name(1..Item.L));
New_Line;
Put("+");
for I in 1..Real_Width loop
Put("-");
end loop;
Put_Line("+");
for J in 1..Item.Flag_Height loop
Put("!");
for K in 1..Item.Flag_Width loop
Put(Item.Flag_Colors(1));
end loop;
for L in 1..Item.Flag_Width loop
Put(Item.Flag_Colors(2));
end loop;
for M in 1..Item.Flag_Width loop
Put(Item.Flag_Colors(3));
end loop;
Put_Line("!");
end loop;
Put("+");
for I in 1..Real_Width loop
Put("-");
end loop;
Put_Line("+");
end Put;
end Flagdrawer;
and then my sorely lacking main program looks like this:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Flagdrawer; use Flagdrawer;
procedure Tenta_Flagdrawah is
F: Flag_Type;
begin
Put_line("Enter the flags name (1): ");
Put_Line("Enter the flags height (2): ");
Put_Line("Enter the stripes' width (3): ");
Put_Line("Enter the RGB for the flag's colors (4): ");
Get(F);
New_Line;
Put(F);
end Tenta_Flagdrawah;
Im only used to assignments that have one specific input, lets say Get(F) where F is Flag_Type, now its spread out over multiple variables and I dont know how to consolidate them.
I've been getting good responses from here in the past, is there any chance anyone could give me some tips as to where Im at fault? I know my main program is severely lacking but I dont know how to code it.
Thanks in advance for any help!
EDIT
I found a solution that works (sort of) which is commented out of this main program I direct to Simon Wright as I didnt quite get what you meant with your declarations. I put them in my MP and I keep getting "actual for item must be a variable". I tried using Item.Name instead but it claims its an invalid prefix. Where did I go wrong you think?
main program .adb
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Flagdrawer; use Flagdrawer;
procedure Tenta_Flagdrawah is
F: Flag_Type;
subtype Color_String is String (1 .. 3);
procedure Get (Item : out Flag_Type;
Name : in String;
Height : in Natural;
Stripe_Width : in Natural;
Colors : in Color_String) is
begin
Put("Enter the flag's name: ");
Get(Name);
Put("Enter the flag's height: ");
Get(Height);
end Get;
begin
-- Put_line("Enter the flags name (1): ");
-- Put_Line("Enter the flags height (2): ");
-- Put_Line("Enter the stripes' width (3): ");
-- Put_Line("Enter the RGB for the flag's colors (4): ");
-- Get(F);
New_Line;
Put(F);
end Tenta_Flagdrawah;