done I think

This commit is contained in:
Jonathan Turner 2023-11-12 17:08:12 -05:00
parent 68979dcb01
commit 4ed4aff9b6
11 changed files with 193 additions and 83 deletions

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
# Compiled source #
###################
*.exe
*.o
*.so
*.ali
*.exe
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

View File

@ -27,7 +27,7 @@ package body ComplexCalculator is
-- Divides two complex numbers -- Divides two complex numbers
function Divide(First, Second : ComplexNumber) return ComplexNumber is function Divide(First, Second : ComplexNumber) return ComplexNumber is
Result : ComplexNumber; Result : ComplexNumber;
Bottom : Float; -- improved readability & writability due to it repeating Bottom : Integer; -- improved readability & writability due to it repeating
begin begin
Bottom := (First.Real ** 2) + (Second.Imaginary ** 2); Bottom := (First.Real ** 2) + (Second.Imaginary ** 2);
@ -47,4 +47,13 @@ package body ComplexCalculator is
return Result; return Result;
end Multiply; end Multiply;
-- ToString method to return a formatted expression of the number.
function ToString(Number : ComplexNumber) return String is
begin
return Integer'Image(Number.Real) & " +" & Integer'Image(Number.Imaginary) & "i";
end ToString;
end ComplexCalculator; end ComplexCalculator;

View File

@ -1,16 +1,18 @@
package ComplexCalculator is package ComplexCalculator is
-- holds the records and fields for the numbers
--Defines that a complex number has two fields.
type ComplexNumber is record type ComplexNumber is record
Real : Float; Real : Integer;
Imaginary : Float; Imaginary : Integer;
end record; end record;
-- Defines the functions for calculations. -- Defines the available functions.
function Add(First, Second : ComplexNumber) return ComplexNumber; function Add(First, Second : ComplexNumber) return ComplexNumber;
function Sub(First, Second : ComplexNumber) return ComplexNumber; function Sub(First, Second : ComplexNumber) return ComplexNumber;
function Multiply(First, Second : ComplexNumber) return ComplexNumber; function Multiply(First, Second : ComplexNumber) return ComplexNumber;
function Divide(First, Second : ComplexNumber) return ComplexNumber; function Divide(First, Second : ComplexNumber) return ComplexNumber;
function ToString(Number : ComplexNumber) return String;
end ComplexCalculator; end ComplexCalculator;

View File

@ -1,16 +1,20 @@
V "GNAT Lib v2021" V "GNAT Lib v2021"
P ZX P SS ZX
RN RN
RV NO_FLOATING_POINT
RV NO_IO RV NO_IO
RV NO_SECONDARY_STACK
RV NO_DYNAMIC_SIZED_OBJECTS
U complexcalculator%b complexcalculator.adb 67f352b9 NE OO PK U complexcalculator%b complexcalculator.adb 30e97987 NE OO PK
W ada%s ada.ads ada.ali W ada%s ada.ads ada.ali
Z ada.strings.text_buffers%s a-sttebu.adb a-sttebu.ali Z ada.strings.text_buffers%s a-sttebu.adb a-sttebu.ali
W ada.text_io%s a-textio.adb a-textio.ali W ada.text_io%s a-textio.adb a-textio.ali
Z system.concat_4%s s-conca4.adb s-conca4.ali
Z system.img_int%s s-imgint.ads s-imgint.ali
Z system.secondary_stack%s s-secsta.adb s-secsta.ali
U complexcalculator%s complexcalculator.ads 1e56cc72 EE NE OO PK U complexcalculator%s complexcalculator.ads 63c49d54 EE NE OO PK
Z ada.strings.text_buffers%s a-sttebu.adb a-sttebu.ali Z ada.strings.text_buffers%s a-sttebu.adb a-sttebu.ali
D ada.ads 20210520051132 76789da1 ada%s D ada.ads 20210520051132 76789da1 ada%s
@ -23,14 +27,17 @@ D a-stuten.ads 20210520051130 808c40ad ada.strings.utf_encoding%s
D a-tags.ads 20210520051130 9eaa38c6 ada.tags%s D a-tags.ads 20210520051130 9eaa38c6 ada.tags%s
D a-textio.ads 20210520051130 aef4d56d ada.text_io%s D a-textio.ads 20210520051130 aef4d56d ada.text_io%s
D a-unccon.ads 20210520051130 0e9b276f ada.unchecked_conversion%s D a-unccon.ads 20210520051130 0e9b276f ada.unchecked_conversion%s
D complexcalculator.ads 20231024191420 1e56cc72 complexcalculator%s D complexcalculator.ads 20231112213916 63c49d54 complexcalculator%s
D complexcalculator.adb 20231025145030 d7514ba6 complexcalculator%b D complexcalculator.adb 20231112214944 fdd931be complexcalculator%b
D interfac.ads 20210520051132 edec285f interfaces%s D interfac.ads 20210520051132 edec285f interfaces%s
D i-cstrea.ads 20210520051132 e53d8b8e interfaces.c_streams%s D i-cstrea.ads 20210520051132 e53d8b8e interfaces.c_streams%s
D system.ads 20210520051136 2ffa5114 system%s D system.ads 20210520051136 2ffa5114 system%s
D s-conca4.ads 20210520051132 7e642b20 system.concat_4%s
D s-crtl.ads 20210520051132 0ebbdb71 system.crtl%s D s-crtl.ads 20210520051132 0ebbdb71 system.crtl%s
D s-exctab.ads 20210520051132 54135002 system.exception_table%s D s-exctab.ads 20210520051132 54135002 system.exception_table%s
D s-ficobl.ads 20210520051132 078245e4 system.file_control_block%s D s-ficobl.ads 20210520051132 078245e4 system.file_control_block%s
D s-imagei.ads 20210520051134 0d3f86a7 system.image_i%s
D s-imgint.ads 20210520051134 bdb6f5ec system.img_int%s
D s-parame.ads 20210520051134 4752c4cb system.parameters%s D s-parame.ads 20210520051134 4752c4cb system.parameters%s
D s-putima.ads 20210520051134 4e095881 system.put_images%s D s-putima.ads 20210520051134 4e095881 system.put_images%s
D s-secsta.ads 20210520051134 9b3ab94b system.secondary_stack%s D s-secsta.ads 20210520051134 9b3ab94b system.secondary_stack%s
@ -44,39 +51,43 @@ D s-unstyp.ads 20210520051134 2b077493 system.unsigned_types%s
D s-wchcon.ads 20210520051136 1b7d22d2 system.wch_con%s D s-wchcon.ads 20210520051136 1b7d22d2 system.wch_con%s
D unchconv.ads 20210520051136 ca2f9e18 unchecked_conversion%s D unchconv.ads 20210520051136 ca2f9e18 unchecked_conversion%s
G a e G a e
G c Z s b [add complexcalculator 11 13 none] G c Z s b [add complexcalculator 12 13 none]
G c Z s b [sub complexcalculator 12 13 none] G c Z s b [sub complexcalculator 13 13 none]
G c Z s b [multiply complexcalculator 13 13 none] G c Z s b [multiply complexcalculator 14 13 none]
G c Z s b [divide complexcalculator 14 13 none] G c Z s b [divide complexcalculator 15 13 none]
G c Z s s [complexnumberIP complexcalculator 3 9 none] G c Z s b [tostring complexcalculator 16 13 none]
G c Z s s [complexnumberIP complexcalculator 4 9 none]
X 1 ada.ads X 1 ada.ads
16K9*Ada 20e8 12|1r6 16K9*Ada 20e8 12|1r6
X 9 a-textio.ads X 9 a-textio.ads
58K13*Text_IO 725e16 12|1w10 58K13*Text_IO 725e16 12|1w10
X 11 complexcalculator.ads X 11 complexcalculator.ads
1K9*ComplexCalculator 16l5 16e22 12|3b14 50l5 50t22 1K9*ComplexCalculator 18l5 18e22 12|3b14 59l5 59t22
3R9*ComplexNumber 8e14 11r33 11r55 12r33 12r55 13r38 13r60 14r36 14r58 12|6r33 4R9*ComplexNumber 9e14 12r33 12r55 13r33 13r55 14r38 14r60 15r36 15r58 16r31
. 6r55 7r16 17r33 17r55 18r16 28r36 28r58 29r16 41r38 41r60 42r16 . 12|6r33 6r55 7r16 17r33 17r55 18r16 28r36 28r58 29r16 41r38 41r60 42r16
5f7*Real{float} 12|10m14 10r28 10r42 21m14 21r28 21r42 32r24 34m14 34r30 . 52r31
. 34r44 35r54 35r69 45m14 45r29 45r43 46r34 46r87 6i7*Real{integer} 12|10m14 10r28 10r42 21m14 21r28 21r42 32r24 34m14 34r30
6f7*Imaginary{float} 12|11m14 11r33 11r52 22m14 22r33 22r52 32r45 34r59 34r78 . 34r44 35r54 35r69 45m14 45r29 45r43 46r34 46r87 55r35
. 35m14 35r35 35r83 45r58 45r77 46m14 46r48 46r68 7i7*Imaginary{integer} 12|11m14 11r33 11r52 22m14 22r33 22r52 32r45 34r59
11V13*Add{3R9} 11>17 11>24 12|6b13 14l8 14t11 . 34r78 35m14 35r35 35r83 45r58 45r77 46m14 46r48 46r68 55r71
11r17 First{3R9} 12|6b17 10r22 11r27 12V13*Add{4R9} 12>17 12>24 12|6b13 14l8 14t11
11r24 Second{3R9} 12|6b24 10r35 11r45 12r17 First{4R9} 12|6b17 10r22 11r27
12V13*Sub{3R9} 12>17 12>24 12|17b13 25l8 25t11 12r24 Second{4R9} 12|6b24 10r35 11r45
12r17 First{3R9} 12|17b17 21r22 22r27 13V13*Sub{4R9} 13>17 13>24 12|17b13 25l8 25t11
12r24 Second{3R9} 12|17b24 21r35 22r45 13r17 First{4R9} 12|17b17 21r22 22r27
13V13*Multiply{3R9} 13>22 13>29 12|41b13 49l8 49t16 13r24 Second{4R9} 12|17b24 21r35 22r45
13r22 First{3R9} 12|41b22 45r23 45r52 46r28 46r62 14V13*Multiply{4R9} 14>22 14>29 12|41b13 49l8 49t16
13r29 Second{3R9} 12|41b29 45r36 45r70 46r41 46r80 14r22 First{4R9} 12|41b22 45r23 45r52 46r28 46r62
14V13*Divide{3R9} 14>20 14>27 12|28b13 38l8 38t14 14r29 Second{4R9} 12|41b29 45r36 45r70 46r41 46r80
14r20 First{3R9} 12|28b20 32r18 34r24 34r53 35r29 35r63 15V13*Divide{4R9} 15>20 15>27 12|28b13 38l8 38t14
14r27 Second{3R9} 12|28b27 32r38 34r37 34r71 35r47 35r76 15r20 First{4R9} 12|28b20 32r18 34r24 34r53 35r29 35r63
15r27 Second{4R9} 12|28b27 32r38 34r37 34r71 35r47 35r76
16V13*ToString{string} 16>22 12|52b13 57l8 57t16
16r22 Number{4R9} 12|52b22 55r28 55r64
X 12 complexcalculator.adb X 12 complexcalculator.adb
7r7 Result{11|3R9} 10m7 11m7 12r14 7r7 Result{11|4R9} 10m7 11m7 12r14
18r7 Result{11|3R9} 21m7 22m7 23r14 18r7 Result{11|4R9} 21m7 22m7 23r14
29r7 Result{11|3R9} 34m7 35m7 36r14 29r7 Result{11|4R9} 34m7 35m7 36r14
30f7 Bottom{float} 32m7 34r92 35r97 30i7 Bottom{integer} 32m7 34r92 35r97
42r7 Result{11|3R9} 45m7 46m7 47r14 42r7 Result{11|4R9} 45m7 46m7 47r14

