C++ Programming Tutorial

 
 
 
 

Image

 # include <iostream.h>
 # include   <stdlib.h>
 # include    <conio.h>

 /***********************************************************************/
 //-----------------------------  Matrix  ------------------------------//
 /***********************************************************************/

 class Matrix
 {
    private:
       float matrix_a[3][3];
       float matrix_b[3][3];
       float matrix_c[3][3];

    public:
       Matrix( );

       void get_matrix_a( );
       void get_matrix_b( );
       void multiply_matrices( );
       void show_result_Matrix( );
 };

 /***********************************************************************/
 //----------------------------  Matrix( )  ----------------------------//
 /***********************************************************************/

 Matrix::Matrix( )
 {
    for(int i=0;i<3;i++)
    {
       for(int j=0;j<3;j++)
       {
      matrix_a[i][j]=0;
      matrix_b[i][j]=0;
      matrix_c[i][j]=0;
       }
    }

    gotoxy(1,1);
    cout<<\" ******************************************************************************\"<<endl;
    cout<<\" * * * * * * * * * * * * * *  Matrix  Multiplication  * * * * * * * * * * * * *\"<<endl;
    cout<<\" ******************************************************************************\"<<endl;

    gotoxy(1,25);
    cout<<\" ******************************************************************************\";
 }

 /***********************************************************************/
 //-------------------------  get_matrix_a( )  -------------------------//
 /***********************************************************************/

 void Matrix::get_matrix_a( )
 {
    gotoxy(1,6);
    cout<<\" Enter the values of the Matrix A row by row :\\n \"<<endl;

    cout<<\"\\t\\t\\t Ú               ¿\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t À               Ù\"<<endl;

    gotoxy(18,10);
    cout<<\" A  = \"<<endl;

    int x=28;
    int y=9;

    for(int i=0;i<3;i++)
    {
       for(int j=0;j<3;j++)
       {
      gotoxy(x,y);
      cin>>matrix_a[i][j];

      x+=5;
       }

       x=28;
       y++;
    }
 }

 /***********************************************************************/
 //-------------------------  get_matrix_b( )  -------------------------//
 /***********************************************************************/

 void Matrix::get_matrix_b( )
 {
    gotoxy(1,15);
    cout<<\" Enter the values of the Matrix B row by row :\\n \"<<endl;

    cout<<\"\\t\\t\\t Ú               ¿\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t À               Ù\"<<endl;

    gotoxy(18,19);
    cout<<\" B  = \"<<endl;

    int x=28;
    int y=18;

    for(int i=0;i<3;i++)
    {
       for(int j=0;j<3;j++)
       {
      gotoxy(x,y);
      cin>>matrix_b[i][j];

      x+=5;
       }

       x=28;
       y++;
    }
 }

 /***********************************************************************/
 //----------------------  multiply_matrices( )  -----------------------//
 /***********************************************************************/

 void Matrix::multiply_matrices( )
 {
    for(int i=0;i<3;i++)
    {
       for(int j=0;j<3;j++)
       {
      float value=0;
      float sum=0;

      for(int k=0;k<3;k++)
      {
         value=matrix_a[j][k]*matrix_b[k][j];
         sum+=value;
      }

      matrix_c[i][j]=sum;
       }
    }
 }

 /***********************************************************************/
 //---------------------  show_result_Matrix( )  -----------------------//
 /***********************************************************************/

 void Matrix::show_result_Matrix( )
 {
    clrscr( );

    gotoxy(1,1);
    cout<<\" ******************************************************************************\"<<endl;
    cout<<\" * * * * * * * * * * * * * *  Matrix  Multiplication  * * * * * * * * * * * * *\"<<endl;
    cout<<\" ******************************************************************************\"<<endl;

    gotoxy(1,6);
    cout<<\" The values of Matrix A and B are :\"<<endl;

    cout<<\"\\t\\t Ú               ¿                  Ú               ¿\"<<endl;
    cout<<\"\\t\\t ³               ³                   ³               ³\"<<endl;
    cout<<\"\\t\\t ³               ³                   ³               ³\"<<endl;
    cout<<\"\\t\\t ³               ³                  ³               ³\"<<endl;
    cout<<\"\\t\\t À               Ù             À               Ù\"<<endl;

    gotoxy(45,9);
    cout<<\" B  = \"<<endl;

    gotoxy(10,9);
    cout<<\" A  = \"<<endl;

    gotoxy(1,15);
    cout<<\" The Product of Matrix A and B is :\\n \"<<endl;

    cout<<\"\\t\\t\\t Ú               ¿\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t ³               ³\"<<endl;
    cout<<\"\\t\\t\\t À               Ù\"<<endl;

    gotoxy(13,19);
    cout<<\" A * B  = \"<<endl;

    int x_1=20;
    int y_1=8;

    int x_2=55;
    int y_2=8;

    int x_3=28;
    int y_3=18;

    for(int i=0;i<3;i++)
    {
       for(int j=0;j<3;j++)
       {
      gotoxy(x_1,y_1);
      cout<<matrix_a[i][j];

      gotoxy(x_2,y_2);
      cout<<matrix_b[i][j];

      gotoxy(x_3,y_3);
      cout<<matrix_c[i][j];

      x_1+=5;
      x_2+=5;
      x_3+=5;
       }

       x_1=20;
       y_1++;

       x_2=55;
       y_2++;

       x_3=28;
       y_3++;
    }

    gotoxy(1,25);
    cout<<\" ******************************************************************************\";
 }

 int main( )
 {
    textmode(BW80);
    clrscr( );

    Matrix Obj;

    Obj.get_matrix_a( );
    Obj.get_matrix_b( );
    Obj.multiply_matrices( );
    Obj.show_result_Matrix( );

    getch( );
    return 0;
 }

    Related Post:
  1. Perform insert, delete, merge and delete multiple occurrences of a number from an array

  2. Program to illustrate the difference between the use of strcomp, strcmpi and stricmp

  3. Program to show an example of Hashing using Mid-Square Method.

  4. Program that reads a number ,coumputes and displays its factorial using do-while loop

  5. Program that will allow a spy to encode and decode messages

  6. Tic-Tac-Toe game

  7. Program to computes the n_th term of the fibonacci series using Toplogical Odering and Dynamic Programming Technique

  8. Program to illustrate static class data

  9. Program that provides an example of This pointer

  10. Program to get possible prime numbers like number 6158 contains the substrings 6, 1, 5, 8, 61, 15, 58, 615, 158, and 6158.Find the largest substring..

  11. Program that provides an example of passing objects to function using call by reference method

  12. Program for function overloading

  13. Program that performs SCANNING of the following program and finds the entire float,integer variables and keywords present in the program

  14. Program to create a stack using static memory allocation

  15. School management system

  16. CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS

  17. Program to convert an Infix Expression into a Postfix Expression

  18. Program to illustrate the implementation of X-Direction Shear Transformation

  19. Program that displays the size, address of the variables of type int , float and char.

  20. Program to illustrate unary operator increment operator overloading with return type

 
 
Didn't find what you were looking for? Find more on Program to multiply two matrices