0% found this document useful (0 votes)
57 views5 pages

6.perform Matrix Operations Using Object: System System - Collections.Generic System - Linq System - Text

The document defines a Matrix class that allows getting, displaying, and transposing matrix data. It contains methods to get matrix elements from user input, display the matrix, and calculate the transpose. The Main method demonstrates creating a Matrix object, getting input, displaying the original and transposed matrices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views5 pages

6.perform Matrix Operations Using Object: System System - Collections.Generic System - Linq System - Text

The document defines a Matrix class that allows getting, displaying, and transposing matrix data. It contains methods to get matrix elements from user input, display the matrix, and calculate the transpose. The Main method demonstrates creating a Matrix object, getting input, displaying the original and transposed matrices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

6.

Perform Matrix Operations Using Object

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp12
{
class Matrix
{
public
int row, col;
int[,] a = new int[10, 10];

public void get()


{
int i, j;
Console.WriteLine("Enter the order of the Matrix: ");
row = int.Parse(Console.ReadLine());
col = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the matrix element:");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
}

public void display()


{
Console.WriteLine("Given Matrix :");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
Console.Write(a[i, j] + "\t");
}
Console.WriteLine();
}
}
public void transpose()
{
Console.WriteLine("Transpose Matrix:");
for (int i = 0; i < col; i++)
{
for (int j = 0; j < row; j++)
{
Console.Write(a[j, i] + "\t");
}
Console.WriteLine();
}
}
}

class trans
{
public static void Main(string[] args)
{
Matrix m = new Matrix();
m.get();
m.display();
m.transpose();
Console.ReadKey();
}

}
}
Output:
9.Implement Operator Overloading

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace overloading
{
class Calculate
{
public int n1, n2;
public Calculate(int no1, int no2)
{
n1 = no1;
n2 = no2;
}

public static Calculate operator + (Calculate c1,Calculate c2)


{
c1.n1+=c2.n1;
c1.n2+=c2.n2;
return c1;
}
public void print()
{
Console.WriteLine("Number 1: " +n1);
Console.WriteLine("Number 2: " +n2);
}
}
class over
{
static void Main(string[] args)
{
Calculate c = new Calculate(20,-40);
c.print();
Calculate c3 = new Calculate(20, -40);
c3+=c;
c3.print();
Console.ReadKey();
}
}
}
Output:

You might also like