Answer to Question #194283 in C++ for Faizan

Question #194283

Two point lies on plane each point has two axis x and y. write a function having point return type to calculate mid-point of two points. Hint class point, data members x, y, return object. In c++


1
Expert's answer
2021-05-21T16:49:55-0400
#include <iostream>


using namespace std;
struct Point{
    float x;
    float y;
};
Point midPoint(float x1,float y1,float x2,float y2){
    float x_mid=(x1+x2)/2;
    float y_mid=(y1+y2)/2;
    Point result={x_mid,y_mid};
    return result;
}


int main()
{
    Point m;
    m=midPoint(-1.0,2.1,-4.2,6.3);
    std::cout <<std::endl<< "The mid point is: " << m;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS