14. Write a program to find transpose of a given matrix of mxn size using unary operator overloading

/* TRANSPOSE OF A GIVEN MATRIX OF MXN SIZE USING UNARY OPERATOR OVERLOADING */ 


#include<iostream>
using namespace std;
class matrix
{
        int x[5][5],m,n;
public:
        matrix()
        {

        }
        matrix(int a,int b)
        {
               m=a;n=b;
        }
        void get();
        void put();
        matrix operator !();
};
void matrix::get()
{
        int i,j;
        cout<<"\n Enter a matrix of order"<<m<<"x"<<n<<"\n";
               for(i=0;i<m;i++)
                   for(j=0;j<n;j++) 
                        cin>>x[i][j];
}
void matrix::put()
{
         int i,j;
        cout<<"\n The matrix after TRANSPOSE is :\n";
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
                    cout<<x[i][j]<<"\t";
               cout<<endl;
     }
}

matrix matrix::operator !()
{
        matrix c(n,m);
        int i,j;
        for(i=0;i<m;i++)
               for(j=0;j<n;j++)
                    c.x[i][j]=x[j][i];
         return c;
}

int main()
{
        int m,n;
        cout<<"\n Enter the order of  matrix \t";
        cin>>m>>n;
        matrix a(m,n),c;
        a.get();
        c=!a;
        c.put();
        return 0;
}
Posted by Unknown On 05:17 26 comments READ FULL POST
13.Write a program to add two matrices of mxn size using binary operator overloading.
 
/* ADD TWO MATRICES OF MXN SIZE USING BINARY OPERATOR OVERLOADING  */ 


#include<iostream>
using namespace std;
class matrix 
{
        int m, n, x[30][30]; 
public:
        matrix(int a, int b)
       { 
                m=a;
                n=b;
       }
        matrix(){}
        void get();
        void put();
        matrix operator +(matrix);
}; 

void matrix:: get()
{  
        cout<<"\n Enter values into the matrix";
               for(int i=0; i<m; i++)
                       for(int j=0; j<n;j++)
                       cin>>x[i][j];

}

void matrix:: put()
{  
        cout<<"\n the sum of the matrix is :\n";
               for(int i=0; i<m; i++)
               {
                       for(int j=0; j<n;j++)
                       cout<<x[i][j]<<"\t";
                       cout<<endl;
               }
} 

matrix matrix::operator +(matrix b)
{   
        matrix c(m,n);
        for(int i=0; i<m; i++)
                for(int j=0; j<n; j++)
                c.x[i][j]= x[i][j] + b.x[i][j];
        return c;
}

int main()
{    
        int m,n;
        cout<<"\n Enter the size of the array";
        cin>>m>>n;
        matrix a(m,n) , b(m,n) , c;
        a.get();
        b.get();
        c= a+b;
        c.put();
        return 0;
}
Posted by Unknown On 05:13 45 comments READ FULL POST
15. Write a program to concatenate one string to another using binary operator overloading.

/* CONCATENATE ONE STRING TO ANOTHER USING BINARY OPERATOR OVERLOADING */ 
 

#include<iostream>
#include<string.h>
 
using namespace std;
class str 
{
        char *st;
public:
        str(int len, char *s)
        {  
               int l=strlen(s);
               st= new char[l];
               st=s; 
        }
        str()
        {
 
        }
        void put();
        str operator +(str);
};

str str :: operator +(str s) 
{  /*str abc;
abc.st=strcat(st, s.st);
return abc;*/
        st=strcat(st, s.st);
        return *this;
}

void str :: put()
{
  cout<<"\n The string after concatenation is : \n"<<st;
}

int main() 
{
        char str1[30], str2[30];
        cout<<"\n Enter a string \n";
        cin>>str1;
        cout<<"\n Enter the 2nd string \n";
        cin>>str2;
        int l1= strlen(str1), l2=strlen(str2);
        str s2(l1,str1), s3(l2,str2), s4;
        s4=s2+s3;
        s4.put();
        return 0;
}
Posted by Unknown On 05:11 No comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *