Please help code in C++ In this assignment you need to write and execute a progr
ID: 3743556 • Letter: P
Question
Please help code in C++
In this assignment you need to write and execute a program that will perform addition, subtraction and multiplication of two valid matrices. The matrices will be stored as double linked lists. Each item in the matrix will contain pointers to its neighboring values. Meaning the corners will have two pointers and the middle items will have four pointers. The entire matrix will only be accessible with a start pointer that points to the top right position as shown below: start To perform the addition and subtraction you must use a recursive function. You are not allowed to use a loop. You can however, use a loop for the matrix multiplication. works before moving on to doing your matrix class Input will be given in the form of two matrices where the first two values of the input file will be the dimensions of the first matrix. Then the items of the first matrix, then the next two values will be the dimensions of the second matrix and then the items of the matrix. You must check if the matrix dimensions are valid for each operation and only perform those operations which the dimensions are valid for.Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int i,j,r,c,choice;
int matrix1[5][5];
int matrix2[5][5];
int sum[5][5],sub[5][5];
cout<<"Square Matrix Addition & Subtraction ";
cout<<"Enter Row & Column = ";cin>>r>>c;
cout<<"Enter matrix 1st ";
for (i=0;i<r;i++)
{for (j=0;j<c;j++)
{cin>>matrix1[i][j];
}
}
cout<<"Entered Matrix is ";
for (i=0;i<r;i++)
{for (j=0;j<c;j++)
{cout<<matrix1[i][j]<<" ";
}cout<<" ";
}
cout<<" Enter matrix 2nd ";
for (i=0;i<r;i++)
{ for (j=0;j<c;j++)
{cin>>matrix2[i][j];
}
}
cout<<"Entered matrix is ";
for (i=0;i<r;i++)
{ for (j=0;j<c;j++)
{cout<<matrix2[i][j]<<" ";
}cout<<" ";
}
cout<<" Enter Choice: 1 = Addition 2 = Subtraction ";
cin>>choice;
if(choice==1)
{ cout<<"Addition of matrix ";
for (i=0;i<r;i++)
{ for (j=0;j<c;j++)
{ sum[i][j]=matrix1[i][j]+matrix2[i][j];
cout<<sum[i][j]<<" ";
}cout<<" ";
}
}
if(choice==2)
{ cout<<"Subtraction of matrix ";
for (i=0;i<r;i++)
{ for (j=0;j<c;j++)
{ sub[i][j]=matrix1[i][j]-matrix2[i][j];
cout<<sub[i][j]<<" ";
}cout<<" ";
}
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.