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

I have trouble to solve these questions so please someone help me out. I\'ll tha

ID: 3591564 • Letter: I

Question

I have trouble to solve these questions so please someone help me out. I'll thank you so much for your help.

Below is the information.

========================================

4. Take the following code and paste it into Eclipse then fill it out as per the directions below:

#include <iostream>

using namespace std;

const int SIZE = 3;

int main()

{

int array[SIZE][SIZE] = {12, 14, 17, 19, 22, 24, 27, 29, 42};

}

Write a program that goes through the array and prints out each element using a double for loop. Use an endl at the appropriate location to print out the array in three lines of three items each with a space between each item.

==============================================================

5. Take the code that you used to complete Question # 4 and paste it into Eclipse then do the following:

This time, modify the program so that instead of printing it to the screen it will output it to a text file using fstream. When done, copy and paste the code from Eclipse into the area below. Don’t worry about submitting the text file that is created, just the code.

Explanation / Answer

a)

#include <iostream>
using namespace std;

const int SIZE = 3;

int main()
{
int array[SIZE][SIZE] = {12, 14, 17, 19, 22, 24, 27, 29, 42};

for(int i=0;i<SIZE;i++) //looping from 0 to SIZE
{
for(int j=0;j<SIZE;j++) //looping from 0 to SIZE-1
{
cout<<array[i][j]<<" "; //printing the elements of a particular row,separated by a space
}

cout<<endl; //printing newline after each row
}

return 0;
}

b)

#include <iostream>
#include<fstream>
using namespace std;

const int SIZE = 3;

int main()
{
int array[SIZE][SIZE] = {12, 14, 17, 19, 22, 24, 27, 29, 42};

ofstream myfile;

myfile.open("OutputFile"); //opening a file named OutputFile to which output is written

for(int i=0;i<SIZE;i++) //looping from 0 to SIZE
{
for(int j=0;j<SIZE;j++) //looping from 0 to SIZE-1
{
myfile<<array[i][j]<<" "; //printing the elements of a particular row,separated by a space
}

myfile<<endl; //printing newline after each row
}

return 0;
}