develop a class AirborneLocation that represents the location of airplanes with
ID: 3557056 • Letter: D
Question
develop a class AirborneLocation that represents the location of airplanes with respect to a reference radar location. Each AirborneLocation object should include data member for aircraftID (integer),
aircraft type (M or C as a char) and the position x,y, and z (double). the x corresponds to east or west with east being positive. the y corresponds to north or south with the north being positive
the z coesponds to up or down with up being positive.
the class should have functions for getting and setting each of its data members. it should also have functions for calculates how far the plane is from the reference (x^2+y^2+z^2)^(1/2)
the main program should read in data from a file. a sample file is given below. then it should ouput all the information in the file in nice neat columns along with the plane that is the closest
and he farthest from the radar station
example
7194 M 95.2 20.4 3.5
9502 C -38.1 -45.9 -1.1
7771 C 55.7 -50.2 .3
9947 M -87.6 14.5 2.0
1213 C 10.8 -96.5 1.5
Explanation / Answer
#include <iostream>
#include <cstdio>
#include <cmath>
#include <fstream>
using namespace std;
class AirborneLocation{
private:
int aircraftID;
char type;
double x,y,z;
public:
int getAircraftID()
{
return aircraftID;
}
void setAircraftID(int id)
{
aircraftID=id;
}
char getAircraftType()
{
return type;
}
void setAircraftType(char _type)
{
type=_type;
}
double getLocationX()
{
return x;
}
void setLocationX(double _x)
{
x=_x;
}
double getLocationY()
{
return y;
}
void setLocationY(double _y)
{
y=_y;
}
double getLocationZ()
{
return z;
}
void setLocationZ(double _z)
{
z=_z;
}
double distanceFromReference()
{
return sqrt(x*x+y*y+z*z);
}
};
int main()
{
ifstream myfile("text.txt");
int id;
char ch;
double x,y,z;
AirborneLocation t[5];
for(int i=0;i<5;i++)
{
myfile>>id>>ch>>x>>y>>z;
t[i].setAircraftID(id);
t[i].setAircraftType(ch);
t[i].setLocationX(x);
t[i].setLocationY(y);
t[i].setLocationZ(z);
}
ofstream inf("output_text.txt");
double NearestRadar=10000000.0,FarthestRadar=-1.0;
for(int i=0;i<5;i++)
{
if(t[i].distanceFromReference()<NearestRadar)
NearestRadar=t[i].distanceFromReference();
if(t[i].distanceFromReference()>FarthestRadar)
FarthestRadar=t[i].distanceFromReference();
inf<<t[i].getAircraftID()<<" "<<t[i].getAircraftType()<<" "<<t[i].getLocationX()<<" "<<t[i].getLocationY()<<" "<<t[i].getLocationZ()<<endl;
}
inf<<"Nearest Radar : "<<NearestRadar<<endl;
inf<<"Farthest Radar : "<<FarthestRadar<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.