All pastes #2129905 Raw Edit

mesx

public cpp v1 · immutable
#2129905 ·published 2012-03-19 10:58 UTC
rendered paste body
#include <stdio.h>#include <math.h>#include <iostream>using namespace std;#define N 3class Vector3f{    public:        float polje[N];        Vector3f(){            for( int i=0; i<3; i++){                polje[i]=0;            }        }        Vector3f(float, float, float);        Vector3f(float a[3]);        Vector3f(const Vector3f &);        Vector3f& operator = (const Vector3f &temp){            if(this != &temp){                this->polje[0] = temp.polje[0];                this->polje[1] = temp.polje[1];                this->polje[2] = temp.polje[2];            }            return *this;        }        //sale = sale + tena        //sale += tena        Vector3f& operator += (const Vector3f &temp){            this->polje[0] = this->polje[0] + temp.polje[0];            this->polje[1] = this->polje[1] + temp.polje[1];            this->polje[2] = this->polje[2] + temp.polje[2];            return *this;        }        Vector3f& operator -= (const Vector3f &);        Vector3f& operator *= (float temp){            this->polje[0] = this->polje[0] * temp;            return *this;        }        Vector3f& operator + (const Vector3f &temp) const{            // this upucuje na lijevu stranu operatora kojeg preopterecujemo            // npr c= a + b, ako preopt +, this upucuje na a;            Vector3f rez = *this;   // kopiramo a u rez;            rez += temp;            // koristimo vec preoptereceni operator +=             return rez;        }        bool operator== (const Vector3f &temp) const{            bool nest;            if ( this->polje[0] == temp.polje[0] &&                     this->polje[1] == temp.polje[1] &&                    this->polje[2] == temp.polje[2] ) nest = 1;            else nest = 0;            return nest;        }        bool operator !=(const Vector3f &temp) const{            bool nest;            if (*this == temp) nest=0;            else nest=1;            return nest;        }        float& operator[](unsigned int temp){             return this->polje[temp];        }        Vector3f& vec_produkt(Vector3f& temp){            Vector3f rez;            rez.polje[0] = this->polje[1] * temp.polje[2] - temp.polje[1] * this->polje[2];            rez.polje[1] = this->polje[0] * temp.polje[2] - temp.polje[0] * this->polje[2];            rez.polje[2] = this->polje[0] * temp.polje[1] - temp.polje[0] * this->polje[1];            rez.ispisi();            return rez;        }        void ispisi();};class Matrix3f{    public:        Vector3f matrica[N];        float a[N][N]; // prva dimenzija matrice        float b[N][N]; // druga        float c[N][N]; // treca        Matrix3f(){            for(int i=0; i<N; i++){                for( int j=0; j<N; j++){                    a[i][j] = 0;                    b[i][j] = 0;                    c[i][j] = 0;                }            }        }        Matrix3f(float polje2D[][N]){            // treba predat 2D polje tipa {{1,1,1},{2,2,2},{3,3,3}}            for(int i=0; i<N; i++){                for( int j=0; j<N; j++){                    a[i][j] = polje2D[i][j];                    b[i][j] = polje2D[i][j];                    c[i][j] = polje2D[i][j];                }            }        }        Matrix3f& operator = (const Matrix3f& temp){            for(int i=0; i<N; i++){                for( int j=0; j<N; j++){                    this->a[i][j] = temp.a[i][j];                    this->b[i][j] = temp.b[i][j];                    this->c[i][j] = temp.c[i][j];                }            }            return *this;        }        Matrix3f& operator += (const Matrix3f& temp){                for(int i=0; i<N; i++){                    for( int j=0; j<N; j++){                        this->a[i][j] = this->a[i][j] + temp.a[i][j];                        this->b[i][j] = this->b[i][j] + temp.b[i][j];                        this->c[i][j] = this->c[i][j] + temp.c[i][j];                    }                }                return *this;        }        void ispisi(){            cout << "A dimenzija: " << endl;            for(int i=0; i<N; i++){                for( int j=0; j<N; j++){                    cout << a[i][j] << " ";                }                cout << endl;            }            cout << "B dimenzija: " << endl;            for(int i=0; i<N; i++){                for( int j=0; j<N; j++){                    cout << b[i][j] << " ";                }                cout << endl;            }            cout << "C dimenzija: " << endl;            for(int i=0; i<N; i++){                for( int j=0; j<N; j++){                    cout << c[i][j] << " ";                }                cout << endl;            }        }};int main(){    Vector3f prvi;    prvi.ispisi();    Vector3f drugi(1,2,3);    drugi.ispisi();    Vector3f treci(prvi);    treci.ispisi();    float b[3] = {7,8,9};    Vector3f tena(b);    tena.ispisi();    Vector3f sale(2,3,4);    sale.ispisi();    sale += tena;    sale *= 5;    cout << "sale " << endl;    sale.ispisi();    Vector3f beba;    beba = sale + tena;    beba.ispisi();    beba = sale;    if (beba != sale) cout << "da" << endl;    else cout << "ne " << endl;    cout << beba[2] << endl;    Vector3f jedan(1,1,1);    Vector3f produkt;    produkt = jedan.vec_produkt(drugi);    produkt.ispisi();    Matrix3f pero;    pero.ispisi();    float s[3][3] = { {1,2,3},{4,5,6},{7,8,9}};    Matrix3f perica(s);    perica.ispisi();    pero = s;    pero.ispisi();    pero +=s;    pero.ispisi();    return 0;}void Vector3f::ispisi(){    cout << "Vector3f: " << endl;    for( int i=0; i<3; i++){        cout << polje[i] << "\t";    }    cout << endl;}Vector3f::Vector3f(float x,float y,float z){    polje[0]=x;    polje[1]=y;    polje[2]=z;}Vector3f::Vector3f(const Vector3f &temp){    for( int i=0; i<3; i++){        polje[i] = temp.polje[i];    }}Vector3f::Vector3f(float a[3]){    for( int i=0; i<3; i++) polje[i]=a[i];}