Write a menu driven program to perform following: a) Input a matrix b) Display matrix c) Add two matrix d) Multiply two matrixes e) Transpose a matrix

 



#include <iostream>
using namespace std;
class menu
{
private:
    int a[10][10];
    int b[10][10],sum[10][10];
    int ijn;

public:
    void inputmatrix();
    void displaymatrix();
    void addmatrix();
    void mulmatrix();
    void transposematrix();
};

void menu ::inputmatrix()
{
    cout << "enter the size of matrix : " << endl;
    cin >> n;
    cout << "enter the elements of the first matrix : " << endl;
    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cin >> a[i][j];
        }
    }

    cout << "enter the elements of the second matrix : " << endl;
    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cin >> b[i][j];
        }
    }
}

void menu ::displaymatrix()
{
    inputmatrix();

    cout << "yr first matrix is : " << endl;
    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cout << " " << a[i][j];
        }
        cout << " " << endl;
    }

    cout << "yr second matrix is : " << endl;
    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cout << " " << b[i][j];
        }
        cout << " " << endl;
    }
}

void menu ::addmatrix()
{
    inputmatrix();

    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            sum[i][j] = a[i][j] + b[i][j];
        }
    }

    cout << " the sum of two matrix is :" << endl;

    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cout << " " << sum[i][j];
        }
        cout << " " << endl;
    }
}

void menu ::mulmatrix()
{
    inputmatrix();
    int mul[n][n], kc[i][j];
    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            sum[i][j] = 0;
            for (k = 0k < nk++)
            {
                sum[i][j] = sum[i][j] + a[i][k] * b[k][j];
                c[i][j] = sum[i][j];
            }
        }
    }

    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cout << " " << c[i][j];
        }
        cout << " " << endl;
    }
}

void menu ::transposematrix()
{
    cout << " enter the size of a matrix :" << endl;
    cin >> n;
    cout << "enter the elements of matrix :" << endl;
    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cin >> a[i][j];
        }
    }

    cout << "yr matrix is : " << endl;
    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cout << " " << a[i][j];
        }
        cout << " " << endl;
    }

    cout<<"the transpose of your matrix is :"<<endl;

    for (i = 0i < ni++)
    {
        for (j = 0j < nj++)
        {
            cout << " " <<a[j][i];
        }
        cout << " " << endl;
    }
}

int main()
{
    menu d;
    int number;
    cout << "choose a option :" << endl;
    cout << "1. input a matrix \n2. display two matrix \n3. add two matrix \n4. multiply two matrix \n5. transpose a matrix " << endl;
    cin >> number;
    switch (number)
    {
    case 1:
        d.inputmatrix();
        break;
    case 2:
        d.displaymatrix();
        break;
    case 3:
        d.addmatrix();
        break;
    case 4:
        d.mulmatrix();
        break;
    case 5:
        d.transposematrix();
        break;

    default:
        break;
    }
}

output :

choose a option : 1. input a matrix 2. display two matrix 3. add two matrix 4. multiply two matrix 5. transpose a matrix 4 enter the size of matrix : 2 enter the elements of the first matrix : 1 2 1 2 enter the elements of the second matrix : 2 1 2 1 6 3 6 3

Comments

Popular Post

Define a class to represent a Bank Account. Include the following members: Data Members: i. Name of the depositor ii. Account number iii. Type of account iv. Balance amount in the account Member Functions: 1. To Input initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance Also write constructor for this class that takes four arguments. It should also handle type of account as savings by default

Define a class in C++ with following description: Private Members A data member Flight number of type integer A data member Destination of type string A data member Distance of type float A data member Fuel of type float A member function CALFUEL() to calculate the value of Fuel as per the following criteria Distance Fuel <=1000 500 more than 1000 and <=2000 1100 more than 2000 2200 Public Members A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call function CALFUEL() to calculate the quantity of Fuel. A function SHOWINFO() to allow user to view the content of all the data members.