/****** COURSE NUMBER: CIS-112 PROJECT # 5 ********/ #include #include #include #include #include #include ifstream indata ("c:strgdata.txt"); void main ( ) { // function prototypes void open_input_file (); void print_headers (); int is_it_a_vowel (char); int is_it_a_consonent (char); int is_it_a_space (char); int is_it_a_newline (char); int is_it_a_punct_mark (char); void print_totals (int totals[]); // declaration of data storage -- arrays + variables char data_in [30] [80] = {" "}; // Two dimensional array int numitems ; // Index used to build array int i = 0 ; // Index used to access array int j ; // Index used to access array int totals [5] = {0} ; // Initializes totals // main () program logic open_input_file (); print_headers (); while (!indata.eof () ) // Builds two dimensional array { indata.getline(data_in[i], 80, '\n'); i++; } // end of while numitems = i ; cout << "\n" << data_in[0]; // Prints first line of data for (i =0; i < numitems; i++) // Index allows last line to print if(strcmp(data_in[i], data_in[i+1]) != 0) { cout << "\n" << data_in [i+1]; totals [3] ++; for (j=0; j < 79; j++) { totals [0] += is_it_a_vowel (data_in[i][j]); totals [1] += is_it_a_consonent (data_in[i][j]); totals [2] += is_it_a_space (data_in[i][j]); totals [4] += is_it_a_punct_mark (data_in[i][j]); } // end of for } // end if if print_totals ( totals ); } // end of main //****************************************************************************** void open_input_file() { if (indata.fail () ) { cout << "Problem opening the input file"; exit (1); } } // **************************** Function - Print_headers ******************* void print_headers () { cout << "\n**********************************************************"; cout << "\n* *"; cout << "\n* Actual Text of the File entited -- STRGDATA.TXT *"; cout << "\n* (Without Duplicate Lines of Code) *"; cout << "\n* *"; cout << "\n**********************************************************\n\n"; } // end of print headers function // *************************************** Function - Check_Vowel ********** int is_it_a_vowel (char char_i) { switch ( char_i) { case 'A' : case 'a': case 'E' : case 'e': case 'I' : case 'i': case 'O' : case 'o': case 'U' : case 'u': return 1; default: return 0; } // end of switch } // end of check vowel function // ******************************** Function - Check_Consonent ************** int is_it_a_consonent (char char_i) { switch ( char_i) { case 'B' : case 'b': case 'C' : case 'c': case 'D' : case 'd': case 'F' : case 'f': case 'G' : case 'g': case 'H' : case 'h': case 'J' : case 'j': case 'K' : case 'k': case 'L' : case 'l': case 'M' : case 'm': case 'N' : case 'n': case 'P' : case 'p': case 'Q' : case 'q': case 'R' : case 'r': case 'S' : case 's': case 'T' : case 't': case 'V' : case 'v': case 'W' : case 'w': case 'X' : case 'x': case 'Y' : case 'y': case 'Z' : case 'z': return 1; default: return 0; } // end of switch } // end of function consonent //******************************************** Function - Check_Space ********** int is_it_a_space (char char_i) { if ( char_i == ' ') return 1 ; else return 0 ; } // end of space function //************************************** Function - Check_Newline ************** int is_it_a_newline (char char_i) { if ( char_i == '\n') return 1 ; else return 0 ; } // end of newline function //**************************** Function - Punctuation ************************ //******************* (Note: alternate method to ispunct() ) *************** int is_it_a_punct_mark (char char_i) { if ( (char_i >= 33) && (char_i <= 47) ) return 1; if ( (char_i >= 58) && (char_i <= 64) ) return 1; if ( (char_i >= 91) && (char_i <= 96) ) return 1; if ( (char_i >= 123) && (char_i <= 126) ) return 1; return 0; } // end of punctuation function //***************************** Function - Output_Totals ******************** void print_totals (int totals []) { cout << "\n\n********************************************************"; cout << "\n* *"; cout << "\n* Totals for the Text File -- STRGDATA.TXT *"; cout << "\n* Summary Report Prepared by: Jim Chaires *"; cout << "\n* Date: April 2002 *"; cout << "\n********************************************************"; cout << "\n"; cout << "\nThe total number of vowels is : " << totals[0]; cout << "\nThe total number of consonents is : " << totals[1]; cout << "\nThe total number of spaces is : " << totals[2]; cout << "\nThe total number of lines is : " << totals[3]; cout << "\nThe total number of punctuation marks is : " << totals[4]; } // end of print totals //******************************************************************************