Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Hubert Stawicki */
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <cstdlib>
- class Macierz{
- private:
- int kolumny,wiersze;
- double **tab;
- void tworze_tab(int x,int y);
- public:
- Macierz();
- Macierz(int x,int y);
- Macierz(Macierz& macierz);
- void set(int x,int y, double wart);
- void set_wiersze(int x)
- {
- wiersze=x;
- }
- void set_kolumny(int y)
- {
- kolumny=y;
- }
- double get(int x,int y);
- int get_wiersze()
- {
- return wiersze;
- }
- int get_kolumny()
- {
- return kolumny;
- }
- };
- void Macierz::tworze_tab(int wiersze, int kolumny)
- {
- int i,j;
- tab = (double **)malloc(wiersze*sizeof(double *));
- for(i=0;i<wiersze;i++)
- {
- tab[i] = (double *)malloc( kolumny*sizeof(double ) );
- }
- }
- Macierz::Macierz()
- {
- tworze_tab(1,1);
- }
- Macierz::Macierz(int wiersze,int kolumny)
- {
- tworze_tab(wiersze,kolumny);
- }
- Macierz::Macierz(Macierz& macierz)
- {
- wiersze = macierz.get_wiersze();
- kolumny = macierz.get_kolumny();
- int i,j;
- tworze_tab(macierz.wiersze,macierz.kolumny);
- for(i=0; i<macierz.wiersze; i++)
- {
- //tab[i] = (double *)malloc(kolumny*sizeof(double *));
- for(j=0; j<macierz.kolumny; j++)
- {
- tab[i][j]=macierz.tab[i][j];
- printf("%.1g ",tab[i][j]);
- }
- printf("\n");
- }
- /*tworze_tab(macierz.wiersze, macierz.kolumny);
- memcpy(tab, macierz.tab, macierz.wiersze*sizeof(double*));
- for(int i=0; i<macierz.kolumny; i++)
- memcpy(tab[i], macierz.tab[i], macierz.kolumny*sizeof(double));*/
- }
- void Macierz::set(int x,int y, double wart)
- {
- if(x<wiersze && y<kolumny)
- tab[x][y]=wart;
- else
- printf("ZLE WSPOLRZEDNE\n");
- }
- double Macierz::get(int i,int j)
- {
- if(i<wiersze && j<kolumny)
- return tab[i][j];
- else
- printf("ZLE WSPOLRZEDNE\n");
- }
- int main()
- {
- int i,j;
- Macierz cos(3,3);
- cos.set_wiersze(3);
- cos.set_kolumny(3);
- /* for(i=0;i<3;i++)
- for(j=0;j<3;j++)
- m1->set(i, j, rand()%3-1);
- for(i=0;i<m1->get_wiersze();i++)
- {
- for(j=0;j<m1->get_kolumny();j++)
- printf("%.1g",m1->get(i,j));
- printf("\n");
- }*/
- for(i=0;i<cos.get_wiersze();i++)
- for(j=0;j<cos.get_kolumny();j++)
- cos.set(i, j, rand()%3-1);
- for(i=0;i<cos.get_wiersze();i++)
- {
- for(j=0;j<cos.get_kolumny();j++)
- {
- printf("%.1lf ",cos.get(i,j));
- }
- printf("\n");
- }
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- cos.set(i,j,5);
- }
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- printf("%.1lf ",cos.get(i,j));
- }
- printf("\n");
- }
- Macierz kopiuj(cos);
- for(i=0;i<kopiuj.get_wiersze();i++)
- {
- for(j=0;j<kopiuj.get_kolumny();j++)
- {
- printf("%.1lf ",kopiuj.get(i,j));
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement