Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstring>
  4. class Postachalnik {
  5. char* country;
  6. char* name;
  7. char* phone;
  8. public:
  9. Postachalnik();
  10. Postachalnik(char*, char*, char*);
  11. Postachalnik(Postachalnik&);
  12. ~Postachalnik();
  13. char* GetCountry() { return country; };
  14. char* GetName() { return name; };
  15. char* GetPhone() { return phone; };
  16. void PrintFull();
  17. void PrintPart();
  18. Postachalnik& SetCountry(char*);
  19. Postachalnik& SetName(char*);
  20. Postachalnik& SetPhone(char*);
  21. };
  22.  
  23. Postachalnik::Postachalnik() {
  24. country = new char [11];
  25. strcpy(country, "no country");
  26. name = new char[8];
  27. strcpy(name, "no name");
  28. phone = new char[9];
  29. strcpy(phone, "no phone");
  30. }
  31.  
  32. Postachalnik::Postachalnik(char* CountryToAdd, char* NameToAdd, char* PhoneToAdd){
  33. name = new char[strlen(NameToAdd) + 1];
  34. strcpy(name, NameToAdd);
  35. country = new char[strlen(CountryToAdd) + 1];
  36. strcpy(country, CountryToAdd);
  37. phone = new char[strlen(PhoneToAdd) + 1];
  38. strcpy(phone, PhoneToAdd);
  39. }
  40.  
  41. Postachalnik::Postachalnik(Postachalnik& a) {
  42. country = new char[strlen(a.country) + 1];
  43. name = new char[strlen(a.name) + 1];
  44. phone = new char[strlen(a.phone) + 1];
  45. strcpy(country, a.country);
  46. strcpy(name, a.name);
  47. strcpy(phone, a.phone);
  48. }
  49.  
  50. Postachalnik::~Postachalnik() {
  51. delete[] name;
  52. delete[] country;
  53. delete[] phone;
  54. }
  55.  
  56. void Postachalnik::PrintFull() {
  57. std::cout << name << '\t' << country << '\t' << phone << '\n';
  58. }
  59.  
  60. void Postachalnik::PrintPart() {
  61. std::cout << name << '\n';
  62. }
  63.  
  64. Postachalnik& Postachalnik::SetCountry(char* CountryToAdd) {
  65. if(country)
  66. delete[] country;
  67. country = new char[strlen(CountryToAdd) + 1];
  68. strcpy(country, CountryToAdd);
  69. return *this;
  70. }
  71.  
  72. Postachalnik& Postachalnik::SetName(char* NameToAdd) {
  73. if(name)
  74. delete name;
  75. name = new char[strlen(NameToAdd) + 1];
  76. strcpy(name, NameToAdd);
  77. return *this;
  78. }
  79.  
  80. Postachalnik& Postachalnik::SetPhone(char* PhoneToAdd) {
  81. if(phone)
  82. delete phone;
  83. phone = new char[strlen(PhoneToAdd) + 1];
  84. strcpy(phone, PhoneToAdd);
  85. return *this;
  86. }
  87.  
  88. class Product {
  89. char* product;
  90. int count;
  91. float price;
  92. Postachalnik obj;
  93. public:
  94. Product();
  95. Product(char*, int, float, Postachalnik&);
  96. Product(Product&);
  97. ~Product();
  98. Product& SetPostachalnik(Postachalnik&);
  99. Product& SetProduct(char*);
  100. Product& SetCount(int);
  101. Product& SetPrice(float);
  102. Postachalnik GetObject() { return obj; }
  103. char* GetProduct() { return product; }
  104. int GetCount() { return count; }
  105. float GetPrice() { return price; }
  106. void PrintFull();
  107. void PrintPart();
  108. };
  109.  
  110. Product::Product() {
  111. product = new char[8];
  112. strcpy(product, "no name");
  113. count = 0;
  114. price = 0;
  115. }
  116.  
  117. Product::Product(char* NameToAdd, int CounttoAdd, float PriceToAdd, Postachalnik& ObjectToAdd) {
  118. product = new char[strlen(NameToAdd) + 1];
  119. strcpy(product, NameToAdd);
  120. count = CounttoAdd;
  121. price = PriceToAdd;
  122. obj.SetCountry(ObjectToAdd.GetCountry());
  123. obj.SetName(ObjectToAdd.GetName());
  124. obj.SetPhone(ObjectToAdd.GetPhone());
  125. }
  126.  
  127. Product::Product(Product& a) {
  128. product = new char[strlen(a.product) + 1];
  129. strcpy(product, a.product);
  130. count = a.count;
  131. price = a.price;
  132. obj.SetName(a.obj.GetName());
  133. obj.SetCountry(a.obj.GetCountry());
  134. obj.SetPhone(a.obj.GetPhone());
  135. }
  136.  
  137. Product::~Product() {
  138. delete product;
  139. }
  140.  
  141. Product& Product::SetCount(int i) {
  142. count = i;
  143. return *this;
  144. }
  145.  
  146. Product& Product::SetPostachalnik(Postachalnik& Set_Object) {
  147. obj.SetCountry(Set_Object.GetCountry());
  148. return *this;
  149. }
  150. Product& Product::SetPrice(float i) {
  151. price = i;
  152. return *this;
  153. }
  154. Product& Product::SetProduct(char* name) {
  155. if (product)
  156. delete[] product;
  157. product = new char[strlen(name) + 1];
  158. strcpy(product, name);
  159. return *this;
  160. }
  161. void Product::PrintFull() {
  162. std::cout << product << '\t' << count << '\t' << price << '\t';
  163. obj.PrintFull();
  164. }
  165.  
  166. void Product::PrintPart() {
  167. std::cout << obj.GetName() << product;
  168. }
  169.  
  170. int main()
  171. {
  172. char COUNTRY[20];
  173. char NAME[20];
  174. char PHONE[20];
  175. char PHONE2[20];
  176. Postachalnik Obj1;
  177. std::cout << "Enter Postachalnik as Country,Name,Phone\n";
  178. std::cin >> COUNTRY;
  179. std::cin >> NAME;
  180. std::cin >> PHONE;
  181. Postachalnik Obj2(NAME, COUNTRY, PHONE);
  182. std::cout << "Enter a callcenter phone of company\n";
  183. std::cin >> PHONE2;
  184. Postachalnik Obj3(Obj2);
  185. Obj3.SetPhone(PHONE2);
  186. int k;
  187. std::cout << "chose a type of Postachalnik information\n" << "1-for Full\t" <<"2-for a PART\n";
  188. std::cin >> k;
  189. switch (k)
  190. {
  191. case 1:
  192. Obj1.PrintFull();
  193. Obj2.PrintFull();
  194. Obj3.PrintFull();
  195. break;
  196. case 2:
  197. Obj1.PrintPart();
  198. Obj2.PrintPart();
  199. Obj3.PrintPart();
  200. }
  201. Product object1;
  202. int COUNT;
  203. float PRICE;
  204. char PRODUCT[20];
  205. std::cout << "Enter Product, count of product amd price\n";
  206. std::cin >> PRODUCT;
  207. std::cin >> COUNT;
  208. std::cin >> PRICE;
  209.  
  210. Product object2(PRODUCT, COUNT, PRICE, Obj2);
  211. Product object3(object2);
  212. float PRICE2;
  213. std::cout << "Enter price in euro\n";
  214. std::cin >> PRICE2;
  215. object3.SetPrice(PRICE2);
  216. std::cout << "chose a type of Product information\n" << "1-for Full\t" << "2-for a PART\n";
  217. std::cin >> k;
  218. switch (k)
  219. {
  220. case 1:
  221. object1.PrintFull();
  222. object2.PrintFull();
  223. object3.PrintFull();
  224. break;
  225. case 2:
  226. object1.PrintPart();
  227. object2.PrintPart();
  228. object3.PrintPart();
  229. }
  230. return 0;
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement