Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Matrix Addition Program

Posted By: Easy Tutor     Category: C++ Programming     Views: 16578

Matrix Addition Program which takes two user-defined matrix and performed addition. Program will also checks wether user had given correct matrix dimension in order to perform addition operation on Matrix

Code for Matrix Addition Program in C++ Programming

/*www.DailyFreeCode.comDownload Projects, Sourcecodes, Tips and Tricks, Interview FAQs, Hotlinks and more....Logon to www.DailyFreeCode.com*///MATRIX ADDITION//Pointers implementation through pointers
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

class matrix
{
int **p,row,col;
public:
void getdata(void);
friend void matrixadd(matrix &,matrix &);
void display(void);
};

void matrix :: getdata(void)
{
clrscr();
cout<<"Enter Size of Row:-";
cin>>row;
p=newint *[row];
cout<<"Enter size of Coulumn:-";
cin>>col;
cout<<"\nEnter Data for Matrix of size "<<row<<"*"<<col<<endl;
 for(int i=0;i<row;i++)
 {
   p[i]=newint [col];
 }
//scaning valuefor(int a=0;a<row;a++)
{
  for(int b=0;b<col;b++)
  {
     cin>>p[a][b];
  }
}
}


void matrix :: display(void)
{
cout<<"\n\n\n\n";
cout<<"Display Function\n\n";
for(int i=0;i<row;i++)
{
   for(int j=0;j<col;j++)
   {
     cout<<setw(5)<<p[i][j];
   }
cout<<endl;
}
}

void matrixadd(matrix &a,matrix &b)
{
int result[10][10];
if(a.row==b.row && a.col==b.col)
{
  for(int i=0;i<a.row;i++)
  {
    for(int j=0;j<a.col;j++)
    {
         result[i][j]=a.p[i][j]+b.p[i][j];
    }
  }
//displayingfor(int x=0;x<a.row;x++)
  {
    for(int y=0;y<a.col;y++)
    {
      cout<<setw(5)<<result[x][y];
    }
    cout<<endl;
  }
}
else
  cout<<"Invalid Matrix Addition Occurs as size differs\n";
}

void main()
{
matrix o1,o2;
o1.getdata();
o2.getdata();
clrscr();
o1.display();
o2.display();
getch();
clrscr();
cout<<"\n\nAfter Adition Has been Performed\n\n";
matrixadd(o1,o2);
getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Matrix Addition Program Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Matrix Addition Program is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!