Make a program ( visual Studio/ c++ project/ in a form of .C) that takes in matr
ID: 3875400 • Letter: M
Question
Make a program ( visual Studio/ c++ project/ in a form of .C) that takes in matrices A, B and X. see the image below.
and find the solution for X=inv(A) * B using CRAMER'S RULE
1. you have to take in matrices A B and X in the main function(see the image below)
The size of Matrix A may vary from 2x2 to 5x5 and so does size of B and X
instead of inputting the elements of A B and X
the inputs are taken as the equations in the form of STRINGS
the elements of A B and X are extracted from the input strings
in this case the characters input for each element of A and B are in the from of sTTTT.VVV
where, s is - for negative number and + for positive number
T are digits before decimal
V are digits after decimal
the equation entered MUST be like
+1023.557a -22.005A +2.0M = 0.004
2. A and B can be float/double numbers
3. X is a vector with all inputs as characters
4. Use Cramer's rule to find the solution.
make a separate function for finding determinant of the matrix.
check if det(A)==0 to determine the solution is possible or not.
display your results for the characters in vector X
roject BASIC REQUIREMENTS 1 you have to take itn 4. Use Cramers nule to find the solution make a separate tunction for finding determinant of the matrix. check if det(A)-0 to determine the soltion is possible or not. 1 instead of inputting the elements of A B and X the inputs are taken as the equations in the form of STRINGS in this case the characters inpus for each element of A and B are in the from of sTTTT VVV T are digts betore decimal V are dgts aner decimal the equation entered MUST be like +1023·557a-22.005A +2.0M 0.004
Explanation / Answer
#include<iostream.h>
void input(int array[][3], int array1[][1]);
int determinent(int array[][3]);
int calculate(int array[][3], int a, int b, int c);
int copy(int array[][3], int array1[][1], int a);
void comp_copy(int array[][3], int array1[][3]);
int main()
{
cout<<"Enter a 3 by 3 matrix from a given system. First, enter the 1st row, then, ";
cout<<" the first entry on the right side of the equality. ";
cout<<"Provide a space for each number. ";
cout<<" Like this: ";
cout<<" 3 4 5 6 -> 6 is the number on the right side of the equality ";
cout<<" 2 7 5 3 ";
cout<<" 1 3 4 2 ";
bool yes=true;
while(yes)
{
cout<<"Enter now... ";
int matrix[3][3];
int matrix1[3][1];
int reserve[3][3];
int s, detr[3], sp1=0,cont=0, teen=1;
char in;
input(matrix, matrix1);
comp_copy(reserve, matrix);
s=determinent(matrix);
while(sp1<3)
{
detr[cont]=copy(matrix, matrix1, sp1);
comp_copy(matrix,reserve);
cont++;
sp1++;
}
cont=0;
while(cont<3)
{
cout<<"x"<<teen<<" = "<< detr[cont]<<" /"<<det00<<endl;
cont++;
teen++;
}
cout<<"If you want to exit press n else press any key ";
cin>>in;
if(in=='n' || in=='N')
return 1;
}
return 0;
}
void input(int array[][3], int array1[][1])
{
int rows=0, col=0, x=0;
while(rows<3)
{
col=0;
while(col<3)
{
cin>>array[rows][col];
col++;
}
cin>>array1[x][0];
x++;
rows++;
}
}
int determinent(int array[][3])
{
int rows=1, col=1;
int z=0;
int temp=0;
int cont=1;
int x=0;
while(x<3)
{
temp=temp+cont*(array[0][x]*calculate(array,rows, col, z));
col=col*0;
z=z+cont;
cont=cont*-1;
x++;
}
cout<<" Determinant of the matrix above is "<<temp<<" ";
return temp;
}
int calculate(int array[][3], int a, int b, int c)
{
int temp1;
temp1=(array[a][b]*array[a+1][b+1+c])-(array[a+1][b]*array[a][b+1+c]);
return temp1;
}
int copy(int array[][3], int array1[][1], int a)
{
int col=0;
int temp;
while(col<3)
{
array[col][a]=array1[col][0];
col++;
}
int i=0, j=0;
while(i<3)
{
j=0;
while(j<3)
{
cout<<array[i][j]<<" ";
j++;
}
cout<<endl;
i++;
}
temp=determinent(array);
return temp;
}
void comp_copy(int array[][3], int array1[][3])
{
int rows=0, col=0;
while(rows<3)
{
col=0;
while(col<3)
{
array[rows][col]=array1[rows][col];
col++;
}
rows++;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.