Advertisement
Guest User

Main.cpp

a guest
Oct 8th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include "MatrixType.h"
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9.     MatrixType matrixStore[10];
  10.        
  11.     do {
  12.         cout << "Choose appropriate Choice and parameters : " << endl;
  13.         cout << "\n";
  14.         cout << "0 Create New Matrix      | Usage: <choice> => 0" << endl;
  15.         cout << "1 Add Matrices      | Usage: <choice> <matrix> <matrix> => 1 0 1" << endl;
  16.         cout << "2 Subtract Matrices     | Usage: <choice> <matrix> <matrix> => 2 2 1" << endl;
  17.         cout << "3 Multiply Matrices     | Usage: <choice> <matrix> <matrix> => 3 1 4" << endl;
  18.         cout << "4 Print Matrix          | Usage: <choice> <index> => 4 0" << endl;
  19.         cout << "5 Exit          | Usage: <choice> => 5" << endl;
  20.         cout << "\n";
  21.         cout << "Enter a choice and/or paramater: " << endl;
  22.        
  23.         int choice;
  24.         cin >> choice ;
  25.        
  26.         switch (choice) {
  27.             case 0: {
  28.                 cout << "\nYou chose to Add a new matrix!" << "\n" << endl;
  29.                 cout << "At which index would you like to add the new matrix ?";
  30.                 int index;
  31.                 cin >> index;
  32.                 cout << endl;
  33.                 cout << "Enter rows and column size: ";
  34.                 int rows, cols;
  35.                 cin >> rows >> cols;
  36.  
  37.                 MatrixType matrix = MatrixType(rows, cols);
  38.                 matrixStore[index] = matrix;
  39.  
  40.                 cout << "Address of matrixStore[index] : " << &matrixStore[index] << endl;
  41.                 cout << "Address of new matrix is : " << &matrix << endl;
  42.  
  43.                 int value;
  44.                 for (int i = 0; i < rows; i++) {
  45.                     cout << "Row " << i << " : ";
  46.                     for (int j = 0; j < cols; j++) {
  47.                         cin >> value;
  48.                         matrix.StoreItem(value, i, j);
  49.                     }
  50.                 }
  51.                 cout << endl;
  52.                 //Print matrix so the use can see
  53.                 matrix.PrintMatrix();
  54.                 cout << "Address of new matrix is : " << &matrix << endl;
  55.                 break;
  56.             }
  57.             case 1: {
  58.                 cout << "you chose to Add two matrices" << endl;
  59.                 cout << "Enter the index of two matrices to be added and the index of the result matrix: " << endl;
  60.                 int index1, index2, resultIndex;
  61.                 cin >> index1 >> index2 >> resultIndex;
  62.  
  63.                 //MatrixType matrix1 = matrixStore[index1];
  64.                 //MatrixType matrix2 = matrixStore[index2];
  65.                
  66.                 //cout << "Address of matrix at " << index1 << "is : " << &matrix1 << endl;
  67.                 //cout << "Address of matrix at " << index2 << "is : " << &matrix2 << endl;
  68.  
  69.                 bool isAddComp = matrixStore[index1].isAddSubCompatible(matrixStore[index2]);
  70.                    
  71.                 if (isAddComp != 0) {
  72.                     int rows = matrixStore[index1].getRowSize();
  73.                     int cols = matrixStore[index1].getColSize();
  74.                     cout << "The two matrices can be added!" << endl;
  75.                     cout << "Computing... " << endl;
  76.                        
  77.                     //Create Result Matrix and a pointer variable to it
  78.                     MatrixType pResultMatrix = MatrixType(rows, cols);
  79.                     matrixStore[resultIndex] = pResultMatrix;
  80.                        
  81.                     //Invoke Add function
  82.                     //cout << "Address of pResultMatrix is : " << &matrixStore[resultIndex] << endl;
  83.                     matrixStore[index1].Add(matrixStore[index2], matrixStore[resultIndex]);
  84.                 }
  85.                 else {
  86.                     cout << "The two matrices can't be added! Sorry!" << endl;
  87.                     }
  88.                     break;
  89.                 }
  90.  
  91.             case 2: cout << "you chose to subtract two matrices!" << endl;
  92.                     break;
  93.            
  94.             case 3: cout << "you chose to Multiply two matrices!" << endl;
  95.                     break;
  96.            
  97.             case 4: {
  98.                         cout << "you chose to Print the matrix!" << endl;
  99.                         cout << "Enter the index of the matrix which you want to print : ";
  100.                         int index;
  101.                         cin >> index;
  102.                         matrixStore[index].PrintMatrix();
  103.                         break;
  104.                     }
  105.            
  106.             case 5: cout << "you chose to exit! Bye-Bye!" << endl;
  107.                     break;
  108.            
  109.             default: cout << "Invalid choice!" << endl;
  110.                 continue;
  111.         }
  112.     } while (true);
  113.    
  114.  
  115.     system("pause");
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement