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.
#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;
}
Comments
Leave a comment