C++ Program To demonstrate ability to write sparse matrix operations.
Write a C++ class to create 2D sparse matrices, sum them, and transpose them. You don't have to use operator overloading in this program. Each matrix should be shown in sparse format (which shown only non-zero items). This program will be a command line-based program. Do not interact with user with a menu. Instead, user will use "command language" (aka command entry) as detailed below. Your program will keep at most five matrices. You should be able to interpret string commands correctly. The command interpreter includes these statements:
- X -- print out matrix in sparse form
- X(a,b) = I -- assigns I to X(a,b)
- matrix X(m,n) -- create a new matrix X with size (m,n)
- X = Y + Z -- sums Y and Z and assigns it to newly created or
existing matrix X.
- X = T(Y) -- transposes Y and assigns it to newly created or
existing matrix X. - exit exits the program
An example run is given below. The command with background shows
user's entry.
>Matrix.exe↩
>>matrix A(4,7)↩
>>A(2,4) = 9↩
>>A↩
2:4 9
>>A(1,5) = 3↩
>>matrix B(4,7)↩
>>B(2,4) = -9↩
>>B(3,3) = 5↩
>>B↩
2:4 -9, 3:3 5
>>A↩
1:5 3, 2:4 9
>> C = A + B↩
>> C↩
1:5 3, 3:3 5
>> D = T(C)↩
>> D↩
3:3 5, 5:1 3
>> exit↩
#include<iostream>
using namespace std;
int main ()
{int A[10][10], i, j, m, n, count = 0;
cout << "Enter number of rows and columns : ";
cin >> m >> n;
cout << "Enter array elements : ";
for (i = 0; i < m; i++)
{for (j = 0; j < n; j++)
{cin >> A[i][j];
if (A[i][j] == 0)
count++;
}
}
if (count > ((m * n) / 2))
cout << "The matrix is a sparse matrix.\n ";
else
cout << "The given matrix is not a sparse matrix.\n ";
for (i = 0; i < m; i++)
{for (j = 0; j < n; j++)
cout << A[i][j] << " ";
cout << "\n ";
}
return 0;
}
C++ Program To demonstrate ability to write sparse matrix operations. Write a C++ class to create...
06) Write a C program to perform matrix operations based of threads. The program accepts from the user a positive integer N. A menu is given to the user: 1. generate matrices: generates three NxN matrices A, B, C with random integer numbers between 0 and 9 2. add: matrix D- A+B+C 3. subtract: matrix D A-B-C 4. display matrices: A, B, C, D 5. display count of result values more than 8. 6. exit: terminate the program When the...
Please create a C program with the following C code declares variable mtx of matrix type, and dynamically allocates memory for mtx. It will then get keyboard input for the N-by-N matrix. Subsequently, the program de-allocates (free) the memory of the matrix. A. Your task is to write the codes to dynamically allocate and de-allocate the memory for the matrix. B. Subsequently, you have to modify the above code so that now the program will first ask the user to...
Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS = 10; const int MAX_COLS = 10; class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand);...
6.18.1 Consider the sparse matrix X below and write C code that would store this code in Yale Sparse Matrix Format. Row 1 [1, 2, 0, 0, 0, 0] Row 2 [0, 0, 1, 1, 0, 0] Row 3 [0, 0, 0, 0, 9, 0] Row 4 [2, 0, 0, 0, 0, 2] Row 5 [0, 0, 3, 3, 0, 7] Row 6 [1, 3, 0, 0, 0, 1] 6.18.2 In terms of storage space, assuming that each element in...
Write a C program to implement matrix multiplication operations. First, you need to prompt the user for the size of both matrix. Then take inputs for both matrices and perform matrix multiplication operation. Finally, print the resulting matrix into the output.
in matlab
6. Create a big matrix with submatrices: The following matrix G is created by inserting the matrices A, B, and C from Exercise 3, together with zero matrices and 2 x 2 identity AY NOT llr SIIAIut. UMOADIT, SOLD Og1 DISTIunUTII》 THIS CONTENT IS PROTECTED AND M 019 2 CopprightQ Schoall of Mathercatical and Statistical Sceom Ariaona State Cniseesity matrices in the appropriate position. Create the matrix using submatrioes A, B, C, zeros and eye (that is, you...
Problem 3 (20 pts) It is required to write a Matrix Calculator Program using C Programming Language that could only perform addition, subtraction, and multiplication of two matrices of appropriate dimensions. Your program should prompt the user to select a matrix operation from a list of options that contains the aforementioned operations. Then, the user should be prompted to enter the dimensions of the two operand matrices. Next, your program should prompt the user to enter the elements of each...
It is required to write a Matrix Calculator Program using C Programming Language that could only perform addition, subtraction, and multiplication of two matrices of appropriate dimensions. Your program should prompt the user to select a matrix operation from a list of options that contains the aforementioned operations. Then, the user should be prompted to enter the dimensions of the two operand matrices. Next, your program should prompt the user to enter the elements of each matrix row-wise. Your program...
In C++
Design a class to perform various matrix operations. A matrix is a set of numbers arranged in rows and columns. Therefore, every element of a matrix has a row position and a column position. If A is a matrix of five rows and six columns, we say that the matrix A is of the size 5 X 6 and sometimes denote it as Asxc. Clearly, a convenient place to store a matrix is in a two-dimensional array. Two...
Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D arrays in Java. Create a single Java class Matrix and inside the class create the specified static methods as described Task # Description 1 Create a matrix (known components) 2 Create a matrix (random components) 3 Create a matrix from vectors 4 Compare two matrices 5 Add two matrices 6 Subtract two matrices 7 Multiply a matrix by a scalar 8 Multiply two matrices...