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

Description: You must write a program which creates a two dimensional integer ar

ID: 651764 • Letter: D

Question

Description:

You must write a program which creates a two dimensional integer array to represent a table with five rows and five columns.

Use loops to prompt the user to enter values for the first row and column.

Fill in the rest of the table with values calculated by summing the values in the table cell above and the table cell to the left of each cell. For example, suppose the user entered the following first row and column:

2

13

17

19

23

3

5

7

11

Then the completed table would have the following values:

2

13

17

19

23

3

16

33

52

75

5

21

54

106

181

7

28

82

188

369

11

39

121

309

678

Finally, you will print the table. Each row must be on a new line, and a space must be used between each table entry.

For the example above, the printed output should look like:

Implementation Details:

On the first line of your program file (.cpp file), place a comment with your name, EUID, and lab section number.

Inside the main function, you must:

2

13

17

19

23

3

5

7

11

Explanation / Answer

#include<iostream.h>
#include<conio.h>

class a1
{
public:
   int a[5][5],i,j,c;

   void fill1()
   {
       clrscr();

       for(i=0;i<5;i++)
       {

           cout<<" Enter no. for a[0]["<<i<<"]";
           cin>>a[0][i];
       }
   }

   void fill2()
   {
       for(i=1;i<5;i++)
       {
           for(j=0;j<5;j++)
           {
               a[i][j] = a[i][j-1] + a[i-1][j];
           }
       }
   }

   void disp()
   {
       for(i=0;i<5;i++)
       {
           for(j=0;j<5;j++)
           {
               cout<<a[i][j]<<" ";
           }
           cout<<" ";
       }
       getch();
   }
};

void main()
{
   a1 o;
   o.fill1();
   o.fill2();
   o.disp();
}