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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
| #include <iostream>
#include <math.h>
#include <cstdlib>
#include <fstream>
using namespace std;
const float pi = 3.14;
enum ttargeti { Aircraft, Missile };
class TTarget
{
private:
double x0,y0,v,a;
public:
TTarget () {};
ttargeti target_tip;
string target_get();
int t0;
virtual void Move(double t) = 0;
double get_x() {return x0;}
double get_y() {return y0;}
double get_v() {return v;}
double get_a() {return a;}
void set_x(double ax) {x0 = ax;}
void set_y(double ay) {y0 = ay;}
void set_v(double av) {v = av;}
void set_a(double aa) {a = aa;}
};
string TTarget::target_get()
{
switch (this->target_tip)
{
case ttargeti::Aircraft:
return "Aircraft";
case ttargeti::Missile:
return "Missile";
}
}
class TAircraft: public TTarget
{
private:
void init(double ax, double ay, double av, double aa)
{
set_x(ax); set_y(ay); set_v(av); set_a(aa);
}
void Move(double t) override
{
double x=get_x();
double y=get_y();
double v=get_v();
double a=get_a();
set_x( x - v*cos(a)*(t-t0) );
set_y( y - v*sin(a)*(t-t0) );
};
public:
TAircraft():TTarget () {}
};
class TMissile: public TTarget
{
double n;
void init(double ax,double ay, double av, double aa)
{
set_x(ax); set_y(ay); set_v(av); set_a(aa); n = rand() % 10;
}
void Move(double t) override
{
{
double x=get_x();
double y=get_y();
double v=get_v();
double a=get_a();
set_x(x - (v+n*(t-t0))*cos(a)*(t-t0));
set_y(y - (v+n*(t-t0))*sin(a)*(t-t0));
}
};
public:
TMissile():TTarget() {}
};
class TRLS
{
private:
double x, y, R;
double Xb,Yb;
int ka,km,NTargets;
double D, eps, tstart, tend, dt, ti;
TTarget** targets = NULL;
public:
void init();
void peleng();
TRLS();
};
TRLS::TRLS()
{
cout<<"Rls x, y: ";
cin>>x>>y;
cout<<"Rls R: "<<endl;
cin>>R;
cout<<"t_start: ";
cin>>tstart;
cout<<"t_end: ";
cin>>tend;
cout<<"kol-vo aircraft: ";
cin>>ka;
cout<<"kol-vo missile: ";
cin>>km;
cout<<"Base x, y: ";
cin>>Xb>>Yb;
NTargets=ka+km;
targets = new TTarget*[NTargets];
for (int j=0; j<(NTargets); j++)
{
if (j<ka)
{
targets[j] = new TAircraft;
}
else targets[j] = new TMissile;
targets[j]->set_x(rand() % 15);
targets[j]->set_y(rand() % 15);
targets[j]->set_v(rand() % 10);
targets[j]->set_a(rand() % 360);
}
}
void TRLS::peleng()
{
string target_type;
ofstream fout("output.txt");
double dx,dy;
dt = (tend - tstart) / 5;
ti = tstart;
while (ti < tend)
{
for (int i=0; i<NTargets;i++)
{
targets[i]->t0 = tstart;
targets[i]->Move(ti);
dx=targets[i]->get_x() - Xb;
dy=targets[i]->get_y() - Yb;
D = sqrt((dx * dx) + (dy * dy));
if (D <= R)
{
if (x==0) eps=-1;
if (targets[i]->get_x() > 0)
{
if (targets[i]->get_y() > 0)
eps = atan(dy / dx)+pi/2;
if (targets[i]->get_y() < 0)
eps = -atan(dy / dx);
}
else if (targets[i]->get_x() < 0)
{
if (targets[i]->get_y() > 0)
eps = atan(dy / dx) + pi/2;
if (targets[i]->get_y() < 0)
eps = atan(dy / dx) + pi;
}
target_type=targets[i]->target_get();
fout << "target № " << i << " "<< target_type<< " time = " << ti << " distance = " << D << " Azimut = " << eps*180.0 << endl;
fout.flush();
}
}
ti=ti+dt;
fout << "New time = "<< ti<<"\n"<<endl;
}
delete[] *targets;
}; |