Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <iostream>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. class Macierz {
  8.  
  9. public:
  10.  
  11.     double **mac;
  12.     int n, m;
  13.  
  14.  
  15.     Macierz(int n, int m) {
  16.         this->n = n;
  17.         this->m = m;
  18.         mac = new double*[n];
  19.  
  20.  
  21.         for (int i = 0; i<n; i++) {
  22.  
  23.             mac[i] = new double[m];
  24.  
  25.         }
  26.     }
  27.  
  28.     void add_mac() {
  29.         for (int i = 0; i<n; i++) {
  30.             for (int j = 0; j<m; j++) {
  31.                 while (!(cin >> mac[i][j])) {
  32.  
  33.                     cout << "Podano nieprawidlowy znak! Sprobuj jeszcze raz" << endl << endl;
  34.                     cin.clear();
  35.                     cin.sync();
  36.                 }
  37.  
  38.             }
  39.         }
  40.         system("cls");
  41.     }
  42.  
  43.     void show_mac() {
  44.         for (int i = 0; i<n; i++) {
  45.             for (int j = 0; j<m; j++) {
  46.  
  47.                 cout << "\t" << mac[i][j];
  48.             }
  49.             cout << endl;
  50.         }
  51.  
  52.     }
  53.  
  54.  
  55.  
  56.  
  57.     void suma(Macierz & maciorka) {
  58.         for (int i = 0; i < n; i++)
  59.         {
  60.             for (int j = 0; j < m; j++)
  61.                 mac[i][j] += maciorka.mac[i][j];
  62.         }
  63.  
  64.     }
  65.  
  66.     double roznica() {
  67.  
  68.     }
  69.  
  70.     double iloczyn() {
  71.  
  72.     }
  73.  
  74. };
  75.  
  76.  
  77. int main(int argc, char** argv) {
  78.  
  79.     Macierz m1(3, 3);
  80.     Macierz m2(3, 3);
  81.     Macierz m3(3, 3);
  82.  
  83.     cout << "Wprowadz dane 1 tablicy: " << endl;
  84.     m1.add_mac();
  85.  
  86.     cout << "Wprowadz dane 2 tablicy: " << endl;
  87.     m2.add_mac();
  88.  
  89.     cout << "Twoja pierwsza macierz: " << endl << endl;
  90.     m1.show_mac();
  91.  
  92.     cout << endl << "Twoja druga macierz: " << endl << endl;
  93.     m2.show_mac();
  94.     cout << endl;
  95.     cout << endl;
  96.  
  97.  
  98.     m2.suma(m1);
  99.     m2.show_mac();
  100.  
  101.    
  102.  
  103.     return 0;
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement