Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .h
- #pragma once
- #include <iostream>
- class Matrica
- {
- friend std::ostream &operator<<(std::ostream &, Matrica&);
- int n; //dimenzija kvadratne matrice
- struct Polinom
- {
- int degree;
- int *coffecients;
- };
- Polinom **arr;
- public:
- Matrica(int);
- void add(int);
- ~Matrica();
- };
- .cpp
- Matrica::Matrica(int numb)
- {
- n=numb;
- arr = new Polinom*[n];
- for (int i = 0; i < n; i++)
- arr[i] = new Polinom[n];
- }
- void Matrica::add(int numb2)
- {
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- arr[i][j].degree = numb2;
- arr[i][j].coffecients = new int[numb2];
- for (int k = 0; k <arr[i][j].degree ; k++)
- {
- arr[i][j].coffecients[k] = i;
- }
- }
- }
- std::ostream & operator<<(std::ostream &out, Matrica &mat)
- {
- for (int i = 0; i < mat.n; i++)
- for (int j = 0; j < mat.n; j++)
- {
- out << "[" << i << "] " << "[" << j << "]=";
- for (int k = 0; k < mat.arr[i][j].degree; k++)
- out << mat.arr[i][j].coffecients[k] << std::endl;
- }
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement