From f33d1d0c8baf484395cc8d05c49901fbdc3128f8 Mon Sep 17 00:00:00 2001 From: Lavanya Goyal <87686764+Lavanya11G@users.noreply.github.com> Date: Sat, 8 Oct 2022 23:12:55 +0530 Subject: [PATCH] Create matrix.cpp Created a matrix gives the sum of 2 matrix difference multiplication and transpose of the matrix closes #738 --- C++/matrix.cpp | 140 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 C++/matrix.cpp diff --git a/C++/matrix.cpp b/C++/matrix.cpp new file mode 100644 index 00000000..466fc57c --- /dev/null +++ b/C++/matrix.cpp @@ -0,0 +1,140 @@ +#include +using namespace std; +class matrix +{ +public: + int a[4][4], b[4][4], c[4][4], d[4][4], r, s, i, j,k; + void get(); + void put(); + void sum(); + void diff(); + void Multi(); + void trans(); +}; + +void matrix ::get() +{ + cout << "\n enter the no. of rows & columns\n"; + cin >> r >> s; + cout << "\n Enter " << r * s << " elements\n"; + for (i = 0; i < r; i++) + { + for (j = 0; j < s; j++) + { + cin >> a[j][i]; + } + } + cout << "\n Enter elements of second Matrix are\n"; + for (i = 0; i < r; i++) + { + for (j = 0; j < s; j++) + { + cin >> b[j][i]; + } + } +} +void matrix ::put() +{ + cout << "\n Elements in the matrix are:\n"; + for (i = 0; i < r; i++) + { + for (j = 0; j < s; j++) + { + cout << "\t" << a[i][j]; + } + cout << "\n"; + } + cout << "\n Elements in the 2nd matrix are:\n"; + for (i = 0; i < r; i++) + { + for (j = 0; j < s; j++) + { + cout << "\t" << b[i][j]; + } + cout << "\n"; + } +} +void matrix ::sum() +{ + cout << "Sum of Matrices 1 and 2 is\n"; + for (i = 0; i < r; i++) + { + for (j = 0; j < s; j++) + { + c[i][j] = a[i][j] + b[i][j]; + cout << c[i][j] << " "; + } + cout << endl; + } +} +void matrix ::diff() +{ + cout << "Diffrence of Matrices 1 and 2 is\n"; + for (i = 0; i < r; i++) + { + for (j = 0; j < s; j++) + { + d[i][j] = a[i][j] - b[i][j]; + cout << d[i][j] << " "; + } + cout << endl; + } +} +void matrix ::Multi() +{ + cout << "Multiplication of Matrices 1 and 2 is\n"; + { + for(i=0;i> ch; + } while (ch != 'n'); + cout << "Thank You!!\n"; + system("pause"); + return 0; +}