Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**array must have header for each dimension when outputted** **Can not use \"pri

ID: 3821197 • Letter: #

Question

**array must have header for each dimension when outputted**

**Can not use "printf"**

**Must use string**

**Must ask user if program should be run again**

**must clear screen if run again**

Write a C++ program that will use a two-dimensional array to create and store the multiplication tables for the integers 1-10. The table shall be created in a function name “multiply_me” and outputted in the main function. You must use global variables to transfer information to and/or from the table. Your output shall be neatly displayed on the console.

Explanation / Answer

#include <iostream>
#include<conio.h>
#include<cstdlib>
#include<iomanip>
#include <ctime>
using namespace std;

void displayTable(int table[10][3]);
bool testMe(int testTable[10][3]);
void gradeMe(int testTable[10][3], int ansTable[10][3]);
void displayMenu();

int main()
{
srand(time(NULL));
int userInput = 0;
int tableChoice = 0;
int myTable[10][3] = {0};
int testTable[10][3];
int ansTable[10][3];

bool tested = false;

do
{
displayMenu();
cin >> userInput;
cout << endl;

switch (userInput)
{
case :
displayTable(myTable);
break;
case 2:
cout << "What times table test would you like to take? > ";
cin >> tableChoice;
createTables(testTable, ansTable, tableChoice);
tested = testMe(testTable);   
if (tested)
{
gradeMe(testTable, ansTable);
}
break;
case 3:
displayTable(myTable);
break;
case 4:
cout << "Program ending. ";
return 0;
default:
cout << "You entered an invalid item number. Please enter a number from 1 to 4. ";
cout << endl;
}

} while (userInput != 4);

return 0;
}

void displayTable(int myTable[10][3])
{
int num; //initialize local variables

//Ask the user what times table they would like to review
cout << "What times table would you like to review?" << endl;;
cout << "Please enter a value from 1 to 12 > ";
cout << " ";
cin >> num;
cout << endl;

for (int k = 0; k < 10; k++)
{
myTable[k][0] = k + 1;
myTable[k][1] = num;
myTable[k][2] = myTable[k][0] * myTable[k][1];
}
for (int k = 0; k < 10; k++)
{
cout << setw(3)<< myTable[k][0] << " * " << myTable[k][1] << " = " << myTable[k][2] << endl;
}
cout << endl;
}

void createTables(int testTable[10][3], int ansTable[10][3], int usersChoice)
{
for (int k = 0; k < 10; k++)
{
testTable[k][0] = k + 1;
testTable[k][1] = usersChoice;
testTable[k][2] = 0;

ansTable[k][0] = k+ 1;
ansTable[k][1] = usersChoice;
ansTable[k][2] = usersChoice * (k + 1);
}
}

bool testMe(int testTable[10][3])
{
bool tested[10] = { false, false, false, false, false,false, false, false, false, false };

while (!AllAnswersAreTested(tested))
{
int index = rand() % 10;
if (tested[index] == false)
{
int randomNum = testTable[index][0];
int tableChoice = testTable[index][1];
int answer;
cout << "What is " << randomNum << " X " << tableChoice << " = ";
cin >> answer;
testTable[index][2] = answer;
tested[index] = true;
}
}
return true;
}

bool AllAnswersAreTested(bool tested[10])
{
for (int k = 0; k < 10; k++)
{
if (tested[i] == false)
{
return false;
}
}
return true;
}

void gradeMe(int testTable[10][3], int ansTable[10][3])
{
int correctAnswers = 0;
for (int k = 0; k<10; k++)
{
if (testTable[i][2] == ansTable[i][2])
{
correctAnswers++;
}
}
int score = (correctAnswers * 10);

if (score == 100)
{
cout << "You passed the test! PERFECT SCORE!!" << endl;
cout << endl;
}
else if (score >= 70)
{
cout << "You passed the test. Your Score is: ";
cout << score;
cout << endl;
}
else if (score < 70)
{
cout << "You did not pass the test. Your Score is: ";
cout << score;
cout << endl;
}
}

void displayMenu()
{

cout << " Multiplication Tables" << endl;
cout << endl;
cout << " 1. Review MyTable" << endl;
cout << " 2. Test Me" << endl;
cout << " 3. Enter a New Multiplication Table (1-12)";
cout << " 4. Quit" << endl;
cout << " Enter a Menu Item > ";
}