home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
advfun5.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-03
|
866b
|
39 lines
// C++ program which uses a function that passes
// a structure by pointer
#include <iostream.h>
struct point {
double x;
double y;
};
// declare the prototype of function getMedian
point getMedian(const point*, const point*);
main()
{
point pt1;
point pt2;
point median;
cout << "Enter the X and Y coordinates for point # 1 : ";
cin >> pt1.x >> pt1.y;
cout << "Enter the X and Y coordinates for point # 2 : ";
cin >> pt2.x >> pt2.y;
// get the coordinates for the median point
median = getMedian(&pt1, &pt2);
// get the median point
cout << "Mid point is (" << median.x
<< ", " << median.y << ")\n";
return 0;
}
point getMedian(const point* p1, const point* p2)
{
point result;
result.x = (p1->x + p2->x) / 2;
result.y = (p1->y + p2->y) / 2;
return result;
};