#include // outputs multiplication table mod modulus // 1711A class, 1997 October 10 int getmodulus(); // prompts then reads modulus void makeheader(int modulus); //outputs heading for table void makelabelrow(int modulus); //outputs top row of mult table for modulus void makerow(int row, int modulus); //outputs row labeled row of mult table for modulus int modmult(int row,int column, int modulus); // returns (row*column) % modulus int main() { int modulus, row; modulus = getmodulus(); // cout << modulus; makeheader(modulus); makelabelrow(modulus); row = 0; do { makerow(row, modulus); row = row + 1; } while (row < modulus); return 0; } int getmodulus() { int modulus, err_count; cout << "\n\nEnter a positive integer\n"; cin >> modulus; err_count = 0; while ((modulus <= 0)&&(err_count < 3)) {err_count++; cout << "\nWarning: the entry was not a positive integer ( > 0)\n"; cout << "Try again\n"; cin >> modulus; } if (modulus > 0) return modulus; //normal return else {cout << "Your input was incorrect, if you had entered 4\n"; cout << "the output would be: \n\n\n"; return 4;} //error trapped return } void makeheader(int modulus) { cout << "\n\n Modular multiplication for " << modulus << endl << endl; return; } void makelabelrow(int modulus) { int column; cout << " *"; column = 0; while (column < modulus) { cout.width(5); cout << column; column = column + 1; }; // end while cout << endl; return; } // end makelabelrow void makerow(int row, int modulus) { int column; cout.width(5); cout << row; column = 0; while (column < modulus) { cout.width(5); cout << modmult(row,column,modulus); column = column +1; } cout << endl; return ; } // end makerow int modmult(int row,int column, int modulus) { return (row*column) % modulus;}