This repository has been archived on 2024-01-18. You can view files and clone it, but cannot push or open issues or pull requests.
Turner-CS4308-Homework_4/main.adb
Jonathan Turner 4ed4aff9b6 done I think
2023-11-12 17:08:12 -05:00

67 lines
2.7 KiB
Ada

with ComplexCalculator;
with Ada.Text_IO;
procedure Main is
-- 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;
begin
-- Creating the first complex number.
FirstComplex.Real := GetInput("Enter First Real Number: ");
FirstComplex.Imaginary := GetInput("Enter First Imaginary Number: ");
Ada.Text_IO.Put_Line("");
-- Creating the second complex numebr.
SecondComplex.Real := GetInput("Enter Second Real Number: ");
SecondComplex.Imaginary := GetInput("Enter Second Imaginary Number: ");
Ada.Text_IO.Put_Line("");
-- 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));
-- 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;
end Main;