Page 131 - DCAP404 _Object Oriented Programming
P. 131
Object-oriented Programming
Notes This program declares a class matrix to represent the number of rows and columns of matrix as
well as two dimensional array to store the contents of matrix. The constructor function used to
initialize the objects allocates the required amount of memory for the matrix.
#include<iostream.h>
#include<conio.h>
//Class Definition
class matrix
{
int **p; //declaring two dimensional array
int dl,d2;
public:
matrix(intx,inty);
void get_value( void);
void dis_value( void);
void square(void);
void cube(void);
};
matrix: : matrix( int x,int y)
{
dl=x;
d2=y;
p= new int *[d1];
for (int i =0;i<d1 ;i++)
p[i]=new int[d2];
} ;
void matrix:: get_value(void)
{
for(int i = 0;i<d1;i++)
for(int j=0;j<d2;j++)
{
cout<<“Please Enter A No At”<<i<<j<< “Position :-”;
cin>>p[i][j];
}
} ;
voidmatrix:: dis_value(void)
{
cout< <“The Matrix Entered”;
for (int i = 0;i<d1 ;i++)
124 LOVELY PROFESSIONAL UNIVERSITY