Advertisement
mostlabs

2.2/1

Dec 16th, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. class address {
  8.  
  9. private:
  10.  
  11. string country, region, district, locality, street, building;
  12.  
  13. int apartment, room;
  14.  
  15. public:
  16.  
  17. address();
  18.  
  19. address(const string&, const string, const string, const string, const string,
  20.  
  21. const string, int, int);
  22.  
  23. address(const address&);
  24.  
  25. ~address();
  26.  
  27. address& operator=(address a);
  28.  
  29. void setData();
  30.  
  31. friend bool operator == (const address&, const address&);
  32.  
  33. void print();
  34.  
  35. };
  36.  
  37. void address::setData() {
  38.  
  39. cout << "country=";
  40. cin >> this->country;
  41. cout << "region=";
  42. cin >> this->region;
  43. cout << "district=";
  44. cin >> this->district;
  45. cout << "locality=";
  46. cin >> this->locality;
  47. cout << "street=";
  48. cin >> this->street;
  49. cout << "building=";
  50. cin >> this->building;
  51.  
  52. cout << "apartment";
  53.  
  54. cin >> this->apartment;
  55.  
  56. cout << "room";
  57.  
  58. cin >> this->room;
  59.  
  60. }
  61.  
  62. address::address() {
  63.  
  64. country = "";
  65.  
  66. region = "";
  67.  
  68. district = "";
  69.  
  70. locality = "";
  71.  
  72. street = "";
  73.  
  74. building = "";
  75.  
  76. apartment = 0;
  77.  
  78. room = 0;
  79.  
  80. }
  81.  
  82. address::address(const string& country, const string region, const string district, const
  83.  
  84. string locality, const string street, const string building, int apartment, int room) {
  85.  
  86. this->country = country;
  87.  
  88. this->region = region;
  89.  
  90. this->district = district;
  91.  
  92. this->locality = locality;
  93.  
  94. this->street = street;
  95.  
  96. this->building = building;
  97.  
  98. this->apartment = apartment;
  99.  
  100. this->room = room;
  101.  
  102.  
  103. }
  104.  
  105. address::~address() {
  106.  
  107. }
  108.  
  109. address::address(const address& _address) {
  110.  
  111. country = _address.country;
  112.  
  113. region = _address.region;
  114.  
  115. district = _address.district;
  116.  
  117. locality = _address.locality;
  118.  
  119. street = _address.street;
  120.  
  121. building = _address.building;
  122.  
  123. apartment = _address.apartment;
  124.  
  125. room = _address.room;
  126.  
  127.  
  128. }
  129.  
  130. address& address::operator=(address a) {
  131.  
  132. this->country = a.country;
  133.  
  134. this->region = a.region;
  135.  
  136. this->district = a.district;
  137.  
  138. this->locality = a.locality;
  139.  
  140. this->street = a.street;
  141.  
  142. this->building = a.building;
  143.  
  144. this->apartment = a.apartment;
  145.  
  146. this->room = a.room;
  147.  
  148. return *this;
  149.  
  150. }
  151.  
  152. bool operator == (const address &d1,const address &d2) {
  153.  
  154. if (d1.country == d2.country && d1.region == d2.region && d1.district ==
  155.  
  156. d2.district && d1.locality == d2.locality && d1.street == d2.street && d1.building ==
  157.  
  158. d2.building && d1.apartment == d2.apartment && d1.room == d2.room)
  159.  
  160. {
  161. cout << true << endl;
  162. return true;
  163.  
  164. }
  165.  
  166. else
  167.  
  168. {
  169. cout << false << endl;
  170. return false;
  171.  
  172. }
  173.  
  174. }
  175.  
  176.  
  177. void address::print() {
  178.  
  179. cout << this->country << " " << this->region << " "<< this->district<< " " << this->locality << " "<< this->street << " " << this->building <<" "<< this->apartment << " " << this->room << endl;
  180.  
  181. }
  182.  
  183. int main() {
  184.  
  185. int n;
  186.  
  187. cout << "Enter the mas size: " << endl;
  188.  
  189. cin >> n;
  190.  
  191. address* mas = new address[n];
  192.  
  193. for (int i = 0; i < n; i++)
  194.  
  195. {
  196.  
  197. mas[i].setData();
  198.  
  199. }
  200. address r = mas[0];
  201.  
  202.  
  203. address q("Russia", "Kursk", "Kursk", "Center", "Alal", "Apartment", 2, 3);
  204. q.print();
  205. cout << endl;
  206.  
  207.  
  208. for (int i = 0; i < n; i++)
  209.  
  210. {
  211.  
  212. mas[i].print();
  213.  
  214. }
  215.  
  216. bool result = r == q;
  217.  
  218. delete[] mas;
  219.  
  220. system("pause");
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement