#include #include using namespace std; #include "utility.h" int main() { cout << fixed; // show fixed decimal cout << "Testing the double swap." << endl; double d1 = 0.4563245792; double d2 = 0.4563245791; cout << "Before swap -- d1 = " << d1 << " and d2 = " << d2 << endl; swap(d1,d2); cout << "After swap -- d1 = " << d1 << " and d2 = " << d2 << endl; cout << endl; cout << "Testing the floating point equality" << endl; cout << "Using the == operator : they are the "; if (d1-d2 == 0.0000000001) cout << "Same"; else cout << "Different"; cout << endl; cout << "Using the dEqual function : they are the "; if (dEqual(d1-d2,0.0000000001)) cout << "Same"; else cout << "Different"; cout << endl << endl; cout << "Testing the round function." << endl; cout << d1 << " rounded to two decimals is " << round(d1,2) << endl; cout << d2 << " rounded to three decimals is " << round(d2,3) << endl; cout << endl; cout << setprecision(5); //show 5 decimals cout << "Testing the floating swap." << endl; float f1 = 0.45632; float f2 = 0.32415; cout << "Before swap -- f1 = " << f1 << " and f2 = " << f2 << endl; swap(f1,f2); cout << "After swap -- f1 = " << f1 << " and f2 = " << f2 << endl; cout << endl; cout << "Testing the integer swap." << endl; int i = 34; int j = -78; cout << "Before swap -- i = " << i << " and j = " << j << endl; swap(i,j); cout << "After swap -- i= " << i << " and j = " << j << endl; cout << endl; return 0; }