#include #include #include // I want pair, which is in this. #include #include using namespace std; using point = pair; namespace Euclid { const string D_NAME = "Euclidian"; int avar = 10; double Distance(point a, point b) { double dx, dy; dx = a.first- b.first; dy = a.second - b.second; return sqrt(dx*dx + dy*dy); } } namespace Manhattan { const string D_NAME = "MANHATTAN"; int avar = 20; double Distance(point a, point b); } namespace Hausdorf { double Distance(point a, point b); } namespace Hausdorf { string D_NAME="Hausdorf"; int avar = 30; } double Distance(point, point); const string D_NAME= "Global"; int avar = 0; using namespace Euclid; namespace HD=Hausdorf; ostream & operator << (ostream & s, const point & p) { s << "(" << p.first <<", " << p.second << ")"; return s; } int main() { point x1{0,0}, x2{10,5}; cout << "Computing the distance from " << x1 << " to " << x2 << endl; /* cout << "\t" << setw(10) << "Default" << setw(10) << Distance(x1, x2) << endl; */ cout << "\t" << setw(10) << ::D_NAME << setw(10) << ::Distance(x1, x2) << endl; cout << "\t" << setw(10) << Euclid::D_NAME << setw(10) << Euclid::Distance(x1, x2) << endl; cout << "\t" << setw(10) << Manhattan::D_NAME << setw(10) << Manhattan::Distance(x1, x2) << endl; cout << "\t" << setw(10) << HD::D_NAME << setw(10) << HD::Distance(x1, x2) << endl; cout << endl; Euclid::avar = 10'000; cout << "The values of avar " << endl; cout << ::D_NAME << " " << ::avar << endl; cout << Euclid::D_NAME << " " << Euclid::avar << endl; cout << Manhattan::D_NAME << " " << Manhattan::avar << endl; cout << Hausdorf::D_NAME << " " << Hausdorf::avar << endl; return 0; } double Distance(point, point){ return 1; } double Manhattan::Distance(point a, point b) { double dx, dy; dx = abs(a.first- b.first); dy = abs(a.second - b.second); return (dx + dy); } namespace Hausdorf{ double Distance(point a, point b) { double dx, dy; dx = abs(a.first- b.first); dy = abs(a.second - b.second); return max(dx, dy); } }