1. Create a class called Matrix having the following data members
int rows:
int cols:
int mat[ ] [ ].
Write a program to implement the following operations (the ones mentioned in comments) on Matrix. The main function of the above program is as below:
int main() { Matrix m1(3,3);//it will initialize rows and cols
ml.get data(): Accept the data in matrix Matrix m2=ml://copy one matrix contents into another
m2.putdata();// display the contents of matrix
Matrix m3;
m3.putdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class matrix{
int row;
int col;
int mat[3][3];
public:
void getData();
void putData();
};
void matrix::getData()
{
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
cout<<"mat["<<i<<"]["<<j<<"] : ";
cin>>mat[i][j];
}
}
}
void matrix::putData()
{
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
cout<<" "<<mat[i][j];
}
cout<<endl;
}
}
int main()
{
matrix m;
m.getData();
m.putData();
getch();
return(0);
}
Comments
Leave a comment