Saturday, September 27, 2014

Construct a matrix of size m X n using the class type objects and there must be a member function that returns a value of the matrix at desired index.

Algorithm:
1.      Create a class with member functions input(),search().
2.      Enter the size of matrix and the elements
3.      Enter the element to be searched.
4.      Searching the data
int  search(int b,int c)
            {
                  int d=a[b][c];
                  cout<
                  return 0;
            }
5.      Call the display function and display.
6.      End of program
Program:
#include
#include
class matrix
{
            private:
            int a[20][20],i,j,n,m,b,c;
            public:
            int input()
            {
                        cout<<"Enter the size of matrix (mXn):";
                        cin>>m>>n;
                        cout<<"Enter the elements of the matrix:";
                        for(i=0;i
                        {
                                    for(j=0;j
                                    {
                                                cin>>a[i][j];
                                    }
                        }
                        for(i=0;i
                        {
                                    for(j=0;j
                                    {
                                                cout<
                                    }
                                    cout<<"\t"<
                        }
                        return 0;
            }
            int  search(int b,int c)
            {
                  int d=a[b][c];
                  cout<
                  return 0;
            }


};
void main()
{
            clrscr();
            int m,n,a[20][20],i,j,b,c;
            matrix m1;
            m1.input();
            cout<<"Enter the element to be searched (mXn):";
            cin>>b>>c;
            m1.search(b,c);
            getch();


}

No comments:

Post a Comment