Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Kolo{
  6. private:
  7. float promien;
  8. int kolor;
  9.  
  10. public:
  11. Kolo();
  12. Kolo(float, int);
  13. double pole()const;
  14. void ustawPromien();
  15. void ustawKolor();
  16. bool operator==(const Kolo &ko)const;
  17.  
  18. };
  19.  
  20. Kolo::Kolo(){
  21. promien = 0;
  22. kolor = 0;
  23. }
  24. Kolo::Kolo(float n, int c){
  25. promien = n;
  26. kolor = c;
  27. }
  28.  
  29. double Kolo::pole()const{
  30. if(promien>0)
  31. return 3.14*(promien*promien);
  32. else
  33. return -1;
  34. }
  35.  
  36. void Kolo::ustawPromien(){
  37. do{
  38. cout << "Wprowadz promien kola > 0 : " << endl;
  39. cin >> promien;
  40. }while(promien<0);
  41. }
  42.  
  43. void Kolo::ustawKolor(){
  44. cout << "Wprowadz kolor kola: " << endl;
  45. cin >> kolor;
  46. }
  47.  
  48. bool Kolo::operator==(const Kolo &ko)const{
  49. if(ko.kolor == kolor && ko.promien == promien)
  50. return 1;
  51. else
  52. return 0;
  53. }
  54.  
  55.  
  56. int main(){
  57. Kolo K1;
  58. Kolo K2(9.5, 10555);
  59.  
  60. K1.ustawPromien();
  61. K1.ustawKolor();
  62.  
  63. cout << "Pole wynosi: " << K1.pole() << endl;
  64. cout << "Pole wynosi: " << K2.pole() << endl;
  65. cout << "K1 == K2? " << K1 == K2 << endl;
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement