Академический Документы
Профессиональный Документы
Культура Документы
#include <iostream.h>
#include <conio.h>
class vector
{
private:
int maxrow,maxcol,elements[10][10];
public:
void read();
void show();
class matrix
{
public:
vector add(vector &a, vector &b);
vector mul(vector &a, vector &b);
};
void vector::read()
{
for(int i=0;i<maxrow;i++)
{
for(int j=0;j<maxcol;j++)
{
cin>>elements[i][j];
}
}
}
void vector::show()
{
cout<<"\n";
for(int i=0;i<maxrow;i++)
{
cout<<"\n";
for(int j=0;j<maxcol;j++)
{
cout<<elements[i][j]<<"\t";
}
}
cout<<"\n";
}
int main()
{
int m,n;
clrscr();
matrix k;
cout<<"Enter A matrix row and column\n";
cin>>m>>n;
vector a;
a.setdata(m,n);
cout<<"\nEnter elements of matrix A\n";
a.read();
cout<<"\nMatrix A:\n";
a.show();
vector b;
b.setdata();
cout<<"\nEnter elements of matrix B\n";
b.read();
cout<<"\nMatrix B:\n";
b.show();
vector c;
cout<<"\nResultant matrix:\n";
cout<<"\nAddition\n";
c=k.add(a,b);
c.show();
cout<<"\nMultiplication";
c=k.mul(a,b);
c.show();
getch();
}
OUTPUT
Matrix A:
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
Resultant matrix:
Addition
2
4
6
8
10
12
14
16
18
Multiplication
30
36
42
66
81
96
102
126
150