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

C++ only . For this lab, you will writ a program that givs th usr th two options

ID: 3606772 • Letter: C

Question

C++ only . For this lab, you will writ a program that givs th usr th two options of quitting (Q) or prforming matrix oprations (P). If thy slct Q, th program should quit. Until th usr slcts Q, th program will rad in two matrics and a constant and print all of th following that ar possibl th sum, th diffrnc, th product of th constant and th first matrix, th product of th two matrics, and th boolan product of th two matrics. Any that ar not possibl should hav a statmnt printd saying why thy wr not printd.

In ordr to do ths oprations, th program must ask for th dimnsions of th first matrix, th first matrix, th dimnsions of th scond matrix, th scond matrix, and th constant. You may assum that nothing can b largr than 10X10. You may NOT assum that th matrics ar squar.

Sampl run data is as follows (printout from th program is shown hr in bold fac so you can dlinat it from th usr input which is shown in rgular font):

Do you want to prform matrix oprations(P) or quit(Q): P

Plas input th dimnsions of th first matrix: 3 3

Plas input th matrix:

1 0 1

1 1 1

0 0 1

Plas input th dimnsions of th scond matrix: 3 3

Plas input th scond matrix:

1 1 1

0 0 0

0 1 0

Plas input th constant:

2

Th sum of th two matrics is:

2 1 2

1 1 1

0 1 1

Th diffrnc of th two matrics is:

0 -1 0

1 1 1

0 -1 1

Th product of th constant and th first matrix is:

2 0 2

2 2 2

0 0 2

Th product of th two matrics is:

1 2 1

1 2 1

0 1 0

Th boolan product of th two matrics is:

1 1 1

1 1 1

0 1 0

Do you want to prform matrix oprations(P) or quit(Q): P

Plas input th dimnsions of th first matrix: 3 2

Plas input th matrix:

3 2

0 1

2 2

Plas input th dimnsions of th scond matrix: 2 2

Plas input th scond matrix:

1 0

1 1

Plas input th constant:

4

Th sum of th two matrics is:

Th matrics cannot b addd bcaus th dimnsions ar incompatibl.

Th diffrnc of th two matrics is:

Th matrics cannot b subtractd bcaus th dimnsions ar incompatibl.

Th product of th constant and th first matrix is:

12 8

0 4

8 8

Th product of th two matrics is:

5 2

1 1

4 2

Th boolan product of th two matrics is:

Th boolan product dos not xist bcaus th matrics ar not boolan.

Do you want to prform matrix oprations(P) or quit(Q): P

Plas input th dimnsions of th first matrix: 3 4

Plas input th matrix:

0 1 0 1

1 1 1 1

0 1 1 0

Plas input th dimnsions of th scond matrix: 3 4

Plas input th scond matrix:

1 1 1 1

1 1 1 1

1 0 0 1

Plas input th constant:

6

Th sum of th two matrics is:

1 2 1 2

2 2 2 2

1 1 1 1

Th diffrnc of th two matrics is:

-1 0 -1 0

0 0 0 0

-1 1 1 -1

Th product of th constant and th first matrix is:

0 6 0 6

6 6 6 6

0 6 6 0

Th product of th two matrics is:

Th two matrics cannot b multiplid bcaus th dimnsions ar incompatibl.

Th boolan product of th two matrics is:

Th boolan product dos not xist bcaus th dimnsions ar incompatibl.

Do you want to prform matrix oprations(P) or quit(Q): Q

Hav a nic day.

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

int m,n,x,y,i,j,k,constant;

char option;

int a[10][10],b[10][10],sum[10][10],diff[10][10],prod[10][10],prodConst[10][10],boolProd[10][10];

do

{

cout<<" Do you want to prform matrix oprations(P) or quit(Q): ";

cin>>option;

if(option == 'Q')

break;

else

{

cout<<" Plas input th dimnsions of th first matrix: ";

cin>>m>>n;

cout<<" Plas input th matrix:";

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

cin>>a[i][j];

}

}

cout<<" Plas input th dimnsions of th second matrix: ";

cin>>x>>y;

cout<<" Plas input th matrix:";

for(i=0;i<x;i++)

{

for(j=0;j<y;j++)

{

cin>>b[i][j];

}

}

cout<<" Plas input th constant: ";

cin>>constant;

if(m != x || n != y)
{

cout<<" The matrices cannot be added because the dimensions are incompatible";
cout<<" The matrices cannot be subtracted because the dimensions are incompatible";
}
else
{

cout<<" Th sum of th two matrics is: ";

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

sum[i][j] = a[i][j] + b[i][j];

}

}

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

cout<<sum[i][j]<<" ";

}

cout<<endl;

}

cout<<" Th diffrnc of th two matrics is: ";

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

diff[i][j] = a[i][j] - b[i][j];

cout<<diff[i][j]<<" ";

}

cout<<endl;

}
}

cout<<" Th product of th constant and th first matrix is: ";

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

prodConst[i][j] = constant*a[i][j];

cout<<prodConst[i][j]<<" ";

}

cout<<endl;

}

if(n != x)
{
cout<<" The two matrices cannot be multiplied because the dimensions are incompatible";
cout<<" The boolean product does not exist because the dimensions are incompatible";
}
else
{

for(i = 0; i < m; ++i)

for(j = 0; j < y; ++j)

{

prod[i][j]=0;

}

cout<<" Th product of th two matrics is: ";

for(i = 0; i < m; ++i)

{

for(j = 0; j < y; ++j)

{

for(k = 0; k < n; ++k)

{

prod[i][j] += a[i][k] * b[k][j];

  

}

cout<<prod[i][j]<<" ";

}

cout<<endl;

}

cout<<" Th boolan product of th two matrics is: ";

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

if(prod[i][j] >= 1)

boolProd[i][j] = 1;

else

boolProd[i][j] = 0;

cout<<boolProd[i][j]<<" ";

}

cout<<endl;

}

}
}

}while(option != 'Q');

return 0;

}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote