/* Thank you to the Author */ #include #include #include #include //Ru: add using namespace std; /* * Function gets file name from user and opens the file. * If the file does not open exit program. */ void getFileName(ifstream &file); /* * Checks each character in nexStr until digit is found. * If digit found loop breaks and 1 is returned, otherwise return 0. */ int containsNum(string nextStr, int startLoc); /* * Converts the first number encountered in str to a double starting at &start * using the atof() function. Also checks if a percent sign is in str. If so, * removes percent sign then converts to double and divides by 100. */ double convertDoub(string str, int &start); /* * Adds toAdd to num[] if the double toAdd is not already present in array. * Function checks each element to see if equal to toAdd. */ int addDoubToList(double toAdd, double num[], int &numElem); /* * Write numElemRef elements from numbers[] to file with name FILENAME */ void outputToFile(double numbers[], const string FILENAME, int &numElemRef); /* * Sort numbers[] in increasing order from start to end using the quicksort algorithm. * Quicksort moves elements in numbers[] around so numbers less than a specified "pivot" * number are on the left side of the array and numbers larger are on the right, then * recursively calls itself to sort those two halves of the array. */ void quickSort(double numbers[], int start, int end); /* * Returns value > 0 if one > two, return < 0 if one < two, return 0 if one = two */ double compare(double one, double two); /* * Removes all commas from string. Applicable Rules: 3) A comma between two numberical digits * must be removed so the digits are concateneated. ie A,143,243,2 would go to A 1431432 */ string removeCommas(string str); /* *Deal with Hyphens. Function checks each character in string. If hyphen found does following: *Check if part of chain of hyphens remove chain if found (ie ---5 becomes 5). Then check if *hyphen follows a letter or number - remove hyphen if true (ie ITT-453 becomes ITT 453). *Then check if following the hyphen is a number or period - if found *do nothing (ie -.45 and -45 left alone). Finally in all other cases remove hyphen. *Note removing hyphen refers to replacing hyphen with white space. */ string removeExtraHyph(string str); /* * Deals with periods in the strings. Starting at first period function reads each character in * string. If two periods found in a row, first period replaced with white space. If two periods * found separated only by numbers remove second period, and check if there is a number prior to the * first period or after the second, if so then rule 7 applies and remove all periods ie 555.556.557 * becomes 555 556 557. Otherwise, rule 8 applies and the first period is a decimal point ie .25. is .25 */ string removeExtraPer(string str); /* * Replace any percent sign that does not follow a number with white space. */ string removeExtraPercent(string str); /* * Replaces any character that is not a number, period, percent sign, or hyphen with white space. */ string removeIgnorables(string str); /* * Checks if char toCheck is a numerical digit. */ bool isNum(char toCheck); /* * Checks if char toCheck is a alphabetical letter. */ bool isLetter(char toCheck);