Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include "MatrixType.h"
- using namespace std;
- int main() {
- MatrixType matrixStore[10];
- do {
- cout << "Choose appropriate Choice and parameters : " << endl;
- cout << "\n";
- cout << "0 Create New Matrix | Usage: <choice> => 0" << endl;
- cout << "1 Add Matrices | Usage: <choice> <matrix> <matrix> => 1 0 1" << endl;
- cout << "2 Subtract Matrices | Usage: <choice> <matrix> <matrix> => 2 2 1" << endl;
- cout << "3 Multiply Matrices | Usage: <choice> <matrix> <matrix> => 3 1 4" << endl;
- cout << "4 Print Matrix | Usage: <choice> <index> => 4 0" << endl;
- cout << "5 Exit | Usage: <choice> => 5" << endl;
- cout << "\n";
- cout << "Enter a choice and/or paramater: " << endl;
- int choice;
- cin >> choice ;
- switch (choice) {
- case 0: {
- cout << "\nYou chose to Add a new matrix!" << "\n" << endl;
- cout << "At which index would you like to add the new matrix ?";
- int index;
- cin >> index;
- cout << endl;
- cout << "Enter rows and column size: ";
- int rows, cols;
- cin >> rows >> cols;
- MatrixType matrix = MatrixType(rows, cols);
- matrixStore[index] = matrix;
- cout << "Address of matrixStore[index] : " << &matrixStore[index] << endl;
- cout << "Address of new matrix is : " << &matrix << endl;
- int value;
- for (int i = 0; i < rows; i++) {
- cout << "Row " << i << " : ";
- for (int j = 0; j < cols; j++) {
- cin >> value;
- matrix.StoreItem(value, i, j);
- }
- }
- cout << endl;
- //Print matrix so the use can see
- matrix.PrintMatrix();
- cout << "Address of new matrix is : " << &matrix << endl;
- break;
- }
- case 1: {
- cout << "you chose to Add two matrices" << endl;
- cout << "Enter the index of two matrices to be added and the index of the result matrix: " << endl;
- int index1, index2, resultIndex;
- cin >> index1 >> index2 >> resultIndex;
- //MatrixType matrix1 = matrixStore[index1];
- //MatrixType matrix2 = matrixStore[index2];
- //cout << "Address of matrix at " << index1 << "is : " << &matrix1 << endl;
- //cout << "Address of matrix at " << index2 << "is : " << &matrix2 << endl;
- bool isAddComp = matrixStore[index1].isAddSubCompatible(matrixStore[index2]);
- if (isAddComp != 0) {
- int rows = matrixStore[index1].getRowSize();
- int cols = matrixStore[index1].getColSize();
- cout << "The two matrices can be added!" << endl;
- cout << "Computing... " << endl;
- //Create Result Matrix and a pointer variable to it
- MatrixType pResultMatrix = MatrixType(rows, cols);
- matrixStore[resultIndex] = pResultMatrix;
- //Invoke Add function
- //cout << "Address of pResultMatrix is : " << &matrixStore[resultIndex] << endl;
- matrixStore[index1].Add(matrixStore[index2], matrixStore[resultIndex]);
- }
- else {
- cout << "The two matrices can't be added! Sorry!" << endl;
- }
- break;
- }
- case 2: cout << "you chose to subtract two matrices!" << endl;
- break;
- case 3: cout << "you chose to Multiply two matrices!" << endl;
- break;
- case 4: {
- cout << "you chose to Print the matrix!" << endl;
- cout << "Enter the index of the matrix which you want to print : ";
- int index;
- cin >> index;
- matrixStore[index].PrintMatrix();
- break;
- }
- case 5: cout << "you chose to exit! Bye-Bye!" << endl;
- break;
- default: cout << "Invalid choice!" << endl;
- continue;
- }
- } while (true);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement