Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class domino
  4. {
  5. private:
  6. int numer_lewy,numer_prawy,dlugosc;
  7. public:
  8. domino(int a=6,int b=0,int c=1)
  9. {
  10. numer_lewy=a;
  11. numer_prawy=b;
  12. dlugosc=c;
  13. }
  14. void wyswietl()
  15. {
  16. cout<<"| "<<numer_lewy<<" ( dlugosc= "<<dlugosc<<" ) "<<numer_prawy<<" |"<<endl;
  17. }
  18. bool mozliwy(domino* a, domino* b)
  19. {
  20. if(a->numer_lewy==b->numer_lewy || a->numer_lewy==b->numer_prawy || a->numer_prawy==b->numer_lewy || a->numer_prawy==b->numer_prawy) return 1;
  21. else return 0;
  22. }
  23. static domino dodaj(domino &a, domino &b, int &weryfikacja)
  24. {
  25. domino d5;
  26. if(weryfikacja==1)
  27. {
  28. if(a.numer_lewy == b.numer_lewy)
  29. {
  30. int temp=a.numer_prawy;
  31. a.numer_lewy=a.numer_prawy;
  32. a.numer_prawy=temp;
  33. d5.numer_lewy=a.numer_lewy;
  34. d5.numer_prawy=b.numer_prawy;
  35. d5.dlugosc += 1;
  36. return d5;
  37. }
  38. if(a.numer_lewy == b.numer_prawy)
  39. {
  40. int temp=b.numer_prawy;
  41. b.numer_lewy=b.numer_prawy;
  42. b.numer_prawy=b.numer_lewy;
  43. d5.numer_lewy=a.numer_lewy;
  44. d5.numer_prawy=b.numer_prawy;
  45. d5.dlugosc +=1;
  46. return d5;
  47. }
  48. if(a.numer_prawy==b.numer_lewy)
  49. {
  50. d5.numer_lewy=a.numer_lewy;
  51. d5.numer_prawy=a.numer_prawy;
  52. d5.dlugosc +=1;
  53. return d5;
  54. }
  55. if(a.numer_prawy==b.numer_prawy)
  56. {
  57. int temp=b.numer_lewy;
  58. b.numer_lewy=b.numer_prawy;
  59. b.numer_prawy=b.numer_lewy;
  60. d5.numer_lewy=a.numer_lewy;
  61. d5.numer_prawy=b.numer_prawy;
  62. d5.dlugosc +=1;
  63. return d5;
  64. }
  65. }
  66. else {cout<<"\nDodawanie nie jest mozliwe!"<<endl;}
  67. }
  68. };
  69.  
  70.  
  71. int main()
  72. {
  73. domino d1(0,6,1),d2(1,6,1),d3(3,2,1),d4;
  74. d1.wyswietl();
  75. d2.wyswietl();
  76. d3.wyswietl();
  77. bool m12=d1.mozliwy(&d1,&d2);
  78. bool m23=d1.mozliwy(&d2,&d3);
  79. cout<<"\nMozliwy dla d1||d2 (odpowiednio 0 - Nie, 1- Tak )= "<<d1.mozliwy(&d1,&d2);
  80. cout<<"\nMozliwy dla d2||d3 (odpowiednio 0 - Nie, 1- Tak )= "<<d1.mozliwy(&d2,&d3);
  81. d4.dodaj(d1,d2,m12);
  82.  
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement