/* Solution to R3 C/C++ Competition Northwestern State University */ #include "stdafx.h" #include #include #include //#include ifstream inData("arfile0.txt", ios::in); ofstream outFile("report2.txt", ios::out); const int recLength = 70, MAX = 10000, MAXLINE = 57; //lines per page of printout int pageNo = 1, //current page number lineCt = 0; //current count of lines processed this page char t1, m1, m2, d1, d2, y1, y2; //global 30 day run date long Tpay=0, Tcredit=0, Tdebit=0, Tchg=0; //global totals // File access error checking. // Exits the program if there is a file error. void error_ck() { if(!inData) { cerr << "File could not be opened.\n"; exit(1); } if(!outFile) { cerr << "File could not be opened.\n"; exit(1); } } void newPage() { //uses lineCt to count lines this page, pageNo for the page number //called every time there is an output line lineCt++; if(lineCt >= MAXLINE) { pageNo++; outFile << "\f\nPage " << pageNo << " Source Transactions for the Accounting Totals \n\n"; lineCt = 0; } } // Returns the integer value of one character from the array. int one_digit(char digit) { int num = 0; if(digit=='1') num = 1; if(digit=='2') num = 2; if(digit=='3') num = 3; if(digit=='4') num = 4; if(digit=='5') num = 5; if(digit=='6') num = 6; if(digit=='7') num = 7; if(digit=='8') num = 8; if(digit=='9') num = 9; return(num); } // Converts the character age to its numerical value long char_to_int(char recs[MAX][recLength], int record, int begin, int end) { long i, digit = 0, num = 0; for(i = begin; i <= end; i++) // steps through each character { digit = one_digit(recs[record][i]); num = (num * 10) + digit; } return(num); } // Initializes the array to spaces. void init(char recs[MAX][recLength]) { int i, j; for(j = 0; j < MAX; j++) { for(i = 0; i < recLength; i++) recs[j][i] = ' '; } } // Reads the data file into one large character array // omits the .'s in the data file //adds a space after the account number - array position 6 int read_file(char recs[MAX][recLength]) { int i=0, j=0, addOne, count = 1; char ch; ifstream inDate("date.c", ios::in); m1 = inDate.get(); m2 = inDate.get(); d1 = inDate.get(); d2 = inDate.get(); y1 = inDate.get(); y2 = inDate.get(); inDate.close(); while((ch = inData.get()) != EOF) { if(ch != '\n') { if( (j= begin; i--) // steps through array positions { for(k = 0; k < count-1; k++) // passes { for(j = 0; j < count-1; j++) // one pass { if(recs[j][i] > recs[j+1][i]) // compares character { swap(recs, j); // Sends to swap function if necessary } } } } } // Mark duplicate records. void mark_dups(char recs[MAX][recLength], int count, int begin, int end) { int i, j, dup; for(j = 0; j < count; j++) // steps through array rows { dup = 1; //assume is a dup and prove it is not for(i = begin; i <= end; i++) // check the key { // if( ( i< 8 )||( i> 15 ) ) //skip over the date created if(recs[j][i] != recs[j+1][i]) // compares character dup = 0; } if(dup==1) recs[j+1][0] = '-'; } } void printAmt(long bucks) { long thou, hundreds, dollars, cents; dollars = bucks/100; thou = dollars / 1000; hundreds = dollars % 1000; cents = bucks % 100; if(thou >= 100) outFile << thou << ","; else if(thou >=10) outFile << " " < 0) outFile << " " << thou << "," ; else outFile << " "; if(hundreds >= 100) outFile << hundreds; else if( (hundreds >= 10) ) outFile << "0" < 0) ) outFile << "000"; else outFile << " "; outFile << "."; if( (cents > 9) ) outFile << cents; else if( (cents < 10) && (cents > 0) ) outFile << "0" << cents; else outFile << "00"; } int subTotal(char ag1, char ag2, char type, char coverage, char recs[MAX][recLength], int count, int begin, int end) { //ag1 and ag2 designate the agency, type is payment, credit, or debit, coverage is Medicare (etc) int i, entries = 0, //number posting entries per posting date age; long total = 0, //total for this agency postTotal = 0; //total for this posting date double avg; char holdDate[6]; for(i = 0; i < 6; i++) holdDate[i] = '0'; //initialize the posting date for the control break for(i = 0; i < count; i++) { if( (recs[i][0]==ag1) && (recs[i][1]==ag2) && (recs[i][7]==type) && (recs[i][8]==coverage) ) { if( (holdDate[0] == recs[i][9]) && (holdDate[1] == recs[i][10]) && (holdDate[2] == recs[i][11]) && (holdDate[3] == recs[i][12]) ) { //same posting date postTotal += char_to_int(recs, i, begin, end); entries++; } else //change of date { //print the total, zero the postTotal, store the new date, add this total to the postTotal if(entries > 0) { outFile << " Posting Date " << holdDate[0]< 0) //do the last date { outFile << " Posting Date " << holdDate[0]<