Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. class Pravokotnik {
  7. int visina, dolzina;
  8. public:
  9. Pravokotnik();
  10. Pravokotnik(int a);
  11. Pravokotnik(int a, int b);
  12. int ploscina () {return dolzina*visina;}
  13. int obseg () {return 2*dolzina+2*visina;}
  14. int diagonala () {return sqrt(dolzina*dolzina+visina*visina);}
  15. };
  16.  
  17. Pravokotnik::Pravokotnik(){
  18. this->visina=1;
  19. this->dolzina=1;
  20. }
  21.  
  22. Pravokotnik::Pravokotnik(int a){
  23. this->visina=a;
  24. this->dolzina=a;
  25. }
  26.  
  27. Pravokotnik::Pravokotnik(int a, int b){
  28. this->visina=a;
  29. this->dolzina=b;
  30.  
  31. }
  32.  
  33. int main () {
  34. double x,y,i;
  35. cout<<"Podaj dimezijo za 2 pravokotnik"<<endl;
  36. cin>>i;
  37. cout<<"Podaj dimeziji za 3 pravokotnik"<<endl;
  38. cin>>x;
  39. cin>>y;
  40. Pravokotnik ena();
  41. Pravokotnik dva(i);
  42. Pravokotnik tri(x,y);
  43.  
  44.  
  45.  
  46. cout<<"Pravokotnik 2"<<endl;
  47. cout << "Ploscina: " << dva.ploscina() << endl;
  48. cout << "Obseg: " << dva.obseg() << endl;
  49. cout << "Diagonala: " << dva.diagonala() << endl;
  50. cout<<endl;
  51. cout<<"Pravokotnik 3"<<endl;
  52. cout << "Ploscina: " << tri.ploscina() << endl;
  53. cout << "Obseg: " << tri.obseg() << endl;
  54. cout << "Diagonala: " << tri.diagonala() << endl;
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement