|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Anyone who knows Ada, pls. help me
I just began learning ada language and my professor asked us to make a program that will calculate the smallest distance between two points, and show what point they are. the range is from 20.0 .. -20.0 and delta x defines the x in the formula axx+bx+c. I made the program but I don't know which part in my logic is wrong, can anyone pls. help. and can I also pls ask if someone can teach me how to declare and use a function in a main program in ada. thank you very much.
this is my code : with Ada.Text_IO, Ada.Float_Text_IO; with ada.Numerics.Generic_elementary_functions; use Ada.Text_IO, Ada.float_text_IO; use Ada; procedure Main is Package squareRoot IS new ada.numerics.Generic_elementary_functions(float); use SquareRoot; Type ListArray is array (1..1000) of float; x : ListArray; y1 : ListArray; y2 : ListArray; a1 : Float; a2 : Float; b1 : float; b2 : float; c1 : float; c2 : float; dx : float; DX1 : float; DY1 : float; DX2 : float; DY2 : float; OldX : Float; point1 :float; point2 :float; Distance:float; point1a : float; point2a : float; sumMulti : Float; smallestdistance : float; counter : Integer; Limit:Integer; begin put ("Enter A for Function 1 : "); get (a1); New_Line; put ("Enter A for Function 2 : "); get (a2); New_Line; put ("Enter B for Function 1 : "); get (B1); New_Line; put ("Enter B for Function 2 : "); get (B2); New_Line; put ("Enter C for Function 1 : "); get (C1); New_Line; put ("Enter C for Function 2 : "); get (C2); New_Line; Put ("Enter delta x value :"); Get (dx); New_Line; counter := 1; OldX := -20.0; while (X(counter) <= 20.0) loop x(Counter):=OldX; y1(counter) := a1*OldX*OldX + b1*OldX + c1; y2(counter) := a2*OldX*OldX + b2*OldX + c2; counter := counter + 1; OldX:= OldX + DX; end loop; limit:=Integer(40.00/dx); for h in 1..Limit loop dX1:=X(h);DY1:=Y1(h); for i in 1..Limit loop DX2:=X(i);DY2:=Y2(i); SumMulti := (DX1-DX2)*(DX1-DX2)+(DY1-DY2)*(DY1-DY2); Distance := SquareRoot.sqrt(sumMulti); if DX1=-20.0 and DX2=-20.0 then SmallestDistance:=Distance; end if; if Distance<=SmallestDistance then SmallestDistance:=distance; point1 := dX1; Point1a := dY1; Point2 := dX2; Point2a := DY2; end if; end loop ; end loop; Put ("The smallest distace is : "); Put (SmallestDistance, 8, 3, 0); New_line; Put ("the smallest distance lies on : "); new_Line; New_Line; Put ("Line 1 : "); Put (Point1, 8, 3, 0); Put (Point1a, 8, 3, 0); new_line; Put ("Line 2 : "); Put (Point2, 8, 3, 0); Put (point2a, 8, 3 ,0); end main; |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Anyone who knows Ada, pls. help me |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|