我有以下代码:
WITH X_IO;
USE X_IO;
WITH X_Characters;
USE X_Characters;
PROCEDURE Beispiel_3 IS
Int : Integer := 1;
Dlm : Integer := 2;
EoI : Integer := 3;
K0,
I0 : Integer;
D0,
Ch0 : Character;
PROCEDURE Get_Symbol (
K1 : OUT Integer;
D1 : OUT Character;
I1 : OUT Integer) IS
BEGIN
LOOP
WHILE Ch0 = ' ' LOOP
Get(Ch0);
END LOOP;
IF Is_Digit(Ch0) OR Ch0 = '.' THEN
I1:= To_Digit(Ch0);
Get(Ch0);
WHILE Is_Digit(Ch0) LOOP
I1:= I1 * 10 + To_Digit(Ch0);
Get(Ch0);
END LOOP;
K1:= Int;
EXIT;
ELSIF Ch0 = '+' OR Ch0 = '-' OR Ch0 = '*' OR Ch0 = '.'
OR Ch0 = '/' OR Ch0 = '(' OR Ch0 = ')' THEN
D1:= Ch0;
Get(Ch0);
K1:= Dlm;
EXIT;
ELSIF Ch0 = '=' THEN
D1:= '=';
K1:= EoI;
EXIT;
ELSE
Put("Unzulaessiges Zeichen: '");
Put(Ch0);
Put("', geloescht");
Get(Ch0);
New_Line;
END IF;
END LOOP;
END;
BEGIN
Get(Ch0);
LOOP
Get_Symbol(K0, D0, I0);
IF K0 = Int THEN
Put(I0, 1);
New_Line;
ELSIF K0 = Dlm THEN
Put(D0);
New_Line;
ELSIF K0 = EoI THEN
Put("Ende.");
EXIT;
END IF;
END LOOP;
END;
使用Code我可以做以下事情: 例: 5 + 4 +3 -1 = 在控制台中输入此内容将导致:
5
+
4
+
3
-
=
end
现在我希望能够写出这样的东西: 5.3 +3 -4.22 = 我想要以下输出:
5.3
+
3
-
4.22
=
end
我在寻找解决方案时遇到了问题。 我有可能,我不喜欢。它将显示如下示例:
5
.
3
-
4
.
22
=
end
我将不胜感激 谢谢
抱歉忘记了图书馆。
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 body X_IO is
-- subtype Positive_Count is Ada.Text_IO.Count
-- range 1..Ada.Text_IO.Count’Last; -- terminate ‘ for SO
-- Allgemeines
procedure Create(File: in out File_Type;
Mode: in File_Mode:= Out_File;
Name: in String:= " ";
Form: in String:= " ") is
begin
Ada.Text_IO.Create(File, Mode, Name, Form);
end Create;
procedure Open(File: in out File_Type;
Mode: in File_Mode;
Name: in String:= " ";
Form: in String:= " ") is
begin
Ada.Text_IO.Open(File, Mode, Name, Form);
end Open;
procedure Close(File: in out File_Type) is
begin
Ada.Text_IO.Close(File);
end Close;
procedure Delete(File: in out File_Type) is
begin
Ada.Text_IO.Delete(File);
end Delete;
procedure Set_Output(File: in File_Type)is
begin
Ada.Text_IO.Set_Output(File);
end Set_Output;
procedure Set_Input(File: in File_Type)is
begin
Ada.Text_IO.Set_Input(File);
end Set_Input;
function Standard_Output return File_Type is
begin
return Ada.Text_IO.Standard_Output;
end Standard_Output;
function Standard_Input return File_Type is
begin
return Ada.Text_IO.Standard_Input;
end Standard_Input;
procedure New_Line(File: File_Type;
Spacing: Positive_Count:= 1) is
begin
Ada.Text_IO.New_Line(File, Spacing);
end New_Line;
procedure New_Line(Spacing: Positive_Count:= 1) is
begin
Ada.Text_IO.New_Line(Spacing);
end New_Line;
procedure Skip_Line(File: File_Type;
Spacing: Positive_Count:= 1) is
begin
Ada.Text_IO.Skip_Line(File, Spacing);
end Skip_Line;
procedure Skip_Line(Spacing: Positive_Count:= 1) is
begin
Ada.Text_IO.Skip_Line(Spacing);
end Skip_Line;
function End_Of_Line(File: in File_Type) return Boolean is
begin
return Ada.Text_IO.End_Of_Line(File);
end End_Of_Line;
function End_Of_Line return Boolean is
begin
return Ada.Text_IO.End_of_Line;
end End_Of_Line;
function End_Of_File(File: in File_Type) return Boolean is
begin
return Ada.Text_IO.End_Of_File(File);
end End_Of_File;
function End_Of_File return Boolean is
begin
return Ada.Text_IO.End_Of_File;
end End_Of_File;
procedure Set_Col(File: File_Type; To: in Positive_Count) is
begin
Ada.Text_IO.Set_Col(File, To);
end Set_Col;
procedure Set_Col(To: in Positive_Count) is
begin
Ada.Text_IO.Set_Col(To);
end Set_Col;
-- Character
procedure Get(File: in File_Type; Item: out Character) is
begin
Ada.Text_IO.Get(File, Item);
end Get;
procedure Get(Item: out Character) is
begin
Ada.Text_IO.Get(Item);
end Get;
procedure Put(File: in File_Type; Item: in Character) is
begin
Ada.Text_IO.Put(File, Item);
exception
when others=> Put_Line(" *** Put-File-Ch *** ");
end Put;
procedure Put(Item: Character) is
begin
Ada.Text_IO.Put(Item);
end Put;
-- String
procedure Get(File: in File_Type;
Item: out String) is
begin
Ada.Text_IO.Get(File, Item);
end Get;
procedure Get(Item: out String) is
begin
Ada.Text_IO.Get(Item);
end Get;
procedure Get_Line(File: in File_Type;
Item: out String;
Last: out Natural) is
begin
Item:= (others=> ' ');
Ada.Text_IO.Get_Line(File, Item, Last);
exception
when others=> Put_Line(" *** Get-Line-File-Str *** ");
end Get_Line;
procedure Get_Line(Item: out String; Last: out Natural) is
begin
Ada.Text_IO.Get_Line(Item, Last);
end Get_Line;
procedure Put(File: in File_Type; Item: in String) is
begin
Ada.Text_IO.Put(File, Item);
end Put;
procedure Put(Item: String) is
begin
Ada.Text_IO.Put(Item);
end Put;
procedure Put_Line(File: in File_Type; Item: in String) is
begin
Ada.Text_IO.Put_Line(File, Item);
end Put_Line;
procedure Put_Line(Item: String) is
begin
Ada.Text_IO.Put_Line(Item);
end Put_Line;
-- Integer
procedure Get(Item: out Integer;
Width: in Field:= 0) is
begin
Ada.Integer_Text_IO.Get(Item);
end Get;
procedure Get(File: in File_Type;
Item: out Integer;
Width: in Field:= 0) is
begin
Ada.Integer_Text_IO.Get(File, Item);
end Get;
procedure Put(Item: in Integer) is
begin
Ada.Integer_Text_IO.Put(Item);
end Put;
procedure Put(File: in File_Type;
Item: in Integer) is
begin
Ada.Integer_Text_IO.Put(File, Item);
end Put;
procedure Put(Item: in Integer;
Width: in Field) is
begin
Ada.Integer_Text_IO.Put(Item, Width);
end Put;
procedure Put(File: in File_Type;
Item: in Integer;
Width: in Field) is
begin
Ada.Integer_Text_IO.Put(File, Item, Width);
end Put;
procedure Get(From: in String; Item: out Integer; Last: out Positive) is
begin
Ada.Integer_Text_IO.Get(From, Item, Last);
end Get;
procedure Put(To: out String; Item: Integer) is
begin
Ada.Integer_Text_IO.Put(To, Item);
end Put;
-- Float
procedure Get(Item: out Float; Width: in Field:= 0) is
begin
Ada.Float_Text_IO.Get(Item, Width);
end Get;
procedure Get(File: in File_Type;
Item: out Float;
Width: in Field:= 0)is
begin
Ada.Float_Text_IO.Get(File, Item, Width);
end Get;
procedure Put(Item: Float;
Fore: in Field:= Default_Fore;
Aft: in Field:= Default_Aft;
Exp: in Field:= Default_Exp) is
begin
Ada.Float_Text_IO.Put(Item, Fore, Aft, Exp);
end Put;
procedure Put(File: in File_Type;
Item: in Float;
Fore: in Field:= Default_Fore;
Aft: in Field:= Default_Aft;
Exp: in Field:= Default_Exp) is
begin
Ada.Float_Text_IO.Put(File, Item, Fore, Aft, Exp);
end Put;
procedure Get(From: in String;
Item: out Float;
Last: out Positive) is
begin
Ada.Float_Text_IO.Get(From, Item, Last);
end Get;
procedure Put(To: out String;
Item: In Float;
Aft: in Field:= Default_Aft;
Exp: in Field:= Default_Exp) is
begin
Ada.Float_Text_IO.Put(To, Item, Aft, Exp);
end Put;
end X_IO;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;
package body X_Characters is
function Is_Lower(Item: in Character) return Boolean is
begin
return Ada.Characters.Handling.Is_Lower(Item);
end Is_Lower;
function Is_Upper(Item: in Character) return Boolean is
begin
return Ada.Characters.Handling.Is_Upper(Item);
end Is_Upper;
function Is_Letter(Item: in Character) return Boolean is
begin
return Ada.Characters.Handling.Is_Letter(Item);
end Is_Letter;
function Is_Digit(Item: in Character) return Boolean is
begin
return Ada.Characters.Handling.Is_Digit(Item);
end Is_Digit;
function Is_Control(Item: in Character) return Boolean is
begin
return Ada.Characters.Handling.Is_Control(Item);
end Is_Control;
function Is_Graphic(Item: in Character) return Boolean is
begin
return Ada.Characters.Handling.Is_Graphic(Item);
end Is_Graphic;
function To_Lower(Item: in Character) return Character is
begin
return Ada.Characters.Handling.To_Lower(Item);
-- exception
-- when others=> Put_Line(" *** To_Lower *** ");
end To_Lower;
function To_Upper(Item: in Character) return Character is
begin
return Ada.Characters.Handling.To_Upper(Item);
-- exception
-- when others=> Put_Line(" *** To_Upper *** ");
end To_Upper;
function To_Integer(Item: in Character) return Integer is
begin
return Character'Pos(Item) - Character'Pos('0');
end To_Integer;
function To_Digit(Item: in Character) return Integer is
begin
return Character'Pos(Item) - Character'Pos('0');
end To_Digit;
begin
-- Put_Line("Hier ist X-Characters");
null;
exception
when others => Put("Exception in package Ada_Characters"); New_Line;
end X_Characters;
我目前的代码:
WITH X_IO;
USE X_IO;
WITH X_Characters;
USE X_Characters;
PROCEDURE Lsg3 IS
Int : Integer := 1;
Dlm : Integer := 2;
EoI : Integer := 3;
K0,
I0 : Integer;
D0,
Ch0 : Character;
Fractional_Place: Float := 0.1;
Point_Found : Boolean := False;
PROCEDURE Get_Symbol (
K1 : OUT Integer;
D1 : OUT Character;
I1 : OUT Integer) IS
BEGIN
LOOP
WHILE Ch0 = ' ' LOOP
Get(Ch0);
END LOOP;
IF Is_Digit(Ch0) THEN
I1:= To_Digit(Ch0);
Get(Ch0);
WHILE Is_Digit(Ch0) LOOP
IF Point_Found = False THEN
I1:= I1 * 10 + To_Digit(Ch0);
END IF;
Get(Ch0);
IF Ch0 = '.' THEN
Point_Found := True;
--Here is the Problem, how to use I1 integer
Fractional_Place := Fractional_Place / 10.0;
END IF;
END LOOP;
K1:= Int;
EXIT;
ELSIF Ch0 = '+' OR Ch0 = '-' OR Ch0 = '*'
OR Ch0 = '/' OR Ch0 = '(' OR Ch0 = ')' THEN
D1:= Ch0;
Get(Ch0);
K1:= Dlm;
EXIT;
ELSIF Ch0 = '=' THEN
D1:= '=';
K1:= EoI;
EXIT;
ELSE
Put("Unzulaessiges Zeichen: '");
Put(Ch0);
Put("', geloescht");
Get(Ch0);
New_Line;
END IF;
END LOOP;
END;
BEGIN
Get(Ch0);
LOOP
Get_Symbol(K0, D0, I0);
IF K0 = Int THEN
Put(I0, 1);
New_Line;
ELSIF K0 = Dlm THEN
Put(D0);
New_Line;
ELSIF K0 = EoI THEN
Put("Ende.");
EXIT;
END IF;
END LOOP;
END;