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

Assume that a bank maintains two kinds of accounts, are called as saving account and current account. The saving account provides compound interest and withdrawal facilities but no cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below the level, a service charge is imposed. Create a class account that stores customer name, account number and type of account. From this derive the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks: a.Include constructor for all the three classes. b.Accept deposit amount from the customer and update the balance. c.Display the balance. d.Compute and deposit interest. e.Permit withdrawal and update the balance. f. Check for minimum balance, impose penalty, necessary and update the balance.