Binary file not shown.

13
default-loc.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<Locations >
<Project >
<file_marker column=" 1" line=" 1" >
<vfs_project />
<vfs_file>C:\GNAT\2021\bin\Turner\complexcalculator.ads</vfs_file>
</file_marker>
<file_marker current="true" column=" 1" line=" 1" >
<vfs_project />
<vfs_file>C:\GNAT\2021\bin\Turner\main.adb</vfs_file>
</file_marker>
</Project>
</Locations>

View File

@ -1,7 +0,0 @@
project Default is
package Compiler is
for Switches ("Ada") use ("-g", "-O2");
end Compiler;
end Default;

View File

@ -2,29 +2,65 @@ with ComplexCalculator;
with Ada.Text_IO; with Ada.Text_IO;
procedure Main is procedure Main is
FirstInput : String(1..10); -- Helper Function to make life easier.
SecondInput : String(1..10); function GetInput(Name : String) return Integer is
Last_Position : Natural; -- Variable to hold the last position RealOrImaginary : Integer;
InputString : String(1..10);
Last_Position : Integer;
begin
Ada.Text_IO.Put(Name);
Ada.Text_IO.Get_Line(InputString, Last_Position);
-- Sets the default characters to ' ' to remove any random characters
InputString(Last_Position+1 .. InputString'Last) := (others => ' ');
RealOrImaginary := Integer'Value(InputString);
return RealOrImaginary;
end GetInput;
-- Variables
FirstComplex, SecondComplex, Result : ComplexCalculator.ComplexNumber;
Option : Integer;
begin begin
-- Your program logic goes here -- Creating the first complex number.
Ada.Text_IO.Put("Specify first imaginary number: "); FirstComplex.Real := GetInput("Enter First Real Number: ");
FirstComplex.Imaginary := GetInput("Enter First Imaginary Number: ");
Ada.Text_IO.Put_Line("");
-- Read the user's input for the first number and store it in FirstInput. -- Creating the second complex numebr.
Ada.Text_IO.Get_Line(FirstInput, Last => Last_Position); SecondComplex.Real := GetInput("Enter Second Real Number: ");
SecondComplex.Imaginary := GetInput("Enter Second Imaginary Number: ");
Ada.Text_IO.Put_Line("");
Ada.Text_IO.Skip_Line; -- Printing out the result of both creations.
-- Display the user's input for the first number. Ada.Text_IO.Put_Line("First Complex Number: " & ComplexCalculator.ToString(FirstComplex));
Ada.Text_IO.Put_Line("You entered: " & FirstInput); Ada.Text_IO.Put_Line("Second Complex Number: " & ComplexCalculator.ToString(SecondComplex));
Ada.Text_IO.Put("Specify second imaginary number: ");
-- Read the user's input for the second number and store it in SecondInput. -- Giving the menu options for what calcualtion to do.
Ada.Text_IO.Get_Line(SecondInput, Last => Last_Position); Ada.Text_IO.Put_Line("");
Ada.Text_IO.Put_Line("Please select a calculation for these two numbers.");
Ada.Text_IO.Put_Line("1. Add");
Ada.Text_IO.Put_Line("2. Subtract");
Ada.Text_IO.Put_Line("3. Multiply");
Ada.Text_IO.Put_Line("4. Divide");
Option := GetInput("Option: ");
Ada.Text_IO.Put_Line("");
-- Easier than making a bunch of ifs ;-;
Case Option is
when 1 =>
Result := ComplexCalculator.Add(FirstComplex, SecondComplex);
Ada.Text_IO.Put_Line("The result for adding these two numbers are: " & ComplexCalculator.ToString(Result));
when 2 =>
Result := ComplexCalculator.Sub(FirstComplex, SecondComplex);
Ada.Text_IO.Put_Line("The result for subtracting these two numbers are: " & ComplexCalculator.ToString(Result));
when 3 =>
Result := ComplexCalculator.Multiply(FirstComplex, SecondComplex);
Ada.Text_IO.Put_Line("The result for multiplying these two numbers are: " & ComplexCalculator.ToString(Result));
when 4 =>
Result := ComplexCalculator.Divide(FirstComplex, SecondComplex);
Ada.Text_IO.Put_Line("The result for dividing these two numbers are: " & ComplexCalculator.ToString(Result));
when others =>
Ada.Text_IO.Put_Line("Invalid Option Selected.");
end case;
-- Display the user's input for the second number.
Ada.Text_IO.Put_Line("You entered: " & SecondInput);
-- Example: Display a message
Ada.Text_IO.Put_Line("Hello, Ada!");
end Main; end Main;

View File

@ -1,17 +1,21 @@
V "GNAT Lib v2021" V "GNAT Lib v2021"
M P W=b M P W=b
P ZX P SS ZX
RN RN
RV NO_IO RV NO_IO
RV NO_LOCAL_ALLOCATORS
RV NO_STANDARD_STORAGE_POOLS
RV NO_DYNAMIC_SIZED_OBJECTS RV NO_DYNAMIC_SIZED_OBJECTS
U main%b main.adb 0b89c4d6 NE OO SU U main%b main.adb 90ffbc9d NE OO SU
W ada%s ada.ads ada.ali W ada%s ada.ads ada.ali
Z ada.strings.text_buffers%s a-sttebu.adb a-sttebu.ali Z ada.strings.text_buffers%s a-sttebu.adb a-sttebu.ali
W ada.text_io%s a-textio.adb a-textio.ali W ada.text_io%s a-textio.adb a-textio.ali
W complexcalculator%s complexcalculator.adb complexcalculator.ali W complexcalculator%s complexcalculator.adb complexcalculator.ali
Z system.concat_2%s s-conca2.adb s-conca2.ali Z system.concat_2%s s-conca2.adb s-conca2.ali
Z system.secondary_stack%s s-secsta.adb s-secsta.ali
Z system.val_int%s s-valint.ads s-valint.ali
D ada.ads 20210520051132 76789da1 ada%s D ada.ads 20210520051132 76789da1 ada%s
D a-except.ads 20210520051128 946f3014 ada.exceptions%s D a-except.ads 20210520051128 946f3014 ada.exceptions%s
@ -23,10 +27,10 @@ D a-stuten.ads 20210520051130 808c40ad ada.strings.utf_encoding%s
D a-tags.ads 20210520051130 9eaa38c6 ada.tags%s D a-tags.ads 20210520051130 9eaa38c6 ada.tags%s
D a-textio.ads 20210520051130 aef4d56d ada.text_io%s D a-textio.ads 20210520051130 aef4d56d ada.text_io%s
D a-unccon.ads 20210520051130 0e9b276f ada.unchecked_conversion%s D a-unccon.ads 20210520051130 0e9b276f ada.unchecked_conversion%s
D complexcalculator.ads 20231024191420 1e56cc72 complexcalculator%s D complexcalculator.ads 20231112213916 63c49d54 complexcalculator%s
D interfac.ads 20210520051132 edec285f interfaces%s D interfac.ads 20210520051132 edec285f interfaces%s
D i-cstrea.ads 20210520051132 e53d8b8e interfaces.c_streams%s D i-cstrea.ads 20210520051132 e53d8b8e interfaces.c_streams%s
D main.adb 20231025152734 bb2bddc9 main%b D main.adb 20231112215834 5dcff4a4 main%b
D system.ads 20210520051136 2ffa5114 system%s D system.ads 20210520051136 2ffa5114 system%s
D s-conca2.ads 20210520051132 02a0d7d0 system.concat_2%s D s-conca2.ads 20210520051132 02a0d7d0 system.concat_2%s
D s-crtl.ads 20210520051132 0ebbdb71 system.crtl%s D s-crtl.ads 20210520051132 0ebbdb71 system.crtl%s
@ -42,24 +46,49 @@ D s-stoele.ads 20210520051134 2dc34a04 system.storage_elements%s
D s-stoele.adb 20210520051134 ed88f8fb system.storage_elements%b D s-stoele.adb 20210520051134 ed88f8fb system.storage_elements%b
D s-traent.ads 20210520051134 26a8d361 system.traceback_entries%s D s-traent.ads 20210520051134 26a8d361 system.traceback_entries%s
D s-unstyp.ads 20210520051134 2b077493 system.unsigned_types%s D s-unstyp.ads 20210520051134 2b077493 system.unsigned_types%s
D s-valint.ads 20210520051134 e7fcadb7 system.val_int%s
D s-valuns.ads 20210520051134 dac7b45d system.val_uns%s
D s-valuei.ads 20210520051134 978dd0a6 system.value_i%s
D s-valueu.ads 20210520051134 7b8fccf5 system.value_u%s
D s-wchcon.ads 20210520051136 1b7d22d2 system.wch_con%s D s-wchcon.ads 20210520051136 1b7d22d2 system.wch_con%s
D unchconv.ads 20210520051136 ca2f9e18 unchecked_conversion%s D unchconv.ads 20210520051136 ca2f9e18 unchecked_conversion%s
G a e G a e
G c Z b b [main standard 4 11 none] G c Z b b [main standard 4 11 none]
G r c none [main standard 4 11 none] [tostring complexcalculator 16 13 none]
G r c none [main standard 4 11 none] [add complexcalculator 12 13 none]
G r c none [main standard 4 11 none] [sub complexcalculator 13 13 none]
G r c none [main standard 4 11 none] [multiply complexcalculator 14 13 none]
G r c none [main standard 4 11 none] [divide complexcalculator 15 13 none]
X 1 ada.ads X 1 ada.ads
16K9*Ada 20e8 14|2r6 11r4 14r4 16r4 18r4 20r4 23r4 26r4 29r4 16K9*Ada 20e8 14|2r6 11r7 12r7 27r4 32r4 35r4 36r4 39r4 40r4 41r4 42r4 43r4
. 44r4 46r4 52r10 55r10 58r10 61r10 63r10
X 9 a-textio.ads X 9 a-textio.ads
58K13*Text_IO 725e16 14|2w10 11r8 14r8 16r8 18r8 20r8 23r8 26r8 29r8 58K13*Text_IO 725e16 14|2w10 11r11 12r11 27r8 32r8 35r8 36r8 39r8 40r8 41r8
271U14*Skip_Line 14|16s16 . 42r8 43r8 44r8 46r8 52r14 55r14 58r14 61r14 63r14
463U14*Put 14|11s16 20s16 463U14*Put 14|11s19
479U14*Get_Line 14|14s16 23s16 479U14*Get_Line 14|12s19
481i7 Last{natural} 14|14r37 23r38 506U14*Put_Line 14|27s16 32s16 35s16 36s16 39s16 40s16 41s16 42s16 43s16
506U14*Put_Line 14|18s16 26s16 29s16 . 44s16 46s16 52s22 55s22 58s22 61s22 63s22
X 11 complexcalculator.ads X 11 complexcalculator.ads
1K9*ComplexCalculator 16e22 14|1w6 1K9*ComplexCalculator 18e22 14|1w6 20r42 35r53 36r53 51r20 52r81 54r20 55r86
. 57r20 58r86 60r20 61r83
4R9*ComplexNumber 9e14 14|20r60
6i7*Real{integer} 14|25m17 30m18
7i7*Imaginary{integer} 14|26m17 31m18
12V13*Add{4R9} 14|51s38
13V13*Sub{4R9} 14|54s38
14V13*Multiply{4R9} 14|57s38
15V13*Divide{4R9} 14|60s38
16V13*ToString{string} 14|35s71 36s71 52s99 55s104 58s104 61s101
X 14 main.adb X 14 main.adb
4U11*Main 4b11 30l5 30t9 4U11*Main 4b11 66l5 66t9
5a4 FirstInput{string} 14m25 18r43 6V13 GetInput{integer} 6b13 6>22 17l8 17t16 25s25 26s30 30s26 31s31 45s14
6a4 SecondInput{string} 23m25 26r43 6a22 Name{string} 11r23
7i4 Last_Position{natural} 14m45 23m46 7i7 RealOrImaginary{integer} 15m7 16r14
8a7 InputString{string} 12m28 14m7 14r38 15r40
9i7 Last_Position{integer} 12m41 14r19
20r4 FirstComplex{11|4R9} 25m4 26m4 35r80 51r42 54r42 57r47 60r45
20r18 SecondComplex{11|4R9} 30m4 31m4 36r80 51r56 54r56 57r61 60r59
20r33 Result{11|4R9} 51m10 52r108 54m10 55r113 57m10 58r113 60m10 61r110
21i4 Option{integer} 45m4 49r9

BIN
main.exe

Binary file not shown.

BIN
main.o

Binary file not shown.