-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrixCalculator.cpp
122 lines (80 loc) · 2.12 KB
/
MatrixCalculator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "Matrix.h"
#include "MatrixCalculator.h"
#include <iostream>
using namespace std ;
void MatrixCalculator::menu(){
int ch = -1 ;
while( true ){
ch = -1 ;
while( ch == -1 ){
cout << "\n Welcome to (Your Name) Matrix Calculator \n " ;
cout << "1- Perform Matrix Addition \n " ;
cout << "2- Perform Matrix Subtraction \n " ;
cout << "3- Perform Matrix Multiplication \n " ;
cout << "4- Matrix Transpose \n " ;
cout << "5- Exit \n " ;
cin >> ch ;
if( ch > 5 || ch < 1){
cout << "invalid choice \n" ;
ch = -1 ;
}
}
if( ch == 1 )add() ;
else if( ch == 2 )sub() ;
else if( ch == 3 )multi() ;
else if( ch == 4 )trans() ;
else{
cout << "Thanks for using " ;
break ;
}
}
}
void MatrixCalculator::add(){
int row , col ;
cin >> row >> col ;
Matrix<double> mat1( row , col ) ;
cin >> mat1 ;
cin >> row >> col ;
Matrix<double> mat2( row , col ) ;
cin >> mat2 ;
Matrix<double> sumMat ;
sumMat = mat1 + mat2 ;
cout << sumMat ;
}
void MatrixCalculator::sub(){
int row , col ;
cin >> row >> col ;
Matrix<double> mat1( row , col ) ;
cin >> mat1 ;
cin >> row >> col ;
Matrix<double> mat2( row , col ) ;
cin >> mat2 ;
Matrix<double> subMat ;
subMat = mat1 - mat2 ;
cout << subMat ;
}
void MatrixCalculator::multi(){
int row , col ;
cin >> row >> col ;
Matrix<double> mat1( row , col ) ;
cin >> mat1 ;
cin >> row >> col ;
Matrix<double> mat2( row , col ) ;
cin >> mat2 ;
if( mat1.getcol() != mat2.getrow() ){
cout << "Invalid process" << endl ;
return;
}
Matrix<double> multiMat ;
multiMat = mat1 *mat2 ;
cout << multiMat ;
}
void MatrixCalculator::trans(){
int row , col ;
cin >> row >> col ;
Matrix<int> mat1( row , col ) ;
cin >> mat1 ;
Matrix<int> transMat ;
transMat = mat1.transpose() ;
cout << transMat ;
}