Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class domino
- {
- private:
- int numer_lewy,numer_prawy,dlugosc;
- public:
- domino(int a=6,int b=0,int c=1)
- {
- numer_lewy=a;
- numer_prawy=b;
- dlugosc=c;
- }
- void wyswietl()
- {
- cout<<"| "<<numer_lewy<<" ( dlugosc= "<<dlugosc<<" ) "<<numer_prawy<<" |"<<endl;
- }
- bool mozliwy(domino* a, domino* b)
- {
- 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;
- else return 0;
- }
- static domino dodaj(domino &a, domino &b, int &weryfikacja)
- {
- domino d5;
- if(weryfikacja==1)
- {
- if(a.numer_lewy == b.numer_lewy)
- {
- int temp=a.numer_prawy;
- a.numer_lewy=a.numer_prawy;
- a.numer_prawy=temp;
- d5.numer_lewy=a.numer_lewy;
- d5.numer_prawy=b.numer_prawy;
- d5.dlugosc += 1;
- return d5;
- }
- if(a.numer_lewy == b.numer_prawy)
- {
- int temp=b.numer_prawy;
- b.numer_lewy=b.numer_prawy;
- b.numer_prawy=b.numer_lewy;
- d5.numer_lewy=a.numer_lewy;
- d5.numer_prawy=b.numer_prawy;
- d5.dlugosc +=1;
- return d5;
- }
- if(a.numer_prawy==b.numer_lewy)
- {
- d5.numer_lewy=a.numer_lewy;
- d5.numer_prawy=a.numer_prawy;
- d5.dlugosc +=1;
- return d5;
- }
- if(a.numer_prawy==b.numer_prawy)
- {
- int temp=b.numer_lewy;
- b.numer_lewy=b.numer_prawy;
- b.numer_prawy=b.numer_lewy;
- d5.numer_lewy=a.numer_lewy;
- d5.numer_prawy=b.numer_prawy;
- d5.dlugosc +=1;
- return d5;
- }
- }
- else {cout<<"\nDodawanie nie jest mozliwe!"<<endl;}
- }
- };
- int main()
- {
- domino d1(0,6,1),d2(1,6,1),d3(3,2,1),d4;
- d1.wyswietl();
- d2.wyswietl();
- d3.wyswietl();
- bool m12=d1.mozliwy(&d1,&d2);
- bool m23=d1.mozliwy(&d2,&d3);
- cout<<"\nMozliwy dla d1||d2 (odpowiednio 0 - Nie, 1- Tak )= "<<d1.mozliwy(&d1,&d2);
- cout<<"\nMozliwy dla d2||d3 (odpowiednio 0 - Nie, 1- Tak )= "<<d1.mozliwy(&d2,&d3);
- d4.dodaj(d1,d2,m12);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement