troubleshooting Question

C++ mag( ) function and prototype

Avatar of Alyssa Zukas
Alyssa Zukas asked on
ProgrammingC++
3 Comments1 Solution1518 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
MURUGESAN N
Requirement analysis,Application Development,Automation Management.Senior technical manager 17.9+years.Knowledge transfer 18.3+years.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros