Given the mass of an object we can calculate the energy cont
Given the mass of an object, we can calculate the energy contained in the object and also the weight of the object.
Given the mass of an object, we can calculated the energy contained in the object as:
E=mc2
Where m is the mass in kilograms, c is the speed of light (3.0 x 108 m/s) and E is the energy in Joules.
Given the mass of an object, we can calculated the weight of the object as:
w=mg
Where m is the mass of the unit in kilograms, g is the gravitational constant for the planet that the object is located on, and w is the weight in Newtons. For the gravitational constant, we’ll use Earth’s which is 9.8 m/s/s.
Programming Exercise:
Create a program that asks the user for the mass of an object. Write a function that takes the mass as a pass by value parameter and calculates the energy and weight and returns these as pass by reference parameters. The main function of the program displays the energy and weight with the correct units.
Program Used: Visual Studios, C++
Solution
#include<iostream>
 using namespace std;
void calculate(float mass,double &energy,double &weight)
 {
 double gravitationalConstant = 9.8;
 double speedOfLight = 300000000.0;
 energy = mass*speedOfLight*speedOfLight;
   
 weight = mass*gravitationalConstant;
 }
int main()
 {
 float mass;
 double weight,energy;
   
 cout << \"Input the mass of the object in kg : \";
 cin >> mass;
 calculate(mass,energy,weight);
   
 cout << \"Energy is : \" << energy << \" Joules.\" << endl;
 cout << \"Weight is : \" << weight << \" Newtons.\" << endl;
 return 0;
   
 }
OUTPUT:
Input the mass of the object in kg : 10
Energy is : 9e+17 Joules.
 Weight is : 98 Newtons.

