Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. class LiczbaZespolona {
  7. private:
  8.     double a;
  9.     double b;
  10.  
  11. public:
  12.     LiczbaZespolona()
  13.     {
  14.         a = 1.0;
  15.         b = 2.0;
  16.     }
  17.     LiczbaZespolona(double x, double y)
  18.     {
  19.         a = x;
  20.         b = y;
  21.     }
  22.     ~LiczbaZespolona()
  23.     {
  24.     }
  25.     friend bool porownaj(LiczbaZespolona, LiczbaZespolona);
  26.     friend ostream& operator<<(ostream& os, const LiczbaZespolona& liczba);
  27. };
  28.  
  29. ostream& operator<<(ostream& outstream, const LiczbaZespolona& liczba) {
  30.     outstream << liczba.a << " " << liczba.b;
  31.     return outstream;
  32. }
  33.  
  34. template<class Typ>
  35. bool porownaj(Typ a, Typ b)
  36. {
  37.     if (a == b)
  38.         return true;
  39.     else
  40.         return false;
  41. }
  42. bool porownaj(LiczbaZespolona l1, LiczbaZespolona l2)
  43. {
  44.     if ((l1.a == l2.a) && (l1.b == l2.b))
  45.         return true;
  46.     else
  47.         return false;
  48. }
  49.  
  50. template<class TypM> class Macierz
  51. {
  52. private:
  53.     vector< vector< TypM > > macierz;
  54.     int szerokosc;
  55.     int wysokosc;
  56. public:
  57.     Macierz()
  58.     {
  59.         szerokosc = wysokosc = 5;
  60.         vector< vector< TypM > > tempMacierz(szerokosc, vector<TypM>(wysokosc, TypM()));
  61.         macierz = tempMacierz;
  62.     }
  63.     Macierz(int x, int y)
  64.     {
  65.         szerokosc = x;
  66.         wysokosc = y;
  67.         vector< vector< TypM > > tempMacierz(szerokosc, vector<TypM>(wysokosc, TypM()));
  68.         macierz = tempMacierz;
  69.     }
  70.     void Dodaj(TypM Element, int x, int y)
  71.     {
  72.         if (((x >= 0) && (x < szerokosc)) && ((y >= 0) && (y < wysokosc)))
  73.             macierz[x][y] = Element;
  74.     }
  75.     TypM& Pobierz(int x, int y)
  76.     {
  77.         if (((x >= 0 )&& (x < szerokosc)) && ((y >= 0) && (y < wysokosc)))
  78.             return macierz[x][y];
  79.     }
  80.     void Wypisz()
  81.     {
  82.         for (int i = 0; i < szerokosc; i++)
  83.         {
  84.             for (int j = 0; j < wysokosc; j++)
  85.                 cout << macierz[i][j] << " ";
  86.  
  87.             cout << endl;
  88.         }
  89.     }
  90.     bool Porownaj(Macierz&)
  91.     {
  92.        
  93.     }
  94. };
  95.  
  96. int main()
  97. {
  98.     Macierz<int> calkowite(9, 11);
  99.     Macierz<double> zmiennoprzecinkowe(3, 7);
  100.     Macierz<LiczbaZespolona> zespolone(8, 3);
  101.  
  102.     zespolone.Wypisz();
  103.     int x; cin >> x;
  104.     return 1;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement