Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 25th, 2004, 08:43 PM
fscwv_student fscwv_student is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 fscwv_student User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Anyone who knows Ada, pls. help me


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT