Question

In: Computer Science

(Part B). Develop a class of 2 x 2 matrices of double precision floating point variables...

(Part B). Develop a class of 2 x 2 matrices of double precision floating point variables that has the features listed below.

  1. An overridden default constructor that initializes all entries of the matrix to zero.
  2. An overridden copy constructor.
  3. A method that returns the inverse of the matrix, if it exists.
  4. A method that multiplies a matrix by a specified double precision floating point variable.

Solutions

Expert Solution

Here is the solution to your question. I tried my best to solve your doubt, however, if you find it is not as good as expected by you. Please do write your further doubts regarding this question in the comment section, I will try to resolve your doubts regarding the submitted solution as soon as possible.

Please give proper indentation as shown in the screenshot

If you think, the solution provided by me is helpful to you please do an upvote

Your question is incomplete, but below is the solution that best solve your doubt.

#include <iostream>

using namespace std;

class Matrix
{
double mat[2][2];

public:

// default constructor (1)
Matrix()
{
for(int i=0;i<2;i+=1)
{
for(int j=0;j<2;j+=1)
{
this->mat[i][j]=0;
}
}
}

// copy constructor (2)
Matrix(Matrix &other)
{
for(int i=0;i<2;i+=1)
{
for(int j=0;j<2;j+=1)
{
this->mat[i][j]=other.get(i,j);
}
}
}

// Inverse Function (3)
Matrix Inverse()
{
Matrix temp;
for(int i=0;i<2;i+=1)
{
for(int j=0;j<2;j+=1)
{
temp.set(this->mat[i][j],i,j);
}
}
double det=(this->get(0,0)*this->get(1,1))-(this->get(0,1)*this->get(1,0));
if(det==0)
{
cout<<endl<<"Inverse doesn't exist, returning same matrix!!!";
}
else
{
double value=1/det;
double x=temp.get(1,1);
temp.set(temp.get(0,0),1,1);   
temp.set(x,0,0);
temp.set(-1*temp.get(0,1),0,1);   
temp.set(-1*temp.get(1,0),1,0);
temp.getMultiplied(value);

}
return temp;
}

// multiplier function (4)
void getMultiplied(double value)
{
for(int i=0;i<2;i+=1)
{
for(int j=0;j<2;j+=1)
{
this->mat[i][j]*=value;
}
}
}

// print function
void print()
{
for(int i=0;i<2;i+=1)
{
for(int j=0;j<2;j+=1)
{
cout<<this->mat[i][j]<<" ";
}
cout<<endl;
}
}

// getter method
double get(int i,int j)
{
return this->mat[i][j];
}

// setter method
void set(double value,int i,int j)
{
this->mat[i][j]=value;
}
};


int main()
{
Matrix mat;
mat.set(3.0,0,0);
mat.set(3.2,0,1);
mat.set(3.5,1,0);
mat.set(3.6,1,1);
cout<<"Matrix is :\n";
mat.print();
Matrix inv=mat.Inverse();
cout<<"Inverse is :\n";
inv.print();

return 0;
}


Related Solutions

Find the double precision floating point for -0.115. Put it in hexadecimal form.
Find the double precision floating point for -0.115. Put it in hexadecimal form.
Using double precision floating point arithmetic, write a( MIPS )program that will convert input temperatures in...
Using double precision floating point arithmetic, write a( MIPS )program that will convert input temperatures in Fahrenheit to Celsius. The program should prompt the user for a temperature in Fahrenheit and then print the corresponding temperature in Celsius. The formula for the conversion is: C = 5/9 * (F – 32)
A) Convert 1101.11011101 x 223 to IEEE Standard 754 for single precision floating-point binary format. B)...
A) Convert 1101.11011101 x 223 to IEEE Standard 754 for single precision floating-point binary format. B) Convert the IEEE Standard 754 number 11001010100011010101000000000000 to its decimal equivalent.  
Determine the IEEE single and double floating point representation of the following numbers: a) (15/2) x...
Determine the IEEE single and double floating point representation of the following numbers: a) (15/2) x 2^50 b) - (15/2) x 2^-50 c) 1/5
For IEEE 754 single-precision floating point, what is the hexadecimal representation of 27.101562? A. 35CCD001 B....
For IEEE 754 single-precision floating point, what is the hexadecimal representation of 27.101562? A. 35CCD001 B. 2F5C10D0 C. 41D8D000 D. 7DCA1111 E. None of the above
Determine the IEEE single and double floating point representation of the following numbers: a) -26.25 b)...
Determine the IEEE single and double floating point representation of the following numbers: a) -26.25 b) 15/2
2. a) Represent the decimal value 47.375 as a single precision IEEE floating point number. Give...
2. a) Represent the decimal value 47.375 as a single precision IEEE floating point number. Give your answer in hexadecimal and show your work. b) Represent the decimal value 47.375 as a double precision IEEE floating point number. Give your answer in hexadecimal and show your work.
Convert 103.375 into double precision floating format show all steps and explanations
Convert 103.375 into double precision floating format show all steps and explanations
Convert -99.999 into double precision floating format show all steps and explanations
Convert -99.999 into double precision floating format show all steps and explanations
Convert -99.999 into double precision floating format show all steps and explanations
Convert -99.999 into double precision floating format show all steps and explanations
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT