C++ program to print 3×3 matrix using class

Print 3×3 matrix using class

This program illustrate the concept to print 3×3 matrix using class. void get(), void get_ele() and void show() are the member function of class scan.

What is matrix

  • It is a rectangular array arranged in rows and coloumns.
  • Suppose a matrix “A” is denoted by m x n order.Where m=rows and n=coloumns.
  • Individual item in matrix “A” will be denoted by “aij” where i=m and j=n.
#include<iostream.h>
#include<conio.h>
class scan
{
 private:
 int d1,d2,p[10][10],i,j;
 public:
 void get(int x,int y)
  {
   d1=x;
   d2=y;
  }
 void get_ele(int i,int j,int val)
 {
  p[i][j]=val;
 }
 void show();
} ;
 
void scan::show()
{
  cout<<"Entered matrix is:- "<<endl;
  for(i=0;i<d1;i++)
   {
    for(j=0;j<d2;j++)
     {
      cout<<"\t"<<p[i][j];
     }
     cout<<endl;
   }
}
 
void main()
{
 clrscr();
 scan s1;
 int a,b,m,i,j;
 cout<<"Enter number of rows in matrix:- "<<endl;
 cin>>a;
 cout<<"Enter number of coloumns in matrix:- "<<endl;
 cin>>b;
 s1.get(a,b);
 cout<<"Enter matrix row wise"<<endl;
 for(i=0;i<a;i++)
  {
   for(j=0;j<b;j++)
    {
     cin>>m;
     s1.get_ele(i,j,m);
    }
  }
  s1.show();
 getch();
}

OUTPUT

Print 3x3 matrix using class<


Comment below if you are facing any problem.


Also read

C++ Program to add two numbers by defining function Outside the class
C++ Simple Program of Static DataMember
C++ Simple program of Static Member Function


Summary
C++ program to print 3x3 matrix using class
Article Name
C++ program to print 3x3 matrix using class
Description
This program illustrate the concept to print 3x3 matrix using class.matrix is a rectangular array arranged in rows and coloumns.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *