Guest User

Untitled

a guest
Nov 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. struct tocka
  6. {
  7. int x, y;
  8. };
  9. class mnoguagolnik
  10. {
  11. char *vid;
  12. int teminja;
  13. tocka *t;
  14. public:
  15. mnoguagolnik(char v[]="cetiriagolnik", int x=4)
  16. {
  17. vid=new char[strlen(v)+1];
  18. strcpy(vid, v);
  19. teminja=x;
  20. }
  21. mnoguagolnik(const mnoguagolnik &a)
  22. {
  23. vid=new char[strlen(a.vid)+1];
  24. strcpy(vid, a.vid);
  25. teminja=a.teminja;
  26. t=new tocka[a.teminja];
  27. for(int i=0; i<teminja; i++)
  28. {
  29. t[i]=a.t[i];
  30. }
  31. }
  32. ~mnoguagolnik()
  33. {
  34. delete[] vid;
  35. delete[] t;
  36. }
  37. void setVid(char *v)
  38. {
  39. strcpy(vid, v);
  40. }
  41. void setTeminja(int x)
  42. {
  43. teminja=x;
  44. delete[] t;
  45. t=new tocka[x];
  46. cout << "Vnesi gi teminjata na " << vid << "ot:" << endl;
  47. for(int i=0;i<x;i++)
  48. {
  49. cout << "T" << i+1 << endl;
  50. cout << "x: ";
  51. cin >> t[i].x;
  52. cout << "y: ";
  53. cin >> t[i].y;
  54. }
  55. }
  56. void setTeminja()
  57. {
  58. cout << "Vnesi gi teminjata na " << vid << "ot:" << endl;
  59. for(int i=0;i<teminja;i++)
  60. {
  61. cout << "T" << i+1 << endl;
  62. cout << "x: ";
  63. cin >> t[i].x;
  64. cout << "y: ";
  65. cin >> t[i].y;
  66. }
  67. }
  68. void setTocki(tocka *x, int n)
  69. {
  70. for(int i=0; i<n; i++)
  71. {
  72. t[i]=x[i];
  73. }
  74. }
  75. char const * getVid()
  76. {
  77. return vid;
  78. }
  79. int getTeminja()
  80. {
  81. return teminja;
  82. }
  83. tocka const * getTocki()
  84. {
  85. return t;
  86. }
  87. void pecati()
  88. {
  89. cout << vid << endl;;
  90. for(int i=0; i<teminja;i++)
  91. {
  92. cout << "T" << i << &#039;(&#039; << t[i].x << &#039;,&#039; << t[i].y << &#039;)&#039; << endl;
  93. }
  94. cout << endl;
  95. }
  96. mnoguagolnik & operator+=(const mnoguagolnik &a)
  97. {
  98. if(teminja!=a.teminja)
  99. {
  100. cout << "Dadenite mnoguagolnici nemozat da se soberat (ne se od ist vid)!";
  101. }
  102. else
  103. {
  104. for(int i=0;i<teminja;i++)
  105. {
  106. t[i].x+=a.t[i].x;
  107. t[i].y+=a.t[i].y;
  108. }
  109. }
  110. return *this;
  111. }
  112. mnoguagolnik & operator*(const mnoguagolnik &a);
  113. mnoguagolnik & operator=(const mnoguagolnik &a)
  114. {
  115. if(this==&a)
  116. return *this;
  117. vid=new char[strlen(a.vid)+1];
  118. strcpy(vid, a.vid);
  119. teminja=a.teminja;
  120. t=new tocka[a.teminja];
  121. for(int i=0; i<teminja; i++)
  122. {
  123. t[i]=a.t[i];
  124. }
  125. return *this;
  126. }
  127. } temp;
  128. mnoguagolnik & mnoguagolnik::operator*(const mnoguagolnik &a)
  129. {
  130. if(teminja!=a.teminja)
  131. {
  132. cout << "Dadenite mnoguagolnici nemozat da se pomnozat (ne se od ist vid)!";
  133. }
  134. else
  135. {
  136. temp=(*this);
  137. for(int i=0;i<teminja;i++)
  138. {
  139. temp.t[i].x=t[i].x*a.t[i].x;
  140. temp.t[i].y=t[i].y*a.t[i].y;
  141. }
  142. }
  143. return temp;
  144. }
  145. int main()
  146. {
  147. mnoguagolnik a;
  148. mnoguagolnik b;
  149. a.setTeminja();
  150. b.setTeminja();
  151. mnoguagolnik c;
  152. c=a*b;
  153. cout << "a*b=" << endl;
  154. c.pecati();
  155. }
Add Comment
Please, Sign In to add comment