wex6_10.cpp

来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 30 行

CPP
30
字号
#include <iostream.h>
#include <math.h>
#pragma hdrstop

#include "wex6_9.h"

// compute the distance between a and b
double Distance(const Complex& a, const Complex& b)
{
	// record the difference of the real and imag parts
	double deltax = b.GetReal() - a.GetReal(),
		   deltay = b.GetImag() - a.GetImag();
		   
	// distance between = square root of sum of squares
	return sqrt(deltax*deltax + deltay*deltay);
}

void main(void)
{
	Complex A(1,2), B(3,5);
	
	cout << Distance(A,B) << endl;
}

/*
<Run>

3.605551
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?