Помощь с программой (пеленгатор)
06.05.2013, 15:08. Показов 459. Ответов 0
2 варианта, оба работают некорректно - первый с отдельным модулем, второй как самостоятельная прога. кончились идеи. ошибки разные, то "переполнение плавающей точки", то просто лажу в файл выводит, то вообще ничего не делают. помогите объеденить и поправить, мозг уже выжат.
итак, первая лажа (с модулем)
Pascal | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
| program l5;
uses unt;
var
f:text;
TRLS:RLS;
tip:string;
x0,y0,V,t0,tk,xrls,yrls,r:real;
begin
writeln('na4alnoe i kone4noe vremya, koordinaty RLS i radius obnaruzheniya');
readln(t0, tk, xrls, yrls, r);
TRLS.init(xrls,yrls,r);
TRLS.peleng(t0,tk);
readln;
end. |
|
Pascal | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
| Unit unt;
interface
const
c=3;
type
missile=^TMissile;
plane=^TAircraft;
pr=^TTarget;
TTarget=object
x0,y0,V,k,x,y,n,t0:real;
tip:string;
constructor init(ax0,ay0,aV,ak:real; atip:string);
destructor destroy;
procedure Move(ti:real);
end;
TAircraft=object(TTarget)
end;
TMissile=object(TTarget)
constructor init(ax0,ay0,aV,ak,an:real; atip:string);
procedure Move(ti:real);virtual;
end;
RLS=object
xrls,yrls,r:real;
massiv:array [1..c] of pr;
constructor init(axrls,ayrls,ar:real);
procedure Peleng(t0,tk:real);
destructor destroy;
end;
implementation
constructor TTarget.init(ax0,ay0,aV,ak:real;atip:string);
begin
tip:=atip;
x0:=ax0;
y0:=ay0;
V:=aV;
k:=aK;
end;
destructor TTarget.destroy;
begin
end;
procedure TTarget.Move(ti:real);
begin
x:=x0-V*cos(k)*(ti-t0);
y:=y0-V*sin(k)*(ti-t0);
end;
constructor TMissile.init(ax0,ay0,aV,ak,an:real;atip:string);
begin
tip:=atip;
x0:=ax0;
y0:=ay0;
V:=aV;
k:=ak;
n:=an;
end;
procedure TMissile.Move(ti:real);
begin
x:=x0-cos(k)*(V+N*(ti-t0))*(ti-t0);
y:=y0-sin(k)*(V+N*(ti-t0))*(ti-t0);
end;
constructor RLS.init(axrls,ayrls,ar:real);
var
z,i:byte;
ax0,ay0,aV,ak,n:real;
atip:string;
begin
for i:=1 to c do
begin
writeln('‚ўҐ¤ЁвҐ вЁЇ 楫Ё:');
writeln('1-а*ЄҐв*');
writeln('2-б*¬®«св');
readln(z);
if (z>=1) and (z<=2) then
case z of
1:begin
writeln('na4alnie koordinaty rakety, skorost, ugol i uskorenie');
readln(ax0,ay0,aV,ak,n);
atip:='raketa';
massiv[i]:=New(missile,init(ax0,ay0,aV,ak,n,atip));
end;
2:begin
writeln('nachalnie koordinaty, skorost i ugol samoleta');
readln(ax0,ay0,aV,ak);
atip:='samolet';
massiv[i]:=New(plane,init(ax0,ay0,aV,ak,atip));
end;
end
else
writeln('Wrong target');
xrls:=axrls;
yrls:=ayrls;
r:=ar;
end;
end;
destructor RLS.destroy;
begin
end;
procedure RLS.Peleng(t0,tk:real);
var
t,dt,d,tm, tn:real;
f:text;
i,number:integer;
tar1,tar2,tar3,tar4,tar5:real;
a:array[1..c] of real;
az:array[1..c] of real;
begin
assign(f,'RLS.txt');
rewrite(f);
t:=t0;
writeln('shag vremeni');
readln(dt);
tn:=tk;
while t<tk do
begin
t:=t+dt;
for i:=1 to c do
begin
massiv[i]^.move(t);
D:=sqrt((massiv[i]^.x - xrls)*(massiv[i]^.x - xrls)+(massiv[i]^.y-yrls)*(massiv[i]^.y-yrls));
if D<=r then if massiv[i]^.tip='raketa' then
tm:=abs(-massiv[i]^.V + sqrt((massiv[i]^.V*massiv[i]^.V)+(2*massiv[i]^.n*D))/massiv[i]^.n)
else
tm:=D/massiv[i]^.V;
if massiv[i]^.tip='raketa' then
massiv[i]^.V:=massiv[i]^.V+massiv[i]^.n*dt;
if (D<=r) and (tn>tm) then begin
tn:=tm; number:=i; end;
az[i]:=abs(arctan((massiv[i]^.y-yrls)/(massiv[i]^.x-xrls)));
write('nomer celi:',i,' ');
write ('vremya',t:4:1);
write('rasstoyanie:',D:2:2,' ');
write('vremya do popadania ', tm:4:4,' ');
writeln('azimuth=',az[i]:4:4);
end;
end;
end;
write(f,'Nomer celi s minimalnim vremenem do popadaniya do i vremya poleta - ',number,' ',tn:4:4);
writeln('Nomer celi s minimalnim vremenem do popadaniya do i vremya poleta - ',number,' ',tn:4:4);
close(f);
end;
end. |
|
лажа намбер ту
Pascal | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
| const g=255;
type
targettype = (aircraft, missile);
ptarget=^ttarget;
paircraft=^taircraft;
pmissile=^tmissile;
ttarget = object
x0,y0,v,k,t,xt,yt:real;
ttype:targettype;
constructor create;
procedure move(ti:real); virtual;
end;
taircraft = object (ttarget)
procedure move(ti:real);virtual;
constructor create;
end;
tmissile = object (ttarget)
n:real;
procedure move(ti:real); virtual;
constructor create;
end;
trls = object
xr,yr,dr:real;
atarget: array [1..g] of ttarget;
procedure initposition;
procedure pelengate(ptt:ptarget; t,dt:real);
end;
constructor ttarget.create;
begin end;
constructor taircraft.create;
begin
writeln('Vvedite koordinaty, skorost i ugol');
readln(x0, y0, v, k); end;
constructor tmissile.create;
begin
writeln('Vvedite koordinaty, skorost, uskorenie i ugol');
readln(x0,y0,v,n,k); end;
procedure trls.initposition;
begin writeln('Nachalnie koordinaty RLS i ego dalnost');
readln(xr,yr,dr); end;
procedure ttarget.move(ti:real);
begin end;
procedure taircraft.move(ti:real);
begin
xt:=x0+v*ti*cos(k);
yt:=y0+v*ti*sin(k);
end;
procedure tmissile.move(ti:real);
begin
xt:=x0+v*ti+n*cos(k)*sqr(ti)/2;
yt:=y0+v*ti+n*sin(k)*sqr(ti)/2;
end;
procedure trls.pelengate(ptt:ptarget; t,dt:real);
var az,d:real;
ip,ik:integer;
tf:text;
begin
assign(tf,'rls.txt');
append(tf);
ik:=round(t/dt);
for ip:=1 to ik do begin
ptt^.move(t);
d:=sqrt(sqr(ptt^.xt-xr)+sqr(ptt^.yt-yr));
az:=arctan((ptt^.yt-yr)/(ptt^.xt-xr));
if dr>=sqrt(sqr(ptt^.xt-xr)+sqr(ptt^.yt-yr)) then
writeln(tf,'Time - ',t,' Dalnost - ',d,' Azimuth - ',az);
t:=t+dt; end; close(tf); end;
var c,j:integer;
rs:trls;
ptt: ^ttarget;
targtype: byte;
dt,t:real;
begin
Writeln('Vremya i shag');
readln(t,dt);
rs.initposition;
writeln('Kolli4estvo celei');
readln(c);
for j:=1 to c do begin
writeln('Type of target (1 - aircraft, 2 - missile)');
readln(targtype);
case targtype of
1: ptt:=new(paircraft,create);
2: ptt:=new(pmissile,create);
end;
rs.pelengate(ptt,t,dt);
end;
end. |
|
|