Can we create a function that is defined as a member of a class (lets say class point) and of type "point" and that takes 2 parameters both of type point? I ve been trying to do that but the program doesnt seem to compile...
#include <iostream>
usingnamespace std;
class point
{
public:
point() {x = 0; y = 0;}
point(double p, double q) {x = p; y = q;}
double x;
double y;
void print();
point midpt(point, point);
};
int main()
{
point a;
a.print();
point b(1,1);
b.print();
point m = midpt(a,b);
m.print();
return 0;
}
void point::print()
{
cout << x << "," << y;
}
point point::midpt(point a, point b)
{
point m;
m.x = (a.x + b.x) / 2;
m.y = (a.y + b.y) / 2;
return m;
}
#include <iostream>
usingnamespace std;
class point
{
public:
point() {x = 0; y = 0;}
point(double p, double q) {x = p; y = q;}
double x;
double y;
void print();
point midpt(point, point);
};
int main()
{
point a;
a.print();
point b(1,1);
b.print();
point m = midpt(a,b);
m.print();
return 0;
}
void point::print()
{
cout << x << "," << y;
}
point point::midpt(point a, point b)
{
point m;
m.x = (a.x + b.x) / 2;
m.y = (a.y + b.y) / 2;
return m;
}
#include <iostream>
usingnamespace std;
class point
{
public:
point() {x = 0; y = 0;}
point(double p, double q) {x = p; y = q;}
double x;
double y;
void print();
point midpt(point, point);
};
int main()
{
point a;
a.print();
point b(1,1);
b.print();
point m = midpt(a,b);
m.print();
return 0;
}
void point::print()
{
cout << x << "," << y;
}
point point::midpt(point a, point b)
{
point m;
m.x = (a.x + b.x) / 2;
m.y = (a.y + b.y) / 2;
return m;
}