Answer to Question #183094 in C++ for Waleed Abid

Question #183094

Suppose in Islamabad International Airport the plans arrivals and departures are frequent and they are moving with kinetic energy. Your task is to write a class to find the kinetic energy of an airplane coming from the UK having the mass and the velocity known to pilots only. You are a pilot so your captain of the plane has given you the task to write a class to perform the calculation, the function must be defined outside the class. Your task is to provide the mass and velocity as arguments to the function and then display the kinetic energy without returning a value.


1
Expert's answer
2021-04-20T08:37:13-0400
#include <iostream>
#include <iomanip>
 
using namespace std;
 
class Plane
{
public:
	Plane() { speed = 0; mass = 0; }
	void SetSpeed(double s) { speed = s; }
	void SetMass(double m) { mass = m; }
	double GetSpeed() { return speed; }
	double GetMass() { return mass; }
private:
	double speed;
	double mass;
};
 
void DisplayE(double mass, double speed)
{
	cout << "Kinetic energy of plane is: " << mass * speed * speed / 2 << "J" << endl;
}
 
int main()
{
	Plane plane;
	cout << "Enter plane mass in kg: ";
	double mass = 0;
	cin >> mass;
	cout << "Enter plane speed in m/s: ";
	double speed = 0;
	cin >> speed;
	cout << endl;
	plane.SetMass(mass);
	plane.SetSpeed(speed);
	cout << fixed << setprecision(2);
	DisplayE(plane.GetMass(), plane.GetSpeed());
	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
APPROVED BY CLIENTS