home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
defargs1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-17
|
948b
|
36 lines
// C++ program illustrates default arguments
#include <iostream.h>
#include <math.h>
inline double sqr(double x)
{ return x * x; }
double distance(double x2, double y2,
double x1 = 0, double y1 = 0)
{
return sqrt(sqr(x2 - x1) + sqr(y2 - y1));
}
main()
{
double x1, y1, x2, y2;
cout << "Enter x coordinate for point 1: ";
cin >> x1;
cout << "Enter y coordinate for point 1: ";
cin >> y1;
cout << "Enter x coordinate for point 2: ";
cin >> x2;
cout << "Enter y coordinate for point 2: ";
cin >> y2;
cout << "distance between points = "
<< distance(x1, y1, x2, y2) << "\n";
cout << "distance between point 1 and (0,0) = "
<< distance(x1, y1, 0) << "\n";
cout << "distance between point 2 and (0,0) = "
<< distance(x2, y2) << "\n";
return 0;
}