/* Course Number : CIS-112 Project # 2 ***************************************************************************/ #include // Preprocessor Directives #include #include #include #include void main() { void header_fcn () ; // Function Prototypes void report_fcn () ; header_fcn () ; report_fcn () ; } // end of main () //************************************************************************** void header_fcn () { cout << "\n\n PGCC REAL ESTATE BROKERS, INC."; cout << "\n\n HOME LOANS PLACED FOR THE MONTHS SEPTEMBER 2004 THROUGH FEBRUARY 2005"; cout << "\n\n SIX MONTH REPORT PREPARED BY: Jim Chaires\n"; cout << "\n\nCompany Name Sept Oct Nov Dec Jan Feb Company"; cout << "\n 2004 2004 2004 2004 2005 2005 Totals\n\n"; } // Build Arrays //***************************************************************************** void report_fcn() { int build_arrays_fcn (char[][16], int [][6]) ; void print_arrays_totals_fcn (char[][16], int [][6], int) ; // Variable List char name_array [20][16]; // 2 dim array - name of mortgage company int loan_array [20][6]; // 2 dim array - number of loans for 6 mnths int numitems; // Number of items in the array cout << setprecision (2) << setiosflags (ios::fixed) << setiosflags (ios::showpoint); numitems = build_arrays_fcn (name_array, loan_array) ; print_arrays_totals_fcn (name_array, loan_array, numitems) ; } // end of report function //***************************************************************************** int build_arrays_fcn(char name_tab [][16], int loan_tab [][6]) { ifstream mortgage_file ("c:mortgage.txt") ; if ( mortgage_file.fail() ) { cout << "\n There is a problem locating the input file\n\n"; cout << " Check that input file is on the correct drive\n"; cout << " and that the name of the file is spelled correctly"; exit(1); } // end of if char company_name[16]; // Names of data fields in input record int loans_sep ; int loans_oct ; int loans_nov ; int loans_dec ; int loans_jan ; int loans_feb ; int row = 0 ; mortgage_file >> company_name >> loans_sep >> loans_oct >> loans_nov >> loans_dec >> loans_jan >> loans_feb; while (!mortgage_file.eof () ) { strcpy(name_tab[row], company_name); loan_tab[row][0] = loans_sep ; loan_tab[row][1] = loans_oct ; loan_tab[row][2] = loans_nov ; loan_tab[row][3] = loans_dec ; loan_tab[row][4] = loans_jan ; loan_tab[row][5] = loans_feb ; row ++ ; mortgage_file >> company_name >> loans_sep >> loans_oct >> loans_nov >> loans_dec >> loans_jan >> loans_feb; } // end of while loop return row; } // end of fcn // Print Arrays //************************************************************************* void print_arrays_totals_fcn (char name_tab [][16], int loans_tab [][6], int numitems) { int row ; int col ; int tot_row = 0 ; int tot_col = 0 ; for (row = 0; row < numitems; row++) { tot_row = 0; cout << setiosflags(ios::left) << setw(19) << name_tab[row]; for (col=0; col<6; col++) { cout << setw(7)<< loans_tab[row][col]; tot_row += loans_tab[row][col]; } // end of for (columns) cout << setiosflags(ios::right) << setw(4) << tot_row << "\n"; } // end of for (rows) //******************************************************* cout << "\nMonthly Totals"; for (col=0; col<6; col++) { tot_col = 0; for (row = 0; row < numitems; row++) tot_col += loans_tab[row][col]; cout << setw(7) << tot_col; } // end of for (columns) } // end of fcn //****************************************************************************