#include <iostream>
#include <cmath>
struct points {
double x = 0;
double y = 0;
points midpt() const {
points a;
a.x = x / 2;
a.y = y / 2;
return /** what do I put here so it returns and creates a new point that is this point's midpoint */
}
};
int main() {
points a{3, 7};
a.midpt();
std::cout << "midpoint = " << a.x << ", " << a.y << std::endl;
}
// this just returns "midpoint = 3, 7"
I'm trying to make it so the function returns and creates a new point that is this point's midpoint so I don't have to create a new point in the main function.
I mean like is there a way to get the Point so I can plug it back in to get the mid point of the mid point without cout just so it returns the points but as a new point
#include <iostream>
struct point {
double x = 0 ;
double y = 0 ;
point mid() const { return point{ x/2, y/2 } ; }
};
int main() {
const point a { 3, 7 } ;
// get the mid point of the mid point
const point b = a.mid().mid() ;
std::cout << "mid point of mid point: " << b.x << ", " << b.y << '\n' ;
// get the mid point of the mid point of the midpoint
constauto c = a.mid().mid().mid() ;
std::cout << "mid point of mid point of mid point: " << c.x << ", " << c.y << '\n' ;
}