Avatar of Alyssa Zukas
Alyssa Zukas
 asked on

C++ mag( ) function and prototype

Assignment I am having trouble with:

Complete 'this program', by adding a function called mag( ) to calculate the magnitude of a vector.  You'll need to add a prototype before main( ), and the implementation (header & body) of the function after main( );

reminder: mag = sqrt (x^2 + y^2)

Calling it with something like:

            vec_length = mag(x, y);

program to be completed:

#include<iostream>
#include<cmath>

using namespace std;

//      for part a, put your function prototype for mag here!


//............................................................

int main(void)
{
    double x = 0;
    double y = 0;
    double v=3.0, w=4.0;
    double m;
   
    cout << "Please enter the X coordinate: ";
    cin >> x;
    cout << "Please enter the Y coordinate: ";
    cin >> y;
   
    m = mag(x,y);       // you need to write this function!
    cout << "The magnitude of ( "<< x << " , "<< y <<" ) is: " << m << endl;
   
    m = mag(v,w);       // now get the magnitude of vector (v,w)
    cout << "The magnitude of ( "<< v << " , "<< w <<" ) is: " << m << endl;
   
   
    return 0;
}


//.................put your mag function here...................
// be sure to add comments describing the inputs and outputs so a reader would
// know how to use it.
ProgrammingC++

Avatar of undefined
Last Comment
MURUGESAN N

8/22/2022 - Mon
evilrix

So, what is it you are specifically having trouble with?
ASKER CERTIFIED SOLUTION
MURUGESAN N

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MURUGESAN N

Best solution provided.
Closing this, since no comment added from Alyssa Zukas.
If modification required, post your comment to Administrator.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23