2023-10-25 14:04:40 +00:00
|
|
|
with ComplexCalculator;
|
|
|
|
with Ada.Text_IO;
|
|
|
|
|
2023-10-25 15:28:39 +00:00
|
|
|
procedure Main is
|
2023-11-12 22:08:12 +00:00
|
|
|
-- Helper Function to make life easier.
|
|
|
|
function GetInput(Name : String) return Integer is
|
|
|
|
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;
|
|
|
|
|
2023-10-25 14:04:40 +00:00
|
|
|
begin
|
2023-11-12 22:08:12 +00:00
|
|
|
-- Creating the first complex number.
|
|
|
|
FirstComplex.Real := GetInput("Enter First Real Number: ");
|
|
|
|
FirstComplex.Imaginary := GetInput("Enter First Imaginary Number: ");
|
|
|
|
Ada.Text_IO.Put_Line("");
|
2023-10-25 15:02:27 +00:00
|
|
|
|
2023-11-12 22:08:12 +00:00
|
|
|
-- Creating the second complex numebr.
|
|
|
|
SecondComplex.Real := GetInput("Enter Second Real Number: ");
|
|
|
|
SecondComplex.Imaginary := GetInput("Enter Second Imaginary Number: ");
|
|
|
|
Ada.Text_IO.Put_Line("");
|
2023-10-25 15:02:27 +00:00
|
|
|
|
2023-11-12 22:08:12 +00:00
|
|
|
-- Printing out the result of both creations.
|
|
|
|
Ada.Text_IO.Put_Line("First Complex Number: " & ComplexCalculator.ToString(FirstComplex));
|
|
|
|
Ada.Text_IO.Put_Line("Second Complex Number: " & ComplexCalculator.ToString(SecondComplex));
|
2023-10-25 15:28:39 +00:00
|
|
|
|
2023-11-12 22:08:12 +00:00
|
|
|
-- Giving the menu options for what calcualtion to do.
|
|
|
|
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;
|
2023-10-25 15:28:39 +00:00
|
|
|
|
|
|
|
end Main;
|