Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///prvi
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- class Die
- {
- private:
- int value;
- public:
- Die();
- Die(int x);
- void set(int x)
- {
- value = x;
- }
- int access(void)
- {
- return value;
- }
- int roll(void)
- {
- return rand() % 6 + 1;
- }
- };
- void jamb(Die polje[])
- {
- int br = 1 , i;
- for (i = 0; i < 5; i++)
- {
- if (polje[i].access() == polje[i + 1].access())
- br++;
- }
- if (br == 5)
- cout << "jamb je bacen"<<endl;
- else
- cout << "nije bacen"<<endl;
- }
- Die::Die()
- {
- value = 0;
- }
- Die::Die(int x)
- {
- value = x;
- }
- int main()
- {
- int i;
- Die polje[5];
- for (i = 0; i<5; i++)
- {
- polje[i].set(polje[i].roll());
- }
- for (i = 0; i < 5; i++)
- {
- cout << polje[i].access()<<endl;
- }
- jamb(polje);
- return 0;
- }
- ///drugi
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Complex
- {
- friend Complex sum(Complex &x, Complex &y)
- {
- Complex z(x.real_part + y.real_part, x.imaginary_part + y.imaginary_part);
- return z;
- }
- private:
- float real_part;
- float imaginary_part;
- public:
- Complex();
- Complex(float x, float y);
- float access_real()
- {
- return real_part;
- }
- float access_imaginary()
- {
- return imaginary_part;
- }
- float abs(void)
- {
- return sqrt(pow(real_part,2) + pow(imaginary_part,2));
- }
- };
- Complex::Complex()
- {
- real_part = 0;
- imaginary_part = 0;
- }
- Complex::Complex(float x,float y)
- {
- real_part = x;
- imaginary_part = y;
- }
- int main()
- {
- Complex z1(2,3);
- Complex z2(4,-2);
- Complex z3;
- z3 = sum(z1, z2);
- cout <<z3.access_real() << endl;
- cout << z3.access_imaginary() << endl;
- cout << z3.abs() << endl;
- return 0;
- }
- //treci
- #include <iostream>
- using namespace std;
- class Point2D
- {
- private:
- int xCor;
- int yCor;
- public:
- Point2D();
- Point2D(int x, int y);
- int accessX(void)
- {
- return xCor;
- }
- int accessY(void)
- {
- return yCor;
- }
- void setCor(int x, int y)
- {
- xCor = x;
- yCor = y;
- }
- };
- class Line
- {
- private:
- Point2D dot1;
- Point2D dot2;
- public:
- Line(Point2D T1, Point2D T2);
- void changeDot1(int x, int y)
- {
- dot1.setCor(x, y);
- }
- void changeDot2(int x, int y)
- {
- dot2.setCor(x, y);
- }
- void ispis(void)
- {
- cout << "T1(" << dot1.accessX() <<","<< dot1.accessY() << ")" << endl;
- cout << "T2(" << dot2.accessX() <<"," << dot2.accessY() << ")" << endl;
- }
- };
- Point2D::Point2D()
- {
- xCor = 1;
- yCor = 1;
- }
- Point2D::Point2D(int x, int y)
- {
- xCor = x;
- yCor = y;
- }
- Line::Line(Point2D T1, Point2D T2)
- {
- dot1 = T1;
- dot2 = T2;
- }
- int main()
- {
- Point2D Tocka1;
- Point2D Tocka2;
- Line pravac(Tocka1,Tocka2);
- pravac.ispis();
- pravac.changeDot1(2, 3);
- pravac.changeDot2(3, 4);
- pravac.ispis();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement