Problem D1 You will need to include the iomanip library, as well as the iostream
ID: 3666195 • Letter: P
Question
Problem D1
You will need to include the iomanip library, as well as the iostream library, for this problem.
In classical physics:
momentum is mass times velocity ( m * v )
kinetic energy is one half the mass times the square of the velocity ( m * v2 / 2 )
Prompts the user for the mass and the velocity as input.
Use double variables.
Then compute the momentum and kinetic energy.
Print the momentum and the kinetic energy with identifying text.
The execution result should have six lines 1) input mass, 2) input velocity, 3) output mass, 4) output velocity, 5) momentum, 6) kinetic energy.
Round the printed values to two decimal positions and align the decimal points.
Test data, run the program twice:
First test input 5.0 kilograms and 4.0 meters per second
Second test input 3.15 kilograms and 10.0 meters per second
Note: With the input in kilograms and meters per second, the units for the momentum is Kg m/s and for Kinetic energy is Joules.
Explanation / Answer
#include <iostream> // cout, fixed
#include <iomanip> // setprecision
using namespace std;
int main () {
double mass,velocity,momentum,kinetic_energy;
cout << "Enter the mass(in KG) and the velocity(in m\s)" << ' ';
cin >>mass>>velocity;
momentum = mass * velocity;
kinetic_energy = mass * velocity * velocity /2;
cout << setw(40);
cout << fixed;
cout << setw(40)<<"Input Mass : "<<setprecision(2) << mass << " Kg ";
cout << setw(40)<<"Input Velocity : "<<setprecision(2) << velocity << " m\s ";
cout << setw(40)<<"Output Mass : "<<setprecision(2) << mass << " Kg ";
cout << setw(40)<<"Output Velocity : "<<setprecision(2) << velocity << " m\s ";
cout << setw(40)<<"Momentum : "<<setprecision(2) << momentum << " Kg m\S ";
cout << setw(40)<<"Kinetic_Energy : "<<setprecision(2) << kinetic_energy << " J ";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.