-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixProduct.cpp
More file actions
149 lines (131 loc) · 3.2 KB
/
MatrixProduct.cpp
File metadata and controls
149 lines (131 loc) · 3.2 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// These changes are made on github
#include <iostream>
#include "Matrix.h"
#include <vector>
#include <string>
using namespace std;
//void initialmatrix(int r,int c, Matrix& obj);
int main()
{
int i =0;
int j=0;
int value=0;
int choice=0;
string dtype;
std::vector<int > v;
cout<<" Welcome to our matric computation program "<<endl;
cout<<" Enter the three numbers for the dimension s1xs2xs3"<<endl;
for (i=0; i<3;++i)
{
cout<<"Enter the "<<i+1<<" dimension"<<endl;
cin>>value;
v.push_back(value);
}
//cout<<" The value of the first dimension is "<<v[1];
int firstrow=v[0];
int firstcol=v[1];
int secondcol=v[2];
cout<<" Enter the type of element you want to enter in small letters"<<endl;
cout<< "now initialising matrix ..........."<<endl;
cin>>dtype;
if(dtype == "int")
{
Matrix<int> m1(firstrow,firstcol,0);
Matrix<int> m2(firstcol,secondcol,0);
Matrix<int> m3(firstrow,secondcol,0);
cout<<" pLease enter the elements of first matrix "<<endl;
for (i=0; i<firstrow;++i)
{
for (j=0; j<firstcol;++j)
{
cout<<" Enter the value of "<<i+1<<" "<<j+1<<" cordinate"<<endl;
cin>> value ;
m1(i,j) = value;
}
}
cout<<" pLease enter the elements of second matrix "<<endl;
for (i=0; i<firstcol;++i)
{
for (j=0; j<secondcol;++j)
{
cout<<" Enter the value of "<<i+1<<" "<<j+1<<" cordinate"<<endl;
cin>> value ;
m2(i,j) = value;
}
}
m1.display();
cout<<endl;
m2.display();
cout<<endl;
cout<<" The multiplication of matrix m1 and m2 is "<<endl;
m3= m1*m2 ;
m3.display();
}
else if (dtype == "float")
{
Matrix<float> m1(firstrow,firstcol,0);
Matrix<float> m2(firstcol,secondcol,0);
Matrix<float> m3(firstrow,secondcol,0);
cout<<" pLease enter the elements of first matrix "<<endl;
for (i=0; i<firstrow;++i)
{
for (j=0; j<firstcol;++j)
{
cout<<" Enter the value of "<<i+1<<" "<<j+1<<" cordinate"<<endl;
cin>> value ;
m1(i,j) = value;
}
}
cout<<" pLease enter the elements of second matrix "<<endl;
for (i=0; i<firstcol;++i)
{
for (j=0; j<secondcol;++j)
{
cout<<" Enter the value of "<<i+1<<" "<<j+1<<" cordinate"<<endl;
cin>> value ;
m2(i,j) = value;
}
}
m1.display();
cout<<endl;
m2.display();
cout<<endl;
cout<<" The multiplication of matrix m1 and m2 is "<<endl;
m3= m1*m2 ;
m3.display();
}
else if (dtype =="double")
{
Matrix<double> m1(firstrow,firstcol,0);
Matrix<double> m2(firstcol,secondcol,0);
Matrix<double> m3(firstrow,secondcol,0);
cout<<" pLease enter the elements of first matrix "<<endl;
for (i=0; i<firstrow;++i)
{
for (j=0; j<firstcol;++j)
{
cout<<" Enter the value of "<<i+1<<" "<<j+1<<" cordinate"<<endl;
cin>> value ;
m1(i,j) = value;
}
}
cout<<" pLease enter the elements of second matrix "<<endl;
for (i=0; i<firstcol;++i)
{
for (j=0; j<secondcol;++j)
{
cout<<" Enter the value of "<<i+1<<" "<<j+1<<" cordinate"<<endl;
cin>> value ;
m2(i,j) = value;
}
}
m1.display();
cout<<endl;
m2.display();
cout<<endl;
cout<<" The multiplication of matrix m1 and m2 is "<<endl;
m3= m1*m2 ;
m3.display();
}
return 0;
}