Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. PO(funkcje zaprzyjaznione - macierz):
  2.  
  3. #include <iostream>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. class macierz
  9. {
  10.     float a[3][3];
  11.     public:
  12.         macierz(float b[3][3])
  13.         {
  14.             for(int i=0;i<3;i++) for(int j=0;j<3;j++) a[i][j]=b[i][j];
  15.         }
  16.        
  17.         friend void wyswietl(macierz);
  18.         friend float suma(macierz);
  19.         friend void norma(macierz);
  20. };
  21.  
  22.  
  23. float suma(macierz m)
  24. {
  25.     float s=0;
  26.     for(int i=0;i<3;i++)
  27.     {
  28.         for(int j=0;j<3;j++)
  29.         {
  30.              s+=m.a[i][j];
  31.         }
  32.     }
  33.     return s;
  34. }
  35.        
  36. void wyswietl(macierz m)
  37. {
  38.     for(int i=0;i<3;i++)
  39.     {
  40.         for(int j=0;j<3;j++)
  41.         {
  42.              cout<<m.a[i][j]<<"\t";
  43.         }
  44.         cout<<endl;
  45.     }
  46.     cout<<endl;
  47. }
  48.  
  49. void norma(macierz m)
  50. {
  51.     float n=0;
  52.     for(int i=0;i<3;i++)
  53.     {
  54.         for(int j=0;j<3;j++)
  55.         {
  56.              n+=m.a[i][j]*m.a[i][j];
  57.         }
  58.     }
  59.     cout<<"Norma: "<<sqrt(n);
  60. }
  61.  
  62. int main()
  63. {
  64.     float q1[3][3]={{1,2,3},{3,4,5},{5,6,7}};
  65.     macierz m1(q1);
  66.     float q2[3][3]={{1,1,1},{0,1,0},{0,0,1}};
  67.     macierz m2(q2);
  68.     wyswietl(m1);
  69.     wyswietl(m2);
  70.     cout<<"Suma1: "<<suma(m1)<<endl;
  71.     cout<<"Suma2: "<<suma(m2)<<endl;
  72.     norma(m2);
  73.    
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement