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

analyze the following program #include <iostream> #include <iomanip> #include <f

ID: 3631013 • Letter: A

Question

analyze the following program

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Program name: MultiplicationTable
int main(void)
{
int I, J;
fstream MultFile;
MultFile.open("g:\multfile.txt", ios::out);
// begin outer for-loop (for rows)
{
// begin inner for-loop (for columns)
{
MultFile<<"Insert proper output here";
}
MultFile<<endl;
}
cin.get(); cin.get();
return 0;
} // MultiplicationTable

The following program is the skeleton of a program which is supposed to output to a file called MultFile the multiplication table for integers from 0 to 9. This program will require two FOR-loops, one nested inside the other. The control variables for these loops should be I and J, which have already been declared. You will be asked to complete this program in the next activity.

Then modify the program MultiplicationTable by completing the given partial program. The following is how MultiFile.text looks.
MultiFile:
0*0=0 0*1=0 0*2=0 0*3=0 0*4=0 0*5=0 0*6=0 0*7=0 0*8=0 0*9=0
1*0=0 1*1=1 1*2=0 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
*
*
*
9*0=0 9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=64 9*8=72 9*9=81

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Program name: MultiplicationTable
int main(void)
{
int I, J;
fstream MultFile;
MultFile.open("g:\multfile.txt", ios::out);
for(int i=0; i<=9;i++)
{
for(int j=0; j<=9;j++)
{
MultFile << i << "*" <<j << "=" << (i*j) << " ";

}
MultFile<<endl;
}
cin.get(); cin.get();
return 0;
} // MultiplicationTable