//************************************************************************** // header file for a library of auxiliary utility functions //************************************************************************** #ifndef UTILITY_H #define UTILITY_H #include const double PI = atan(1.0)*4.0; const double TOLERANCE = 1.0E-8; //************************************************************************ // function to compare two double for "equality". Returns true if they // are within TOLERANCE of each other. //************************************************************************ bool dEqual( double x, double y); //************************************************************************ // function to exchange the values stored in two integer locations // // post-condition -- a and b have their values exchanged //************************************************************************ void swap(int& a, int& b); //************************************************************************ // function to exchange the values stored in two float locations // // post-condition -- a and b have their values exchanged //************************************************************************ void swap(float& a, float& b); //************************************************************************ // function to exchange the values stored in two double locations // // post-condition -- a and b have their values exchanged //************************************************************************ void swap(double& a, double& b); //************************************************************************ // function to return a random integer between 1 and n // // pre-condtion -- n > 0 // post-condition -- the returned value is between 1 and n inclusive //************************************************************************ int rand(int n); //************************************************************************ // function to return a random integer between a and b // // pre-condtion -- a > 0, b > 0 // post-condition -- the returned value is between a and b inclusive //************************************************************************ int rand(int a, int b); //************************************************************************** // Function to round a value to n decimal places // // post-condition -- returns the rounded value //************************************************************************** double round(double value, int n); //************************************************************************** // Function to return the distance between two points // // parameter usage : // x1, y1 -- import the first point // x2, y2 -- import the second point //************************************************************************** double distance(double x1, double y1, double x2, double y2); //************************************************************************** // Function to return true is n is prime // // a number is prime if it is not evenly divisible by // any number less than it. In this version we only check // divisors up to the square root of n. //************************************************************************** bool prime(int n); //************************************************************************** // Function to return true if the character is a vowel // // post-condition -- returns true if ch is a vowel and false otherwise //************************************************************************** bool isVowel(char ch); #endif