/* multiplication table for the integers 1 to 10 */ #include #include using namespace std; void printheadings(ofstream &); //function prototypes void printrow(ofstream &, int); int main() { // declare and open the output file //ofstream outfile("c:\\bc\\CISC1110\\pgms\\chapter5\\myoutput.txt"); //comment-out for debugging ofstream outfile("con"); //un-comment for debugging printheadings(outfile); for (int m1 = 1; m1 <= 10; m1++) printrow(outfile, m1); //m1 = multiplicand outfile.close(); //close the output file // system("pause"); //un-comment when using DevC++ return 0; } /* Function printheadings() * Input: * out1 - a reference to the output file * Process: * prints headings for a multiplication chart * Output: * prints the table headings */ void printheadings(ofstream &out1) { out1 << "\tThis is a Multiplication Table from 1 to 10" << endl << endl; out1.width(5); out1 << "X"; /* loop to print the heading of multipliers */ for (int m2 = 1; m2 <= 10; m2++) { out1.width(5); out1 << m2; } out1 << endl; return; } /* Function printrow() * Input: * out2 - a reference to the output file * m1 - the current multiplicand * Process: * prints a row of a multiplication table by calculating the * first 10 multiples of the multiplicand. * Output: * prints a row of the table */ void printrow(ofstream &out2, int m1) { out2.width(5); out2 << m1; //prints the multiplicand for (int m2 = 1; m2 <= 10; m2++) //m2=multiplier { out2.width(5); out2 << m1 * m2; //prints the product } out2 << endl; return; }