Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Matrica{
- private:
- float matrica[10][10];
- int n;
- int k;
- public:
- Matrica(){
- n=0;
- k=0;
- for(int i=0;i<10;i++){
- for(int j=0;j<10;j++){
- matrica[i][j]=0;
- }
- }
- }
- void setVrednost(int i,int j,int vrednost){
- matrica[i][j]=vrednost;
- }
- void setN(int n1){
- n=n1;
- }
- void setK(int k1){
- k=k1;
- }
- int getVrednost(int i,int j){
- return matrica[i][j];
- }
- friend istream& operator>>(istream &in, Matrica &m){
- in>>m.n>>m.k;
- for(int i=0;i<m.n;i++){
- for(int j=0;j<m.k;j++){
- in>>m.matrica[i][j];
- }
- }
- return in;
- }
- friend ostream& operator<<(ostream &out,const Matrica &m){
- for(int i=0;i<m.n;i++){
- for(int j=0;j<m.k;j++){
- out<<m.matrica[i][j]<<" ";
- }
- out<<endl;
- }
- return out;
- }
- Matrica operator +(const Matrica &m){
- Matrica novaMatrica;
- novaMatrica.setK(k);
- novaMatrica.setN(n);
- for(int i=0;i<n;i++){
- for(int j=0;j<k;j++){
- novaMatrica.setVrednost(i,j,matrica[i][j]+m.matrica[i][j]);
- }
- }
- return novaMatrica;
- }
- Matrica operator +(int vrednost){
- Matrica novaMatrica;
- novaMatrica.setK(k);
- novaMatrica.setN(n);
- for(int i=0;i<n;i++){
- for(int j=0;j<k;j++){
- novaMatrica.setVrednost(i,j,matrica[i][j]+vrednost);
- }
- }
- return novaMatrica;
- }
- Matrica operator -(const Matrica &m){
- Matrica novaMatrica;
- novaMatrica.setK(k);
- novaMatrica.setN(n);
- for(int i=0;i<n;i++){
- for(int j=0;j<k;j++){
- novaMatrica.setVrednost(i,j,matrica[i][j]-m.matrica[i][j]);
- }
- }
- return novaMatrica;
- }
- Matrica operator *(const Matrica &m){
- Matrica novaMatrica;
- novaMatrica.setK(k);
- novaMatrica.setN(n);
- for(int i=0;i<n;i++){
- for(int j=0;j<k;j++){
- for(int j1=0;j1<k;j1++){
- novaMatrica.setVrednost(i,j,novaMatrica.getVrednost(i,j)+(matrica[i][j1]*m.matrica[j1][j]));
- }
- }
- }
- return novaMatrica;
- }
- };
- int main()
- {
- Matrica A,B,C;
- cin>>A>>B>>C;
- Matrica D=B*C;
- Matrica R=A-D+2;
- cout<<R;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement