© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

Home Lab Exercise Object Oriented Programming Lab Exercise ProgramsCPP Program For Matrix Addition▼


CPP Program For Matrix Addition

Alogarithm steps:

  1. Start the program
  2. Create the class
  3. Declare the data member as array and member function
  4. Get the input and store it in an array
  5. Create the object for the class
  6. Call the function by using of the object
  7. The function perform the operation using the array data members
  8. Compile and execute the program

CPP Program For Matrix Addition

#include class matrix { int a[2][2], b[2][2], c[2][2]; void add() { cout<<”Enter the A matrix:”<<”\n”; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { cin>>a[i][j]; } } cout<<”Enter the B matrix:”<<”\n”; for(int i=0; i<2; i++) { for (int j=0; j<2; j++) { cin>>b[i][j]; } } for( i = 0; i< 2; i++) { for( j = 0; j<2; j++) { c[i][j] = a[i][j] + b[i][j]; } } cout<<”Addition of Two matrixes:”<

SAMPLE INPUT AND OUTPUT:
Enter the A matrix:
1 1
1 1
Enter the B matrix:
2 2
2 2
Addition of Two matrixes:
3 3
3 3

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom