Answer to Question #181061 in C++ for RAMAKRISHNA

Question #181061

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

m1.getdata(); //accept the data in matrix

Matrix m2=m1; //copy one matrix contents into another

m2.putdata(); // display the contents of matrix

Matrix m3;

m3.putdata();

}


1
Expert's answer
2021-04-15T03:27:46-0400
#include<bits/stdc++.h>
using namespace std;
class Matrix
{
public:
    int rows,col,n;
    int mat[5][5];
    Matrix(int rows,int col)
    {
        int i=0,j=0;
        for(i=0;i<rows;i++)
        {
            for(j=0;j<col;j++)
            {
                mat[i][j]=0;
            }
        }
    }
    void getdata(int rows,int col)
    {
        int i=0,j=0;
        for(i=0;i<rows;i++)
        {
            for(j=0;j<col;j++)
            {
                cin>>mat[i][j];
            }
        }
    }
    void putdata(int rows,int col)
    {
        int i=0,j=0;
        for(i=0;i<rows;i++)
        {
            for(j=0;j<col;j++)
            {
                cout<<mat[i][j]<<" ";
            }
            cout<<"\n";
        }
    }


};
int main()
{
    Matrix m1(3,3);
    m1.getdata(3,3);
    Matrix m2=m1;
    m2.putdata(3,3);
    Matrix m3(3,3);
    m3.putdata(3,3);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS