Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. class Postachalnik {
  4. char* country;
  5. char* name;
  6. char* phone;
  7. public:
  8. Postachalnik();
  9. Postachalnik(char*, char*, char*);
  10. Postachalnik(Postachalnik&);
  11. ~Postachalnik();
  12. char* GetCountry() { return country; };
  13. char* GetName() { return name; };
  14. char* GetPhone() { return phone; };
  15. void PrintFull();
  16. void PrintPart();
  17. Postachalnik& SetCountry(char*);
  18. Postachalnik& SetName(char*);
  19. Postachalnik& SetPhone(char*);
  20. };
  21.  
  22. Postachalnik::Postachalnik() {
  23. country = new char [11];
  24. strcpy(country, "no country");
  25. name = new char[8];
  26. strcpy(name, "no name");
  27. phone = new char[9];
  28. strcpy(phone, "no phone");
  29. }
  30.  
  31. Postachalnik::Postachalnik(char* CountryToAdd, char* NameToAdd, char* PhoneToAdd){
  32. name = new char[strlen(NameToAdd) + 1];
  33. strcpy(name, NameToAdd);
  34. country = new char[strlen(CountryToAdd) + 1];
  35. strcpy(country, CountryToAdd);
  36. phone = new char[strlen(PhoneToAdd) + 1];
  37. strcpy(phone, PhoneToAdd);
  38. }
  39.  
  40. Postachalnik::Postachalnik(Postachalnik& a) {
  41. country = new char[strlen(a.country) + 1];
  42. name = new char[strlen(a.name) + 1];
  43. phone = new char[strlen(a.phone) + 1];
  44. strcpy(country, a.country);
  45. strcpy(name, a.name);
  46. strcpy(phone, a.phone);
  47. }
  48.  
  49. Postachalnik::~Postachalnik() {
  50. delete name;
  51. delete country;
  52. delete phone;
  53. }
  54.  
  55. void Postachalnik::PrintFull() {
  56. std::cout << name << '\t' << country << '\t' << phone << '\n';
  57. }
  58.  
  59. void Postachalnik::PrintPart() {
  60. std::cout << name << '\n';
  61. }
  62.  
  63. Postachalnik& Postachalnik::SetCountry(char* CountryToAdd) {
  64. delete country;
  65. country = new char[strlen(CountryToAdd) + 1];
  66. strcpy(country, CountryToAdd);
  67. return *this;
  68. }
  69.  
  70. Postachalnik& Postachalnik::SetName(char* NameToAdd) {
  71. delete name;
  72. name = new char[strlen(NameToAdd) + 1];
  73. strcpy(name, NameToAdd);
  74. return *this;
  75. }
  76.  
  77. Postachalnik& Postachalnik::SetPhone(char* PhoneToAdd) {
  78. delete phone;
  79. phone = new char[strlen(PhoneToAdd) + 1];
  80. strcpy(phone, PhoneToAdd);
  81. return *this;
  82. }
  83.  
  84. class Product {
  85. Postachalnik obj;
  86. char* product;
  87. int count;
  88. float price;
  89. public:
  90. Product();
  91. Product(char*, int, float, Postachalnik&);
  92. Product(Product&);
  93. ~Product();
  94. Product& SetPostachalnik(Postachalnik&);
  95. Product& SetProduct(char*);
  96. Product& SetCount(int);
  97. Product& SetPrice(float);
  98. Postachalnik GetObject();
  99. char* GetProduct();
  100. int GetCount();
  101. float GetPrice();
  102. void PrintFull();
  103. };
  104. Product::Product() {
  105. product = new char[8];
  106. strcpy(product, "no name");
  107. count = 0;
  108. price = 0;
  109. Postachalnik firma;
  110. }
  111. Product::Product(char* NameToAdd, int CounttoAdd, float PriceToAdd, Postachalnik& ObjectToAdd) {
  112. product = new char[strlen(NameToAdd) + 1];
  113. strcpy(product, NameToAdd);
  114. count = CounttoAdd;
  115. price = PriceToAdd;
  116. obj = ObjectToAdd;
  117. }
  118. Product::Product(Product& a) {
  119. product = new char[strlen(a.product) + 1];
  120. count = a.count;
  121. price = a.price;
  122. obj = a.obj;
  123. }
  124. Product::~Product() {
  125. delete product;
  126. obj.~Postachalnik();
  127. }
  128. Postachalnik Product::GetObject() {
  129. return obj;
  130. }
  131. int Product::GetCount(){
  132. return count;
  133. }
  134. char* Product::GetProduct(){
  135. return product;
  136. }
  137. float Product::GetPrice() {
  138. return price;
  139. }
  140. void Product::PrintFull() {
  141. std::cout << product << '\t' << count << '\t' << price << '\t';
  142. obj.PrintFull();
  143. }
  144. int main()
  145. {
  146. char COUNTRY[20];
  147. char NAME[20];
  148. char PHONE[20];
  149. Postachalnik Obj1;
  150. std::cout << "Enter Postachalnik as Country,Name,Phone";
  151. std::cin >> COUNTRY;
  152. std::cin >> NAME;
  153. std::cin >> PHONE;
  154. Postachalnik Obj2(COUNTRY, NAME, PHONE);
  155. Postachalnik Obj3 = Obj2;
  156. Obj1.PrintFull();
  157. Obj2.PrintFull();
  158. Obj3.PrintFull();
  159. Obj1.SetName(COUNTRY).SetCountry(NAME).SetPhone(PHONE);
  160. std::cout << "Objects after changes:" << '\n';
  161. Obj1.PrintFull();
  162. Obj2.PrintFull();
  163. Obj3.PrintFull();
  164. Obj1.SetCountry(PHONE);
  165. Obj2.SetName(COUNTRY);
  166. Obj3.SetPhone(NAME);
  167. Obj1.PrintFull();
  168. Obj2.PrintFull();
  169. Obj3.PrintFull();
  170. Product object1;
  171. Product object2(NAME, 10, 3.5, Obj3);
  172. object1.PrintFull();
  173. object2.PrintFull();
  174.  
  175. object2.GetObject().PrintFull();
  176. return 0;
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement