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. Program to illustrate the functions returning pointers

  2. Program to illustrate the implementation of 3D Rotation Transformation along y-axis

  3. Program for Operator Overloading

  4. Program to estimate the Differential value of a given function using Trapezoidal Rule [Predictor-Corrector Scheme (PC2)]

  5. Program to read a Non Linear Function, construct and display the Difference Table

  6. Program to implement a Translator that reads an Infix Expression translates it into a Postfix Expression and evaluate the Postfix Expression

  7. Program to illustrate the implementation of Scaling Transformation

  8. Program to draw a Rectangle

  9. Program that takes short date from a user and displays long date

  10. Program that reads a numbers , computes and displays the factorial of the given number using recursion

  11. Code for finding a no in a binary search tree and displaying its level where it is found (root is at zero level)

  12. Program to show the projection of 3D objects using Cavalier Oblique Parallel Projection onto xy-plane (i.e. angle=45 deg)

  13. Program to fill different types of geometric shapes using Boundary Fill Algorithm (Using Linked-List)

  14. Program to illusrate data conversion user defined data types using functions

  15. Implement a Matrix class representing 2-dimensional matrix with the following functionalities i.e. operators + , - , * , == , += &lt;&lt; , &gt;&gt; etc

  16. Develop a Toy Compiler, which takes a series of statements as input, and creates a symbol table from it

  17. Problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs

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

  19. Program to illustrate classes with inline functions

  20. Program to illustrate template classes

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