Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <vector>
- #include <iomanip>
- #include <string>
- #include "Zespolone.h"
- #include "Punkt.h"
- using namespace std;
- template<class typ>
- class Macierz
- {
- private:
- int kolumny,wiersze;
- vector <vector<typ>> macierz;
- public:
- Macierz(int kol, int wier)
- {
- this->kolumny = kol;
- this->wiersze = wier;
- macierz.resize(wiersze, vector<typ>(kolumny, 0));
- }
- Macierz operator+(Macierz matrix) //dodawanie macierzy
- {
- Macierz wynik(matrix.kolumny,matrix.wiersze);
- try {
- if (kolumny != matrix.kolumny || wiersze != matrix.wiersze)
- {
- string blad = "rozmiar macierzy sie rozni";
- throw(blad);
- }
- for (int i = 0; i < wiersze; i++)
- {
- for (int p = 0; p < kolumny; p++)
- {
- wynik.macierz[i][p] = macierz[i][p] + matrix.macierz[i][p];
- }
- }
- }
- catch(string wyjatek)
- {
- cout << "Blad : " << wyjatek << endl;
- }
- return wynik;
- }
- Macierz operator-(Macierz matrix) //odejmowanie macierzy
- {
- Macierz wynik(matrix.kolumny, matrix.wiersze);
- try {
- if (kolumny != matrix.kolumny || wiersze != matrix.wiersze)
- {
- string blad = "rozmiar macierzy sie rozni";
- throw(blad);
- }
- for (int i = 0; i < wiersze; i++)
- {
- for (int p = 0; p < kolumny; p++)
- {
- wynik.macierz[i][p] = macierz[i][p] - matrix.macierz[i][p];
- }
- }
- }
- catch (string wyjatek)
- {
- cout << "Blad : " << wyjatek << endl;
- }
- return wynik;
- }
- Macierz operator*(Macierz matrix) //mnozenie macierzy
- {
- Macierz wynik(matrix.kolumny, matrix.wiersze);
- try {
- if (kolumny != matrix.wiersze)
- {
- string blad = "rozmiar kolumn i wierszy sie rozni";
- throw(blad);
- }
- for (int i = 0; i < wiersze; ++i)
- {
- for (int j = 0; j < matrix.kolumny; ++j)
- {
- for (int k = 0; k < kolumny; ++k)
- {
- wynik.macierz[i][j] = macierz[i][k] * matrix.macierz[k][j];
- }
- }
- }
- }
- catch (string wyjatek)
- {
- cout << "Blad : " << wyjatek << endl;
- }
- return wynik;
- }
- Macierz operator*(int N) //mnozenie macierzy przez liczbe
- {
- Macierz wynik(kolumny, wiersze);
- for (int i = 0; i < wiersze; i++)
- {
- for (int j = 0; j < kolumny; j++)
- {
- wynik.macierz[i][j] = macierz[i][j] * N;
- }
- }
- return wynik;
- }
- Macierz operator!() //negacja
- {
- Macierz wynik(kolumny, wiersze);
- for (int i = 0; i < wiersze; i++)
- {
- for (int p = 0; p < kolumny; p++)
- {
- wynik.macierz[i][p] = macierz[i][p] * -1;
- }
- }
- return wynik;
- }
- // bool operator>(Macierz matrix) //negacja
- // {
- // typ suma1,suma2;
- // for (int i = 0; i < wiersze; i++)
- // {
- // for (int p = 0; p < kolumny; p++)
- // {
- // suma1 = macierz[i][p];
- // }
- // }
- // for (int i = 0; i < matrix.wiersze; i++)
- // {
- // for (int p = 0; p < matrix.kolumny; p++)
- // {
- // suma2 = matrix.macierz[i][p];
- // }
- // }
- // if (suma1 >= suma2)
- // {
- // cout << " pierwszy wiekszy" << endl;
- // return true;
- // }
- // else
- // {
- // cout << " druga wieksza" << endl;
- //return false;
- // }
- //
- //
- // }
- // bool operator<(Macierz matrix) //negacja
- // {
- //
- // return !(*this > matrix);
- //
- // }
- //
- //
- //wypisywanie
- template<class typdanych>
- friend ostream& operator<< (std::ostream& stream, const typdanych& matrix) {
- for (int i = 0; i < matrix.wiersze; i++)
- {
- cout << "|";
- for (int p = 0; p < matrix.kolumny; p++)
- {
- stream << showpos << right;
- stream << setw(5);
- stream << matrix.macierz[i][p];
- }
- cout << " |" << endl;
- }
- cout << endl;
- return stream;
- }
- void wypelnij()
- {
- cout << "Wprowadz liczby" << endl;
- for (int i = 0; i < wiersze; i++)
- {
- for (int p = 0; p < kolumny; p++)
- {
- int x;
- cin >> x;
- macierz[i][p] = x;
- }
- }
- }
- void wypelnijPunktami()
- {
- int x, y, z;
- cout << "Wprowadz liczby" << endl;
- for (int i = 0; i < wiersze; i++)
- {
- for (int p = 0; p < kolumny; p++)
- {
- cout << "Wprowadz x" << endl;
- cin >> x;
- cout << "Wprowadz y" << endl;
- cin >> y;
- cout << "Wprowadz z" << endl;
- cin >> z;
- macierz[i][p] = Punkt(x,y,z);
- }
- }
- }
- void wypelnijZespolone()
- {
- int x, y;
- cout << "Wprowadz liczby" << endl;
- for (int i = 0; i < wiersze; i++)
- {
- for (int p = 0; p < kolumny; p++)
- {
- cout << "Wprowadz czesc rzeczywista" << endl;
- cin >> x;
- cout << "Wprowadz czesc zespolona" << endl;
- cin >> y;
- macierz[i][p] = Zespolona(x, y);
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement