<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kitkat</title>
    <description>The latest articles on DEV Community by Kitkat (@kritikaacharya).</description>
    <link>https://dev.to/kritikaacharya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F912877%2Ff2618e3f-8ac9-4d27-97f4-9ae3f6ba1b51.jpeg</url>
      <title>DEV Community: Kitkat</title>
      <link>https://dev.to/kritikaacharya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kritikaacharya"/>
    <language>en</language>
    <item>
      <title>The products</title>
      <dc:creator>Kitkat</dc:creator>
      <pubDate>Sun, 21 Aug 2022 16:25:37 +0000</pubDate>
      <link>https://dev.to/kritikaacharya/the-products-4775</link>
      <guid>https://dev.to/kritikaacharya/the-products-4775</guid>
      <description>&lt;p&gt;Problem:&lt;br&gt;&lt;br&gt;
Overload the binary operator * to multiply the 2x2 matrix. Define a class Matrix with 2-D integer type array with equal size 2. Initialize one object of Matrix k with predefined values. Initialize another object of Matrix l with the user's values. Similarly, create another object n with 0 values to store the result. Now define an operator function to make the expression m = k*l executable.&lt;br&gt;&lt;br&gt;
Problem Analysis:&lt;br&gt;&lt;br&gt;
The problem is to subtract two matrices by using operator overloading. A class named matrix is defined having data members: mat[2]&lt;a href="https://dev.to2D-array"&gt;2&lt;/a&gt; and member functions void set(), void display(), one default constructor and one parameterized constructor. During the processing or calculation phase, we need a operator overloading function matrix operator - (matrix mat1) to get resultant of difference of two matrices for this problem.&lt;br&gt;&lt;br&gt;
Input variables     Processing&lt;br&gt;&lt;br&gt;
variables/calculations      Output variables    Necessary   heade&lt;br&gt;
files/functions/macr&lt;br&gt;
mat[2]&lt;a href="https://dev.to2Darray"&gt;2&lt;/a&gt;      mat[2]&lt;a href="https://dev.to2Darray"&gt;2&lt;/a&gt;      mat[2]&lt;a href="https://dev.to2Darray"&gt;2&lt;/a&gt;      iostream matrix operator * &lt;br&gt;
( matrix mat1) &lt;/p&gt;

&lt;p&gt;Algorithm:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Start
&lt;/li&gt;
&lt;li&gt; Define a class matrix and its data members and member functions  3. Define an operator overloading function: matrix operator * (matrix mat1)
&lt;/li&gt;
&lt;li&gt; Create objects of matrix class: k,l,m. &lt;/li&gt;
&lt;li&gt; Set the elements of matrix k as predefined values
&lt;/li&gt;
&lt;li&gt; Input the elements of matrix l
&lt;/li&gt;
&lt;li&gt; Perform m = k * l
&lt;/li&gt;
&lt;li&gt; Display the values of matrices: k,l and m &lt;/li&gt;
&lt;li&gt; Stop
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Flowchart:  &lt;/p&gt;

&lt;p&gt;Source Code:&lt;/p&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;p&gt;using namespace std;&lt;/p&gt;

&lt;p&gt;class Matrix&lt;br&gt;
{&lt;br&gt;
    int mat[2][2];&lt;br&gt;
    public:&lt;br&gt;
    Matrix(){}&lt;br&gt;
    friend Matrix operator*(Matrix mat1, Matrix mat2);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void setMatrix(){
    cout&amp;lt;&amp;lt;"Enter 2x2 matrix: "&amp;lt;&amp;lt;endl;
    for (int i = 0; i &amp;lt; 2; i++)
    {
        for (int k = 0; k &amp;lt; 2; k++)
        {
            cin&amp;gt;&amp;gt; mat[i][k];
        }

    }

}

void printMatrix(){
    cout&amp;lt;&amp;lt;"Here you go: "&amp;lt;&amp;lt;endl;
    for (int i = 0; i &amp;lt; 2; i++)
    {
        for (int k = 0; k &amp;lt; 2; k++)
        {
            cout&amp;lt;&amp;lt; mat[i][k]&amp;lt;&amp;lt;" ";
        }
        cout&amp;lt;&amp;lt;endl;

    }


}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;Matrix operator*(Matrix mat1, Matrix mat2)&lt;br&gt;
{&lt;br&gt;
    {&lt;br&gt;
        Matrix mult;&lt;br&gt;
        for(int i=0; i&amp;lt;2; i++)&lt;br&gt;
        {&lt;br&gt;
            for(int j=0; j&amp;lt;2; j++)&lt;br&gt;
            {&lt;br&gt;
                for(int k=0; k&amp;lt;2; k++)&lt;br&gt;
                {&lt;br&gt;
                    mult.mat[i][j] += (mat1.mat[i][k] * mat2.mat[k][j]);&lt;br&gt;
                }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        }
    }
    return mult;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;int main(){&lt;br&gt;
    Matrix a,b,c;&lt;br&gt;
    a.setMatrix();&lt;br&gt;
    b.setMatrix();&lt;br&gt;
    c=a*b;&lt;br&gt;
    c.printMatrix();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
p2.cpp&lt;br&gt;
Open with ZIP Extractor&lt;br&gt;
1 of 15&lt;/p&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;p&gt;using namespace std;&lt;/p&gt;

&lt;p&gt;class Matrix&lt;br&gt;
{&lt;br&gt;
    int mat[2][2];&lt;br&gt;
    public:&lt;br&gt;
    Matrix(){}&lt;br&gt;
    friend Matrix operator*(Matrix mat1, Matrix mat2);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void setMatrix(){
    cout&amp;lt;&amp;lt;"Enter 2x2 matrix: "&amp;lt;&amp;lt;endl;
    for (int i = 0; i &amp;lt; 2; i++)
    {
        for (int k = 0; k &amp;lt; 2; k++)
        {
            cin&amp;gt;&amp;gt; mat[i][k];
        }

    }

}

void printMatrix(){
    cout&amp;lt;&amp;lt;"Here you go: "&amp;lt;&amp;lt;endl;
    for (int i = 0; i &amp;lt; 2; i++)
    {
        for (int k = 0; k &amp;lt; 2; k++)
        {
            cout&amp;lt;&amp;lt; mat[i][k]&amp;lt;&amp;lt;" ";
        }
        cout&amp;lt;&amp;lt;endl;

    }


}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;Matrix operator*(Matrix mat1, Matrix mat2)&lt;br&gt;
{&lt;br&gt;
    {&lt;br&gt;
        Matrix mult;&lt;br&gt;
        for(int i=0; i&amp;lt;2; i++)&lt;br&gt;
        {&lt;br&gt;
            for(int j=0; j&amp;lt;2; j++)&lt;br&gt;
            {&lt;br&gt;
                for(int k=0; k&amp;lt;2; k++)&lt;br&gt;
                {&lt;br&gt;
                    mult.mat[i][j] += (mat1.mat[i][k] * mat2.mat[k][j]);&lt;br&gt;
                }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        }
    }
    return mult;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;int main(){&lt;br&gt;
    Matrix a,b,c;&lt;br&gt;
    a.setMatrix();&lt;br&gt;
    b.setMatrix();&lt;br&gt;
    c=a*b;&lt;br&gt;
    c.printMatrix();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
-Discussion and Conclusion:&lt;br&gt;&lt;br&gt;
This program is to multiply two 2x2 matrices by using operator overloading function. Hence, the product of two matrices were performed and displayed. From this lab, I understood the basic structure of C++ programming including the meaning of header files, class, data members and functions, operator overloading function, two dimensional array and steps of problem solving.  &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
