Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class matrix { //////////////
- private: // a b //
- int a,b,c,d; // c d //
- public: //////////////
- matrix(void);
- matrix(int,int,int,int);
- matrix(const matrix&);
- int det(void); //// /// /// /// ///////// /////////
- void show(const char[255]="\b"); ///// /// /// /// /// /// /// ///
- void operator=(const matrix&); // /// /// /// /// /// /// /// ///
- matrix operator+(matrix); // /// /// /// /// /// /// /// ///
- matrix operator*(matrix); /// ////////// /// ///////// /////////
- void operator+=(matrix); /// /// /// ///////// /////////
- void operator*=(matrix); /// /// /// /// /// /// ///
- matrix operator-(void); /// /// /// /// /// /// ///
- matrix operator-(matrix); /// /// /// /// /// /// ///
- void operator-=(matrix); /////// /// /// ///////// /////////
- };
- void matrix::operator -=(matrix A) {
- (*this)=(*this)-A;
- }
- void matrix::operator *=(matrix A) {
- (*this)=(*this)*A;
- }
- void matrix::operator +=(matrix A) {
- (*this)=(*this)+A;
- }
- matrix matrix::operator*(matrix A) {
- return matrix(a*A.a+b*A.c, a*A.b+b*A.d, c*A.a+d*A.c, c*A.b+d*A.d);
- }
- matrix matrix::operator-(matrix A) {
- return -A+(*this);
- }
- matrix matrix::operator-(void) {
- return matrix(-a,-b,-c,-d);
- }
- matrix matrix::operator+(matrix A) {
- return matrix(a+A.a,b+A.b,c+A.c,d+A.d);
- }
- void matrix::operator =(const matrix& A) {
- a=A.a; b=A.b; c=A.c; d=A.d;
- }
- matrix::matrix() {
- a=1; b=0; c=0; d=1;
- }
- matrix::matrix(int a1, int b1, int c1, int d1) {
- a=a1; b=b1; c=c1; d=d1;
- }
- matrix::matrix(const matrix &A) {
- a=A.a; b=A.b; c=A.c; d=A.d;
- }
- int matrix::det() {
- return a*d-b*c;
- }
- void matrix::show(const char str[255]) {
- cout<<"Matrix "<<str<<":"<<endl;
- cout<<setw(5)<<a<<setw(5)<<b<<endl;
- cout<<setw(5)<<c<<setw(5)<<d<<endl<<endl;
- }
- int main() {
- matrix A(1,2,3,4),B(4,5,6,7),C;
- A.show("A");
- B.show("B");
- C.show("C");
- C=A*B;
- C.show("C=A*B");
- cout<<"Det[A]: "<<A.det()<<endl;
- cout<<"Det[B]: "<<B.det()<<endl;
- cout<<"Det[C]: "<<C.det()<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment