-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_danger.cpp
73 lines (58 loc) · 1.85 KB
/
detect_danger.cpp
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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// x0 y0 z0 are coordinates in the origin
double radius, x0, y0, z0=0;
cout<<"Please introduce geometric data to build our radar (radius x y):"<<endl;
cin>> radius >> x0 >> y0;
cout<<endl;
radius = radius*radius;
// xt : refers to the x coordinate of a dangerous land (in Spanish --> terrestre) target
// yt : refers to the y coordinate of a dangerous land target
// xa : refers to the x coordinate of a dangerous air target
// ya : refers to the y coordinate of a dangerous air target
// za : refers to the z coordinate of a dangerous air target
// perimT : perimeter of action of the land target
// perimA : perimeter of action of the air target
double xt, yt, xa, ya, za, perimT, perimA;
// This var indicates if the target is a land target or an air target.
// Specified by the user.
char letra;
do {
cout << "What type of target is it, T (land), A (air) or D (none)?: " ;
cin >> letra;
cout << endl;
if(letra=='T')
{
cout << "Land target detected" << endl;
cout << "Please give me its XY coordinates: ";
cin >> xt >> yt;
perimT = pow(xt-x0,2)+pow(yt-y0,2); // calculate the action perimeter
if(perimT < radius)
{
cout<<"ALERT! LAND THREAT!"<<endl;
}else
cout << "It's OK" <<endl;
}
if(letra=='A')
{
cout << "Air target detected" << endl;
cout << "Please give me its XYZ coordinates: ";
cin >> xa >> ya >> za;
perimA=pow(xa-x0,2)+pow(ya-y0,2)+za*za;
if(perimA < radius)
{
cout<<"ALERT! AIR THREAT!"<<endl;
}else
cout << "It's OK" <<endl;
}
if(letra=='D')
{
cout<<"None Threat"<<endl;
cout << "Good Bye" << endl;
}
cout << endl;
} while( letra != 'D' );
}