Advertisement
sellmmaahh

zsr-10-zad5

May 17th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include<stdexcept>
  3. #include <cmath>
  4.  
  5. class Robot {
  6.     double x, y, ugao;
  7.  
  8. public:
  9.     Robot () {Robot::x=0; Robot::y=0; Robot::ugao=0;};
  10.    explicit Robot (double ugao) {Robot::x=0; Robot::y=0; Robot::ugao=ugao;};
  11.    Robot(double x, double y, double ugao) {Robot::x=x; Robot::y=y; Robot::ugao=ugao;};
  12.  
  13. void IdiNaprijed(double pomak);
  14. void IdiNazad(double pomak);
  15. void OkreniSeNaijevo(double ugao) {Robot::ugao+=ugao;};
  16. void OkreniSeNadesno(double ugao) {Robot::ugao-=ugao;};
  17. double DajPozicijuX() const {return Robot::x;};
  18. double DajPozicijuY() const {return Robot::y; };
  19. double DajOrjent9aciju() const {return Robot::ugao; };
  20. void Ispisi() const;
  21. };
  22.  
  23. void Robot::IdiNaprijed(double pomak) {
  24. Robot::x+=pomak*cos(Robot::ugao);
  25. Robot::y+=pomak*sin(Robot::ugao);
  26. }
  27. void Robot::IdiNazad(double pomak) {
  28. Robot::x-=pomak*cos(Robot::ugao+180);
  29. Robot::y-=pomak*sin(Robot::ugao+180);
  30. }
  31.  
  32. void Robot::Ispisi () const {
  33. std::cout<<"Robot se nalazi na poziciji ("<<x<<","<<y<<") i gleda pod uglom "<<ugao<<" stepeni u odnosu na x osu.";
  34. }
  35.  
  36. int main () {
  37. Robot r1(3,5,30);
  38.  
  39. r1.IdiNaprijed (3);
  40. r1.Ispisi();
  41. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement