Answer to Question #156811 in C++ for Gem

Question #156811

From of C++ classes and object, one of the company which is Company ABC, an airline company is closely monitoring the distance between airplanes as they take-off in the same airport. You are asked to create a system that would calculate the distance between two planes A and B given the following plane attributes: Take-off Time, Speed (mi/hr), direction (north, east, west, south). Also, given the time where the navigation officer would like to check the distance.


DISPLAY:

AIR TIME OF PLANE A AND B -TIME ON AIR TO TAKE OFF

DISTANCE OF PLANE A AND B FROM THE AIRPORT

DISTANCE BETWEEN PLANE A AND B



1
Expert's answer
2021-01-22T11:44:55-0500
#include <iostream>
#include <cmath>
using namespace std;

int times = 0;

class plane
{
private:
	int take_off_time = 0; //Departure time from the airport
	int airtime = 0; //flight time
	int speed = 0; //speed plane
	string direction = "N/C"; // direction plane
	bool dir = 0; //Variable for easy calculation of the distance between planes depending on the direction.
public:
	void input() //The input of initial data
	{
		cin >> take_off_time;
		cin >> speed;
		char c;
		cin >> c;
		switch (c)
		{
		case 'n':
			direction = "North";
			break;
		case 'e':
			direction = "East";
			dir = 1;
			break; 
		case 'w':
				direction = "West";
				dir = 1;
				break;
		case 's':
			direction = "South";
			break;
		}
	}
	void air_time() //Displays the flight time.
	{
		if (times>take_off_time)
		airtime++;
		cout <<airtime<<endl;
		
	}
	void distance_airport() //Distance to the airport
	{
		int dis = airtime*speed;
		cout << dis<<endl;
	}
	
	void dis_ab(plane b) //Distance between planes
	{
		float dis;
		if (direction == b.direction)
			dis = abs(airtime*speed - b.airtime*b.speed);
		else
		{
			if (dir && b.dir)
			{
				dis = airtime*speed + b.airtime*b.speed;
			}
			else
				dis = sqrt(pow(airtime*speed, 2) + pow(b.airtime*b.speed, 2));
		
		}	
		cout << "Distance between plane A and B " << dis << endl;
	}
};
int main() {
	plane a, b;
	cout << "Enter the departure time (in whole hours), the speed (in mi / hr), and the first letter of the direction (n, e, w, s) of plane A: ";
	a.input();
	cout << "Enter the departure time (in whole hours), the speed (in mi / hr), and the first letter of the direction (n, e, w, s) of plane B: ";
	b.input();
	char c='c';
	while (c!='n')
	{
		cout << "**********************************\n";
		cout << "Time " << times << " hours\n";
		cout << "Flight time of plane A: ";
		a.air_time();
		cout << "Distance to the airport from plane A: ";
		a.distance_airport();
		cout << "Flight time of plane B: ";
		b.air_time();
		cout << "Distance to the airport from plane B: ";
		b.distance_airport();
		a.dis_ab(b);
		cout << "**********************************\n";
		times++;
		cout << "Enter 'n' to end the program , and 'y' to get the report for the next hour: ";
		cin >> c;
		system("cls");
	}
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog