Question
Please code in C++.
3. Submit a header file (project3.h), a definition file (project3.cpp), a main file (main.cpp), and a makefile to compile the
Resize resize 3980 87 8 1 39800 98 8 0 878 0 0 0 0 0 0 0 You must use of pointers to your matrix and the use of operations li
After taking the choice value, one should have a switch block to choose which function (for the matrix operation) needs to be
matrix2 # of rows: 2 matrix2 # of columns: 2 Enter element (0,0): 2 Enter element(0,1): 3 Enter element (1,0): 3 Enter elemen
Enter your choice: 3 matrix1 # of rows: 2 matrix1 # of columns: 1 Enter element (0,0): 2 Enter element (1,0): 1 matrix2 # of
Choice 2: subtraction Choice 3: multiplication Choice 4: determinant Choice 5: transpose Choice 6: inverse Choice 7: resize/r
Menu Choice 1: addition Choice 2: subtraction Choice 3: multiplication Choice 4: determinant Choice 5: transpose Choice 6: in
12 3 4 Another note should pop up to ask the user if he/she wants to do resizing or reshaping. For ex.: Do you want to resize


link to continue the code is this below or you can make your own code if you wish(fix any mistakes if you think there are any in it):

cpp.sh/3qcekv
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<stdlib.h>
#include<string.h>
#define s 20
using std::cout;
using std::cin;
using std::endl;

class matrix
{
public:
int a[s][s],x,y;
  void get();
void put();
void inverse();
void determinant();
void resize(int row, int column) ;
matrix operator+(matrix);
matrix operator-(matrix);
matrix operator*(matrix);
matrix transpose();
};

#include "matrix.h"
#include <iostream>
#include <cassert>

void matrix::get()
{
cout<<"Enter the order of Matrix "<<" :\n";
cin>>x>>y;
cout<<"Enter the Matrix "<<" :\n";
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
cin>>a[i][j];

}
void matrix::put()
{
cout<<"The Ans is:\n";
for(int i=0;i<x;i++)
{
cout<<"\n\t";
for(int j=0;j<y;j++)
cout<<a[i][j]<<" ";
}
}
matrix matrix::operator+(matrix b)
{
matrix r;
if((x!=b.x)||(y!=b.y))
{
cout<<"\n\tMatrix Addition is not possible the result is incorrect\n\n";
r.x=0;
r.y=0;
}
else
{
r.x=x;
r.y=y;
}
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
r.a[i][j]=a[i][j]+b.a[i][j];
return r;
}
matrix matrix::operator-(matrix b)
{
matrix r;
if((x!=b.x)||(y!=b.y))
{
cout<<"\n\tMatrix subtraction is not possible the result is incorrect\n\n";
r.x=0;
r.y=0;
}
else
{
r.x=x;
r.y=y;
}
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
r.a[i][j]=a[i][j]-b.a[i][j];


return r;
}
matrix matrix::operator*(matrix b)
{
matrix r;
int i,j;
if((x!=b.y)||(y!=b.x))
{
cout<<"\n\tMatrix Multiplication is not possible the result is incorrect\n\n";
r.x=0;
r.y=0;
}
else
{
r.x=x;
r.y=b.y;
}
for(int i=0;i<s;i++)
for(int j=0;j<s;j++)
r.a[i][j]=0;
for(i=0;i<x;i++)
for(j=0;j<b.y;j++)
for(int k=0;(k<y)||(k<b.x);k++)
r.a[i][j]+=a[i][k]*b.a[k][j];

return r;
}
matrix matrix::transpose()
{
matrix r;
int i,j;
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
r.a[i][j]=a[j][i];
r.x=x;
r.y=y;
return r;
}
/*matrix determinant */
void matrix::determinant()
{
  
int i, j;
   float determinant = 0;
  
   //finding determinant
   for(i = 0; i < 3; i++)
       determinant = determinant + (a[0][i] * (a[1][(i+1)%3] * a[2][(i+2)%3] - a[1][(i+2)%3] * a[2][(i+1)%3]));
  
   cout<<("\n\ndeterminant: %f\n", determinant);
   //finding inverse
   printf("\nInverse of matrix is: \n");
   for(i = 0; i < 3; i++){
       for(j = 0; j < 3; j++)
   cout<<("%.2f\t",((a[(j+1)%3][(i+1)%3] * a[(j+2)%3][(i+2)%3]) - (a[(j+1)%3][(i+2)%3] * a[(j+2)%3][(i+1)%3]))/determinant);
      
       cout<<("\n");
   }
   }
  

#include<iostream>
#include<stdlib.h>
#include<string.h>
#include "matrix.h"
#define s 20
using std::cout;
using std::cin;
using std::endl;


//..........................Main function..................................

int main()
{

char op;
matrix a,b,c;
int t=1;
while(t)
{
cout<<"\tSelect Option\n\n1.Matrix Addition\n2.Matrix Subtration\n3.Matrix Multiplication\n4.Matrix Transponse\nmatrix determinangt and inverse\n6.Exit\n";
cin>>op;
switch(op)
{
case '1':
cout<<"\n\tMatrix Addiation\n";
a.get();
b.get();
c=a+b;
c.put();
break;
case'2':
cout<<"\n\tMatrix Subtration\n";
a.get();
b.get();
c=a-b;
c.put();
break;
case'3':
cout<<"\n\tMatrix Multpication\n";
a.get();
b.get();
c=a*b;
c.put();
break;
case'4':
cout<<"\n\tMatrix Transpose\n";
a.get();
c=a.transpose();
c.put();
break;
case '5':
cout<<"matrix determinant and inverse\n";
a.get();
a.determinant();
a.put();
break;
case'6':
cout<<"\n\tPress any key to exit\n";
t=0;
break;
default:
cout<<"\n\tEnter a valid option\n";
}
  
}
    return 0;
}

first file main.cpp

#include<iostream>
#include<stdlib.h>
#include<string.h>
#include "project3.h"
#define s 20
using std::cout;
using std::cin;
using std::endl;


//..........................Main function..................................

int main()
{

char op;
matrix a,b,c;
int t=1;
while(t)
{
cout<<"\tSelect Option\n\n1.Matrix Addition\n2.Matrix Subtration\n3.Matrix Multiplication\n4.Matrix Transponse\nmatrix determinangt and inverse\n6.Exit\n";
cin>>op;
switch(op)
{
case '1':
cout<<"\n\tMatrix Addiation\n";
a.get();
b.get();
c=a+b;
c.put();
break;
case'2':
cout<<"\n\tMatrix Subtration\n";
a.get();
b.get();
c=a-b;
c.put();
break;
case'3':
cout<<"\n\tMatrix Multpication\n";
a.get();
b.get();
c=a*b;
c.put();
break;
case'4':
cout<<"\n\tMatrix Transpose\n";
a.get();
c=a.transpose();
c.put();
break;
case '5':
cout<<"matrix determinant and inverse\n";
a.get();
a.determinant();
a.put();
break;
case'6':
cout<<"\n\tPress any key to exit\n";
t=0;
break;
default:
cout<<"\n\tEnter a valid option\n";
}
  
}
  
  
return 0;
}

next project3.cpp

#include "project3.h"
#include <iostream>
#include <cassert>

void matrix::get()
{
cout<<"Enter the order of Matrix "<<" :\n";
cin>>x>>y;
cout<<"Enter the Matrix "<<" :\n";
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
cin>>a[i][j];

}
void matrix::put()
{
cout<<"The Ans is:\n";
for(int i=0;i<x;i++)
{
cout<<"\n\t";
for(int j=0;j<y;j++)
cout<<a[i][j]<<" ";
}
}
matrix matrix::operator+(matrix b)
{
matrix r;
if((x!=b.x)||(y!=b.y))
{
cout<<"\n\tMatrix Addition is not possible the result is incorrect\n\n";
r.x=0;
r.y=0;
}
else
{
r.x=x;
r.y=y;
}
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
r.a[i][j]=a[i][j]+b.a[i][j];
return r;
}
matrix matrix::operator-(matrix b)
{
matrix r;
if((x!=b.x)||(y!=b.y))
{
cout<<"\n\tMatrix subtraction is not possible the result is incorrect\n\n";
r.x=0;
r.y=0;
}
else
{
r.x=x;
r.y=y;
}
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
r.a[i][j]=a[i][j]-b.a[i][j];


return r;
}
matrix matrix::operator*(matrix b)
{
matrix r;
int i,j;
if((x!=b.y)||(y!=b.x))
{
cout<<"\n\tMatrix Multiplication is not possible the result is incorrect\n\n";
r.x=0;
r.y=0;
}
else
{
r.x=x;
r.y=b.y;
}
for(int i=0;i<s;i++)
for(int j=0;j<s;j++)
r.a[i][j]=0;
for(i=0;i<x;i++)
for(j=0;j<b.y;j++)
for(int k=0;(k<y)||(k<b.x);k++)
r.a[i][j]+=a[i][k]*b.a[k][j];

return r;
}
matrix matrix::transpose()
{
matrix r;
int i,j;
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
r.a[i][j]=a[j][i];
r.x=x;
r.y=y;
return r;
}
/*matrix determinant */
void matrix::determinant()
{
  
int i, j;
   float determinant = 0;
  
   //finding determinant
   for(i = 0; i < 3; i++)
       determinant = determinant + (a[0][i] * (a[1][(i+1)%3] * a[2][(i+2)%3] - a[1][(i+2)%3] * a[2][(i+1)%3]));
  
   cout<<("\n\ndeterminant: %f\n", determinant);
   //finding inverse
   printf("\nInverse of matrix is: \n");
   for(i = 0; i < 3; i++){
       for(j = 0; j < 3; j++)
   cout<<("%.2f\t",((a[(j+1)%3][(i+1)%3] * a[(j+2)%3][(i+2)%3]) - (a[(j+1)%3][(i+2)%3] * a[(j+2)%3][(i+1)%3]))/determinant);
      
       cout<<("\n");
   }
   }
next project3.h


#include <iostream>
class matrix
{
public:
int a[s][s],x,y;
  
  
void get();
void put();
void inverse();
void determinant();
void resize(int row, int column) ;
matrix operator+(matrix);
matrix operator-(matrix);
matrix operator*(matrix);
matrix transpose();
};

now i am uploading a screenshot of running program with proper output window

#include<stdlib.h> #include<string.h> #define s 20 using std::cout; using std::cin; using std::endl; class matrix public: int1.Matrix Addition 2.Matrix Subtration 3.Matrix Multiplication 4.Matrix Transponse matrix determinangt and inverse 6.Exit Matr1.Matrix Addition 2.Matrix Subtration 3.Matrix Multiplication 4.Matrix Transponse natrix determinangt and inverse 6.Exit Matr

Add a comment
Know the answer?
Add Answer to:
Please code in C++. link to continue the code is this below or you can make...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ must use header files and implementation files as separate files. I’ll need a header file,...

    C++ must use header files and implementation files as separate files. I’ll need a header file, implementation file and the main program file at a minimum. Compress these files into one compressed file. Make sure you have adequate documentation. We like to manipulate some matrix operations. Design and implement a class named matrixMagic that can store a matrix of any size. 1. Overload the addition, subtraction, and multiplication operations. 2. Overload the extraction (>>) and insertion (<<) operators to read...

  • For the program described below, document your code well. Use descriptive identifier names. Use s...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • For the program described below, document your code well. Use descriptive identifier names. Use spaces and...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • Please help me out with this assignment. Please read the requirements carefully. And in the main...

    Please help me out with this assignment. Please read the requirements carefully. And in the main function please cout the matrix done by different operations! Thanks a lot! For this homework exercise you will be exploring the implementation of matrix multiplication using C++ There are third party libraries that provide matrix multiplication, but for this homework you will be implementing your own class object and overloading some C+ operators to achieve matrix multiplication. 1. 10pts] Create a custom class called...

  • The assignment In this assignment you will take the Matrix addition and subtraction code and modify...

    The assignment In this assignment you will take the Matrix addition and subtraction code and modify it to utilize the following 1. Looping user input with menus in an AskUserinput function a. User decides which operation to use (add, subtract) on MatrixA and MatrixB b. User decides what scalar to multiply MatrixC by c. User can complete more than one operation or cancel. Please select the matrix operation 1- Matrix Addition A+ B 2-Matrix Subtraction A-B 3Scalar Multiplication sC 4-Cancel...

  • Write in C code What to do Write a function with the following signature: float* matrix...

    Write in C code What to do Write a function with the following signature: float* matrix multiplication(float* left, float* right, int rows, int shared, int columns); The first two arguments are two pointers to the beginning of two matrices with the dimensions (rows,shared) and (shared, columns) correspondingly. The remaining arguments specify these dimensions. The return value will return a pointer to the very beginning of the result matrix. That said, you need to provide the space for the result matrix...

  • In this lab you will code a simple calculator. It need not be anything overly fancy,...

    In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it as far as you want. You will be creating this program in three small sections. You have the menu, the performance of the basic arithmetic operations (Addition, Subtraction Multiplication, and Division), and the looping. You may want to get the switch menu working first, and then fill in the code for these four arithmetic operations...

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • using the source code at the bottom of this page, use the following instructions to make...

    using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT