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.
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
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.
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
JAVA Write a Temperature class that has two instance variables: a temperature value (a floating-point number)...
JAVA Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degrees if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius). Include the following: (1) two...
Convert 1101.11011101 x 223 to IEEE Standard 754 for single-precision floating-point binary format. Convert the IEEE...
Convert 1101.11011101 x 223 to IEEE Standard 754 for single-precision floating-point binary format. Convert the IEEE Standard 754 number 11001010100011010101000000000000 to its decimal equivalent.
a newer version of IEEE 754 defines a half precision floating point format that is only...
a newer version of IEEE 754 defines a half precision floating point format that is only 16 bits wide. the left most bit is still the sign bit. the exponent is 5 bits wide and has a bias of 15, and the fraction is 10 bits long. A hidden 1 is assumed similar to single and double precision formats. what is the bit pattern to represent -0.5 using this format?
Given the definition for a Point class that holds the coordinates of the point as double...
Given the definition for a Point class that holds the coordinates of the point as double values x and y, write a function called pt_dist that takes two points and returns the straight-line distance between them (as a double). Use two ways, pt_dist function version and the pt_dist method version. In main, include two if else tests for each, If passed "TEST PASSED, DIST IS " else "Test Failed, dist is ". Hint: Rhymes with Bythagorean Beorem. #include <iostream> #include...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT