Question: Develop overloading functions 'distance' and make the code below works. #include #include double distance(double x1,double x2); // this function returns 1-dimensional distance between x1 and
Develop overloading functions 'distance' and make the code below works.
#include#include double distance(double x1,double x2); // this function returns 1-dimensional distance between x1 and x2 // // Declare functions here // // int main (int argc, char *argv[]){ // Do not change 'main' function body double x1 = 1.2; double x2 = 0.8; double y1 = 3.2; double y2 = 2.9; double z1 = 1.975; double z2 = 1.6; std::cout << "1d distance=" << distance(x1,x2) << std::endl; std::cout << "2d distance=" << distance(x1,y1,x2,y2) << std::endl; std::cout << "3d distance=" << distance(x1,y1,z1,x2,y2,z2) << std::endl; return 0; } double distance(double x1,double x2){ return std::abs(x1 - x2); } // // Define functions here //
- Use an appropriate data type for each variable and function.
- Do not change 'main' function body.
- do this in C++
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
