-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixComputation.cpp
More file actions
173 lines (168 loc) · 3.09 KB
/
MatrixComputation.cpp
File metadata and controls
173 lines (168 loc) · 3.09 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include<bits/stdc++.h>
using namespace std;
#define sk 100
class matrix
{
public:
int i,j,k,sum,r1,r2,c1,c2;
int m1[sk][sk],m2[sk][sk];
char reply;
void getin(void);
void mply(void);
void add(void);
void minus(void);
void read(void);
void input(void);
};
void matrix::getin()
{
cout<<" WELCOME TO SOLUTION OF TWO MATRICRES ";
cout<<endl;
cout<<"YOU CAN CALCULATE UPTO A LIMIT OF MATRIX 100 * 100 \n";
cout<<"YOU CAN DO THE FOLLOWING :ADDITION SUBTRACTION \n";
cout<<"MULTIPLICATION AND READ ONLY \n";
cout<<" DO YOU WANT TO CONTINUE [Y/N] : ";
cin >>reply;
if(reply=='y'||reply=='Y')
{
cout<<"\nEnter the number of rows and columns of matrix 1 : ";
cin>>r1>>c1;
cout<<"\nEnter the value of matrix 1 : "<<endl;
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
cin>>m1[i][j];
cout<<"\nEnter the number of rows and columns of matrix 2 : ";
cin>>r2>>c2;
cout<<"\nEnter the value of matrix 2 : "<<endl;
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
cin>>m2[i][j];
}
else exit(0);
}
void matrix::mply()
{
cout<<"THE RESULT AFTER MULTIPLICATION IS :";
if(c1==r2)
{
for(i=0;i<r1;i++)
{
cout<<endl;
for(j=0;j<c2;j++)
{
sum=0;
for(k=0;k<c1;k++)
sum+=m1[i][k]*m2[k][j];
cout<<setw(6)<<sum;
}
}
}
else
{
cout<<"\nNVALID INPUT ";
cout<<"\nMULTIPLICATION NOT POSSIBLE ";
}
}
void matrix::add()
{
cout<<"\nTHE RESULT AFTER ADDITION IS :";
if(r1==r2&&c1==c2)
{
for(i=0;i<r1;i++)
{
cout<<endl;
for(j=0;j<c1;j++)
cout<<setw(3)<<(m1[i][j]+m2[i][j]);
}
}
else
{
cout<<"\nINVALID INPUT ";
cout<<"\nADDITION NOT POSIIBLE ";
}
}
void matrix::minus()
{
cout<<"\nTHE RESULT AFTER SUBTRACTION IS :";
if(r1==r2&&c1==c2)
{
for(i=0;i<r1;i++)
{
cout<<endl;
for(j=0;j<c1;j++)
cout<<setw(3)<<(m1[i][j]-m2[i][j]);
}
}
else
{
cout<<"\nINVALID INPUT ";
cout<<"\nSUBTRACTION NOT POSSIBLE ";
}
}
void matrix::read()
{
cout<<" ENTERED MATRIX 1 IS :\n";
for(i=0;i<r1;i++)
{
cout<<endl;
for(j=0;j<c1;j++)
cout<<setw(3)<<m1[i][j];
}
cout<<endl;
cout<<"ENTERED MATRIX 2 IS :\n";
for(i=0;i<r2;i++)
{
cout<<endl;
for(j=0;j<c2;j++)
cout<<setw(3)<<m2[i][j];
}
}
int main()
{
int ans,option;
char response;
matrix m;
start :
m.getin();
again :
cout<<"\nWhat you wish to do : "<<endl;
cout<<"1.ADDITION ";
cout<<"2.SUBTRACTION ";
cout<<"3.MULTIPLY ";
cout<<"4.READ ONLY ";
cout<<"5.EXIT \n";
cout<<"\nENTER YOUR CHOICE IN NUMBERS : ";
repeat :
cin>>ans;
switch(ans)
{
case 1 : m.add(); break;
case 2 : m.minus(); break;
case 3 : m.mply(); break;
case 4 : m.read(); break;
case 5 : goto exit ;
default :
{
cout<<"INVALID ENTRY ENTER YOUR CHOICE AGAIN : \n";
goto repeat;
}
}
cout<<"\nDO YOU WANT TO DO IT FOR ANOTHER TIME [Y/N] :";
cin>>response;
if(response=='y'||response=='Y')
{
wrong:
cout<<"\nEnter your choice in number ";
cout<<"\n1.FOR Same matrix 2.FOR Another matrix";
cin>>option;
switch(option)
{
case 1 : goto again;
case 2 : goto start;
default: cout<<"\nINVALID ENTRY ";
goto wrong;
}
}
exit :
return 0;
}