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

in C++, Write a program that creates a table for the user\'s choice of basic mat

ID: 3841223 • Letter: I

Question

in C++, Write a program that creates a table for the user's choice of basic math operations (+, -, *, /, and %). These operations will all be performed in an integer-only way. (Modulo doesn't work with decimals anyway... And you're going to have enough trouble lining up the table without dealing with decimal places on division!)

The user should also be allowed to choose the size of the table (it will, of course, be square: 4x4, 5x5, etc.). You may limit the maximum size of the table, for formatting purposes.Make sure your table is neat and lines up nicely (see the examples below). Columns should all be of equal width. This should be the minimum width necessary to hold the largestanswer for the table's operation. (Be careful! This may be a negative value!) Note that, if each column is as small as possible, you can fit more of them on the screen...

Try to use functions to break up the program into more manageable -- re-usable -- pieces. (You'll note that most of the table display is identical but for the corner symbol, the largest answer width, and the calculation of the entries themselves... Perhaps you could parameterize the data portions of this and ...er... 'farm-out' the calculation of the entries to a parameterized little helper function..?)

As an example, the program interaction might look something like (the parts in this color are typed by the user):

Explanation / Answer

// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
int row,column,size,k,h;
char ch;
do{
cout<<' '<<' '<<"Welcome To Math Table Program!!!"<<endl<<endl; //menu to choose
cout<<' '<<"Table Menu"<<endl<<endl;
cout<<"1)Addition table"<<endl;
cout<<"2)Multiplication table"<<endl;
cout<<"3)Subtraction table"<<endl;
cout<<"4)Division table"<<endl;
cout<<"5)Remainder table"<<endl;
cout<<"6)Quit"<<endl;
cout<<"Choice :"; //accepting user choice
cin>>ch;
cout<<endl;
do{
cout<<"What should be the size of the table ? "; //accepting the size of the table
cin>>size;
if(size>10)
cout<<"I'm sorry,"<<size<<" is too large table to print on the screen.."<<endl;
else if(size<0)
cout<<"I'm sorry,"<<size<<"would be stupid..."<<endl;
}while(size>10 || size<0);
cout<<endl;
cout<<"Thank you..calculating"<<endl<<endl;
h=size+size+size+size;
if(ch=='+' || ch=='a' || ch=='A' || ch=='1') //calculating the addition chart
{
cout<<"+ |";
for(k=1;k<=size;k++)
{
cout<<' '<<k<<' ';
}
cout<<endl;
  
for(k=1;k<h;k++)
{
cout<<"-----";
}
cout<<endl;
for( int row = 0; row < size; ++row )
{
cout<<row+1<<"|";
for( int column = 0; column < size; ++column )
{
cout <<' '<< ( column + 1 ) + ( row + 1 ) << ' ';
}   
cout << endl;
}
}
else if(ch=='*' || ch=='m' || ch=='M' || ch=='2') //calculating the multiplication chart
{
cout<<"+ |";
for(k=1;k<=size;k++)
{
cout<<' '<<k<<' ';
}
cout<<endl;
  
for(k=1;k<h;k++)
{
cout<<"-----";
}
cout<<endl;
for( int row = 0; row < size; ++row )
{
cout<<row+1<<"|";
for( int column = 0; column < size; ++column )
{
cout <<' '<< ( column + 1 ) * ( row + 1 ) << ' ';
}   
cout << endl;
}
}
else if(ch=='-' || ch=='s' || ch=='S' || ch=='3') //calculating the subtraction chart
{
cout<<"+ |";
for(k=1;k<=size;k++)
{
cout<<' '<<k<<' ';
}
cout<<endl;
  
for(k=1;k<h;k++)
{
cout<<"-----";
}
cout<<endl;
for( int row = 0; row < size; ++row )
{
cout<<row+1<<"|";
for( int column = 0; column < size; ++column )
{
cout <<' '<< ( column + 1 ) - ( row + 1 ) << ' ';
}   
cout << endl;
}
}
else if(ch=='/' || ch=='d' || ch=='D' || ch=='4') //calculating the division chart
{
cout<<"+ |";
for(k=1;k<=size;k++)
{
cout<<' '<<k<<' ';
}
cout<<endl;
  
for(k=1;k<h;k++)
{
cout<<"-----";
}
cout<<endl;
for( int row = 0; row < size; ++row )
{
cout<<row+1<<"|";
for( int column = 0; column < size; ++column )
{
cout <<' '<< ( column + 1 ) / ( row + 1 ) << ' ';
}   
cout << endl;
}
}
else if(ch=='%' || ch=='R' || ch=='r' || ch=='5') //calculating the Remainder chart
{
cout<<"+ |";
for(k=1;k<=size;k++)
{
cout<<' '<<k<<' ';
}
cout<<endl;
  
for(k=1;k<h;k++)
{
cout<<"-----";
}
cout<<endl;
for( int row = 0; row < size; ++row )
{
cout<<row+1<<"|";
for( int column = 0; column < size; ++column )
{
cout <<' '<< ( column + 1 ) % ( row + 1 ) << ' ';
}   
cout << endl;
}
}
else //quit the table
{
cout<<"Thank you for using the MTP!!"<<endl<<endl;
cout<<"Endeavor to have a auspicious day!";
exit(0);
}
}while(ch!='6' || ch!='q' || ch!='Q');
}