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++
#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;
}
Comments
Leave a comment