Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- class Macierz
- {
- public:
- Macierz(const int, const int); //wiersze i kolumny > 1 i < 100
- int getWiersze() const;
- int getKolumny() const;
- void Ustaw(const int, const int, const double);
- double Pobierz(const int, const int);
- private:
- int wiersze, kolumny;
- double ** tab;
- };
- Macierz::Macierz(const int wiersze, const int kolumny)
- {
- if (wiersze > 1 && wiersze < 100) this->wiersze = wiersze;
- else
- {
- this->wiersze = 2;
- printf("Zla wartosc! Wiersze ustalone na 2");
- }
- if (kolumny > 1 && kolumny < 100) this->kolumny = kolumny;
- else
- {
- this->kolumny = 2;
- printf("Zla wartosc! Kolumny ustalone na 2");
- }
- tab = new double * [wiersze];
- for (int i = 0; i < wiersze; i++)
- {
- tab[i] = new double [kolumny];
- for (int j = 0; j < kolumny; j++)
- {
- tab[i][j] = 0;
- }
- }
- }
- int Macierz::getWiersze() const
- {
- return wiersze;
- }
- int Macierz::getKolumny() const
- {
- return kolumny;
- }
- void Macierz::Ustaw(const int wiersz, const int kolumna, const double nowaWartosc)
- {
- tab[wiersz][kolumna] = nowaWartosc;
- }
- double Macierz::Pobierz(const int wiersz, const int kolumna)
- {
- return tab[wiersz][kolumna];
- }
- class MacierzWeWy : public Macierz
- {
- public:
- MacierzWeWy(const int, const int);
- void Wprowadz();
- void Wyswietl();
- };
- MacierzWeWy::MacierzWeWy(const int wiersze, const int kolumny) : Macierz(wiersze, kolumny)
- {}
- void MacierzWeWy::Wprowadz()
- {
- double nowaWartosc;
- for (int i = 0; i < getWiersze(); i++)
- {
- for (int j = 0; j < getKolumny(); j++)
- {
- printf("tab[%i][%i] = ", i, j);
- scanf("%lf", &nowaWartosc);
- Ustaw(i, j, nowaWartosc);
- }
- }
- }
- void MacierzWeWy::Wyswietl()
- {
- for (int i = 0; i < getWiersze(); i++)
- {
- for (int j = 0; j < getKolumny(); j++)
- {
- printf("tab[%i][%i] = %.2lf\n", i, j, Pobierz(i, j));
- }
- }
- }
- int main()
- {
- MacierzWeWy macierzWeWy(3, 2);
- macierzWeWy.Wprowadz();
- macierzWeWy.Wyswietl();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement