Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DZiedziczeniemaceirze.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <malloc.h>
- #include <conio.h>
- class Macierz
- {
- protected:
- int wiersze, kolumny;
- float **nxm;
- public:
- Macierz(const int k, const int w)
- {
- if ( (w<0) || (k<0) || (w>100) || (k>100) )
- {
- }
- else
- {
- wiersze = w;
- kolumny = k;
- nxm = (float**) malloc (sizeof (float*) * kolumny);
- for (int i=0;i<kolumny;i++)
- {
- nxm[i] = (float*) malloc (sizeof (float) * wiersze);
- }
- for (int i=0; i<kolumny;i++)
- {
- for (int j=0;j<wiersze;j++)
- {
- nxm[i][j] = 0;
- }
- }
- }
- }
- const int Wiersze () const
- {
- return wiersze;
- }
- const int Kolumny () const
- {
- return kolumny;
- }
- void Ustaw (const int k,const int w,const float value)
- {
- nxm[k][w] = value;
- }
- const float Pobierz (const int k,const int w) const
- {
- return nxm[k][w];
- }
- };
- class MacierzWewy : public Macierz
- {
- public:
- MacierzWewy (const int k, const int w) : Macierz (k, w)
- {
- }
- void Wprowadz()
- {
- float temp;
- for (int i=0;i<kolumny;i++)
- {
- for (int j=0;j<wiersze;j++)
- {
- printf ("tab[%d][%d] - ",i,j);
- scanf ("%f", & nxm[i][j]);
- }
- }
- }
- const void Wyswietl() const
- {
- for (int i=0;i<kolumny;i++)
- {
- for (int j=0;j<wiersze;j++)
- {
- printf ("\ntab[%d][%d] - %.2f",i,j, nxm[i][j]);
- }
- }
- }
- };
- class Macierz2x2 : public MacierzWewy
- {
- public:
- Macierz2x2 (): MacierzWewy (2, 2)
- {
- }
- const float Wyznacznik() const
- {
- return ( ( nxm[0][0] * nxm[1][1] ) - ( nxm [0][1] * nxm [1][0] ) );
- }
- const void Wyswietl ()
- {
- MacierzWewy::Wyswietl();
- printf ("\nWyznacznik - %.2f", Wyznacznik() );
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- Macierz mac(6,6);
- mac.Wiersze();
- mac.Kolumny();
- mac.Ustaw(2,3,55.5);
- MacierzWewy wew (4,4);
- wew.Ustaw(3,3,15.67);
- wew.Wprowadz();
- wew.Wyswietl();
- Macierz2x2 mala;
- mala.Ustaw(1,1,1);
- mala.Ustaw(0,1,2);
- mala.Ustaw(0,0,3);
- mala.Ustaw(1,0,4);
- printf ("\nWyznacznik - %.10f\n", mala.Wyznacznik());
- mala.Wyswietl();
- _getch();
- return 0;
- }
Advertisement