• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 16th, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <stdexcept>
3. #include <cmath>
4.
5. using namespace std;
6. class Vektor3d
7. {
8.     int koordinate [3];
9.     mutable int broj_ispisa=0;
10.
11. public:
12.     void Postavi(double x,double y,double z)
13.     {
14.         Vektor3d::koordinate[0]=x;
15.         Vektor3d::koordinate[1]=y;
16.         Vektor3d::koordinate[2]=z;
17.     }
18.     void Ocitaj (double &x,double &y,double &z)
19.     {
20.         x=Vektor3d::koordinate[0];
21.         y=Vektor3d::koordinate[1];
22.         z=Vektor3d::koordinate[2];
23.     }
24.     void Ispis() const
25.     {
26.         std::cout<<"{"<<koordinate[0]<<","<<koordinate[1]<<","<<koordinate[2]<<"}";
27.         broj_ispisa++;
28.     }
29.     double DajX() const
30.     {
31.         return koordinate[0];
32.     }
33.     double DajY() const
34.     {
35.         return koordinate[1];
36.     }
37.     double DajZ() const
38.     {
39.         return koordinate[2];
40.     }
41.     double DajDuzinu() const
42.     {
43.         return sqrt(koordinate[0]*koordinate[0]+koordinate[1]*koordinate[1]+koordinate[2]*koordinate[3]);
44.     }
45.     Vektor3d &PomnoziSkalarom(double s)
46.     {
47.         koordinate[0]*=s;
48.         koordinate[1]*=s;
49.         koordinate[2]*=s;
50.         return *this;
51.     }
52.     Vektor3d &SaberiSa (const Vektor3d &v)
53.     {
54.         koordinate[0]+=v.koordinate[0];
55.         koordinate[1]+=v.koordinate[1];
56.         koordinate[2]+=v.koordinate[2];
57.         return *this;
58.     }
59.     friend Vektor3d ZbirVektora(const Vektor3d &v1, const Vektor3d &v2);
60.     Vektor3d PostaviX (int x)
61.     {
62.         Vektor3d::koordinate[0]=x;
63.         return *this;
64.     }
65.     Vektor3d PostaviY (int y)
66.     {
67.         Vektor3d::koordinate[1]=y;
68.         return *this;
69.     }
70.     Vektor3d PostaviZ (int z)
71.     {
72.         Vektor3d::koordinate[2]=z;
73.         return *this;
74.     }
75.     int BrojIspisa () {
76.     return broj_ispisa;
77.     }
78. };
79. Vektor3d ZbirVektora (const Vektor3d &v1, const Vektor3d &v2)
80. {
81.     Vektor3d v3;
82.     v3.koordinate[0]=v1.koordinate[0]+v2.koordinate[0];
83.     v3.koordinate[1]=v1.koordinate[1]+v2.koordinate[1];
84.     v3.koordinate[2]=v1.koordinate[2]+v2.koordinate[2];
85.     return v3;
86. }
87.
88.
89. int main()
90. {
91.     Vektor3d v1,v2,v3;
92.     v1.Postavi(1,2,3);
93.     v2.Postavi(1,2,3);
94.     v2.Postavi(1,2,3);
95.     v1.Ispis();
96.     v1.SaberiSa(v2).Ispis();
97.     Vektor3d v4;
98.     v4.PostaviX(1);
99.     v4.PostaviY(1);
100.     v4.PostaviZ(1);
101.     int a=v1.DajX();
102.     int b=v2.DajY();
103.     int c=v1.DajZ();
104.     Vektor3d d=ZbirVektora(v1,v2);
105.     cout<<"Vektor se ispisao: "<<v4.BrojIspisa();
106.
107.     return 0;
108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top