Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdexcept>
- #include <cstring>
- #include <cmath>
- #include <vector>
- #include "TestCurenja.h"
- using namespace std;
- class Vektor3d {
- double x,y,z;
- public:
- Vektor3d () {x=0; y=0; z=0;}
- Vektor3d (double x, double y, double z) {Vektor3d::x=x; Vektor3d::y=y; Vektor3d::z=z; }
- void PostaviX(double x) {Vektor3d::x=x; }
- void PostaviY(double y) {Vektor3d::y=y; }
- void PostaviZ(double z) {Vektor3d::z=z; }
- void Postavi(double x, double y, double z) {
- Vektor3d::x=x; Vektor3d::y=y; Vektor3d::z=z;
- }
- void Ocitaj (double &x, double &y, double &z) const {
- x=Vektor3d::x; y=Vektor3d::y; z=Vektor3d::z;
- }
- double DajX() const {return x;}
- double DajY() const {return y;}
- double DajZ() const {return z;}
- double DajDuzinu() const {return sqrt(x*x+y*y+z*z); }
- friend ostream &operator <<(ostream &tok, const Vektor3d &v) {
- tok<<"{"<<v.x<<","<<v.y<<","<<v.z<<"}";
- return tok;
- }
- friend Vektor3d &operator*= (Vektor3d &v1, int a) {
- v1.x*=a; v1.y*=a; v1.z*=a;
- return v1;
- }
- friend Vektor3d &operator+=(Vektor3d &v1, const Vektor3d v2) {
- v1.x+=v2.x; v1.y+=v2.y; v1.z+=v2.z;
- return v1;
- }
- };
- int main () {
- Vektor3d v1, v2;
- v1.Postavi(3,4,5);
- v2.Postavi(2,1,1);
- cout<<"Duzina prvog vektora: "<<v1.DajDuzinu()<<endl;
- cout<<"Duzina drugog vektora: "<<v2.DajDuzinu()<<endl;
- v1+=v2;
- cout<<v1;
- cout<<endl;
- v2*=3;
- cout<<v2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement