Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Macierz{
- private:
- float a;
- float b;
- float c;
- float d;
- public:
- Macierz()
- {
- float a=0;
- float b=0;
- float c=0;
- float d=0;
- }
- Macierz(float a,float b, float c, float d): a(a), b(b), c(c), d(d){}
- float det();
- friend istream& operator>>(istream& in, Macierz& Z);
- friend ostream& operator<<(ostream& out,const Macierz& Z);
- friend Macierz operator*(const Macierz& Z, float k);
- friend Macierz operator*(const Macierz& A, const Macierz& B);
- friend Macierz operator^(const Macierz& Z, int n);
- };
- int main()
- {
- Macierz A(1,2,3,4), B;
- cout<<"Podaj macierz: "<<endl;
- cin>>B;
- cout<<"Det B: "<<B.det()<<endl;
- cout<<"B * k: "<<B * 3<<endl;
- cout<<"A * B: "<<A * B<<endl;
- cout<<"B ^ k: "<<(B ^ 2)<<endl;
- return 0;
- }
- float Macierz::det()
- {
- return a*d-b*c;
- }
- istream& operator>>(istream& in, Macierz& Z)
- {
- in>>Z.a>>Z.b>>Z.c>>Z.d;
- return in;
- }
- ostream& operator<<(ostream& out,const Macierz& Z)
- {
- out<<endl<<Z.a<<" "<<Z.b<<endl<<Z.c<<" "<<Z.d<<endl;
- return out;
- }
- Macierz operator*(const Macierz& Z, float k)
- {
- Macierz W;
- W.a=Z.a*k;
- W.b=Z.b*k;
- W.c=Z.c*k;
- W.d=Z.d*k;
- return W;
- }
- Macierz operator*(const Macierz& A, const Macierz& B)
- {
- Macierz W;
- W.a=(A.a*B.a)+(A.b*B.c);
- W.b=(A.a*B.b)+(A.b*B.d);
- W.c=(A.c*B.a)+(A.d*B.c);
- W.d=(A.c*B.b)+(A.d*B.d);
- return W;
- }
- Macierz operator^(const Macierz& Z, int n)
- {
- Macierz W;
- W = Z;
- if (n == 0){
- W.a = 1;
- W.b = 0;
- W.c = 0;
- W.d = 1;
- }
- if (n > 1){
- for(int i=0; i<n-1; ++i){
- W = W * Z;
- }
- }
- return W;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement