Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Uppgift 2. Skapa en datatyp som motsvarar ett komplext tal på formen "a + bi"
- --Uppgift 3. Skriv ett program som läser in två komplexa tal, summerar dem, och skiver ut summan av talen
- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
- with Ada.Float_Text_Io; use Ada.Float_Text_Io;
- with Ada.Text_IO; use Ada.Text_IO;
- procedure Komplex_Addition is
- type Komplext_Tal is
- record
- Reellt: Float;
- Imaginart: Float;
- end record;
- procedure Inmatning(Tal: in out Komplext_Tal) is
- C: Character;
- begin
- Put("Mata in ett komplext tal på formen 'a+bi': ");
- Get(Tal.reellt);
- Get(C);
- Get(Tal.Imaginart);
- Get(C);
- Skip_Line;
- end Inmatning;
- function "+"(X,Y: in Komplext_Tal) return Komplext_Tal is
- Summa: Komplext_Tal;
- begin
- Summa.Reellt:=X.Reellt + Y.Reellt;
- Summa.Imaginart:=X.Imaginart + Y.Imaginart;
- return Summa;
- end "+";
- procedure Put(X: in Komplext_Tal) is
- begin
- Put(X.Reellt,Fore=>0,Aft=>0,Exp=>0);
- Put(" + ");
- Put(X.Imaginart,Fore=>0,Aft=>0,Exp=>0);
- Put("i");
- end Put;
- K: Komplext_Tal;
- K2: Komplext_Tal;
- begin
- Inmatning(K);
- Inmatning(K2);
- Put(K+K2);
- end Komplex_Addition;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement