C++ Momentum is defined as the product of an item\'s mass and its velocity. Mass
ID: 3688359 • Letter: C
Question
C++
Momentum is defined as the product of an item's mass and its velocity. Mass is a scalar value, whereas velocity is generally expressed as a vector quantity with three components. The product of the scalar moss and the velocity yields momentum as a vector quantity. Write a function named momentum that will accept as arguments a one-dimensional velocity array with three values (type double) (i.e. a 3d vector) and a mass (type double), and return a dynamically allocated array representing the momentum. Note the momentum is determined by multiplying the scalar mass by each element of the vector array. Test your momentum function by constructing a short main program that will ask the user to input values for the velocity and mass from the console, and then display the momentum.Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
double* FindMomentum(double vel[],double m)
{
double momentum[3];
int i;
for(i=0;i<3;i++)
{
cout << "mass :" <<m << " ";
momentum[i]=m*vel[i];
}
return momentum;
}
int main()
{
double mass,velocity[3],*mom;
int i;
cout << "Enter the mass:";
cin >> mass;
cout << "Enter the velocity vector values(3):";
for(i=0;i<3;i++)
cin >> velocity[i];
mom=FindMomentum(velocity,mass);
cout << "Momentum vector is : ";
for(i=0;i<3;i++)
cout <<*(mom+i)<<setprecision(2)<< " ";
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.