Search
 
SCRIPT & CODE EXAMPLE
 

CPP

two dimensional matrix using oops concept

#include<iostream.h>
	 #include<conio.h>

	   class matrix
	   {
		  int a[10][10], m,n;
		 public:
		 matrix()
		 {
		 }
		 matrix(int m,int n)
		 {
			this->m=m;
			this->n=n;


		 }
		 void set_mat()
		 {
		 for(int i=0;i<m;i++)
		  for(int j=0;j<n;j++)
		  a[i][j]=0;
		  }

		 void read_mat();
		 void disp_mat();
		 void mul_mat(matrix,matrix);
	  };
	  void matrix :: read_mat()
	  {
		for(int i=0;i<m;i++)
		 for(int j=0;j<n;j++)
		 {
		   cout<<"enter element "<<i+1<<","<<j+1<<"?";
		   cin>>a[i][j];
		 }
	  }
	  void matrix :: disp_mat()
	  {
		cout<<"Matrix Elements:
";
		for(int i=0;i<m;i++)
		{
		 for(int j=0;j<n;j++)
			cout<<a[i][j]<<"  ";
		  cout<<endl;
		 }

	   }
	   void matrix :: mul_mat(matrix m1,matrix m2)
	   {
		  if(m1.n!=m2.m)
		  cout<<"matrix multiplication is not possible ";
		  else
		  {
		  for(int i=0;i<m1.m;i++)
		   for(int j=0;j<m1.n;j++)
			for(int k=0;k<m2.n;k++)
			{
			  a[i][j]+=m1.a[i][k]*m2.a[k][j];
			}
		  }
		}
		void main()
		{
		  int m,n,p,q;
		  clrscr();


		  cout<<"enter first matrix size ?";
		  cin>>m>>n;
		  matrix m1(m,n);
		  m1.read_mat();
		  cout<<"enter second matrix size ?";
		  cin>>p>>q;
		  matrix m2(p,q);
		  m2.read_mat();
		  matrix m3(m,q);
		  m3.set_mat();
		  m3.mul_mat(m1,m2);
		  m1.disp_mat();
		  m2.disp_mat();
		  m3.disp_mat();
		  getch();
		  }
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to test if char in = to another in c++ 
Cpp :: cpp reference array 
Cpp :: c++ program 
Cpp :: 378. Kth Smallest Element in a Sorted Matrix using binary search 
Cpp :: Character convert c++ 
Cpp :: query for rmq using sqrt decomposition 
Cpp :: c++ synchronization primitives example programs 
Cpp :: read large files part by part in C++ 
Cpp :: sort n characters in descending order c++ 
Cpp :: why do men drink liquor 
Cpp :: c++ to assembly 
Cpp :: Int main ( ) { int i,n; cinn; i=n; while(i=1) { i=i+5; i=i-6; } } 
Cpp :: racing horses codechef solution c++ 
Cpp :: deadlock detection in c++coding ninjas 
Cpp :: C++ Battery Low 
Cpp :: how to find the mean and standard deviation of trqiing dataset in pytorch 
Cpp :: how can I convert each and every element of string push into set in c++? 
Cpp :: Consider a pair of integers, (a,b). The following operations can be performed on (a,b) in any order, zero or more times: - (a,b) - ( a+b, b ) - (a,b) - ( a, a+b ) 
Cpp :: c++ arreglo/array 
Cpp :: amusia 
Cpp :: how to implement stack 
Cpp :: c++ shift array to the right 
Cpp :: modify value in map c++ 
Cpp :: c++ copy string 
Cpp :: cpp set time 
C :: boilerplate c 
C :: how to set a pointer to an offset in c 
C :: get_session` is not available when using TensorFlow 2.0. 
C :: how to auto run something on cmd 
C :: c get random float 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =