Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #pragma once
  2. #pragma once
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. #pragma warning(disable:4996)
  7. using namespace std;
  8.  
  9. struct Item {
  10. char Name[35];
  11. char myDate[8];
  12. char Section[10];
  13. int Count;
  14. friend ostream &operator<<(ostream& out, const Item & s) {
  15. out << s.Name << " " << s.myDate << " " << s.Section << " " << s.Count;
  16. return out;
  17. }
  18. friend istream &operator>>(istream& in, Item & s) {
  19. in.ignore();
  20. in.getline(s.Name, 100, '\n');
  21. in >> s.myDate >> s.Section >> s.Count;
  22. in.ignore();
  23. return in;
  24. }
  25. };
  26.  
  27. struct Price {
  28. char Name[35];
  29. double pr;
  30. friend ostream &operator<<(ostream& out, const Price & s) {
  31. out << s.Name << " " << s.pr;
  32. return out;
  33. }
  34. friend istream &operator>>(istream& in, Price & s) {
  35. in.ignore();
  36. in.getline(s.Name, 100, '\n');
  37. in >> s.pr;
  38. in.ignore();
  39. return in;
  40. }
  41. };
  42.  
  43.  
  44. struct Med {
  45. char Name[35];
  46. char myDate[8];
  47. char Section[10];
  48. double pr;
  49. int Count;
  50. friend ostream &operator<<(ostream& out, const Med & s) {
  51. out << s.Name << " " << s.myDate << " " << s.Section << " " << s.pr << " " << s.Count;
  52. return out;
  53. }
  54. friend istream &operator>>(istream& in, Med & s) {
  55. in.getline(s.Name, 100, '\n');
  56. in >> s.myDate >> s.Section >> s.pr>>s.Count;
  57. return in;
  58. }
  59. };
  60.  
  61. template <class T>
  62. class MED {
  63. //char Table_Title[50];
  64. int count;
  65. T* M;
  66. public:
  67. MED() {
  68. count = 0;
  69. M = NULL;
  70. }
  71. MED(int _count) {
  72. count = _count;
  73. M = new T[count];
  74. }
  75. MED(MED & st)
  76. {
  77. count = st.count;
  78. M = new T[count];
  79. for (int i = 0; i < count; i++)
  80. M[i] = st.M[i];
  81. }
  82. ~MED()
  83. {
  84. count = 0;
  85. delete[]M;
  86. }
  87. MED& operator=(const MED &st)
  88. {
  89. if (this != &st) {
  90. count = st.count;
  91. for (int i = 0; i < count; i++)
  92. M[i] = st.M[i];
  93. }
  94. return *this;
  95. }
  96. int GetCount() {
  97. return count;
  98. }
  99. T& operator[](int index)
  100. {
  101. return M[index];
  102. }
  103. friend ostream& operator<<(ostream& out, const MED<T> & st)
  104. {
  105. for (int i = 0; i<st.count; i++)
  106. out << st.M[i] << endl;
  107. out << endl;
  108. return out;
  109. }
  110. friend istream& operator>>(istream& out, MED<T> & st)
  111. {
  112. for (int i = 0; i<st.count; i++)
  113. out >> st.M[i];
  114. return out;
  115. }
  116. friend MED<T> operator+(MED<T>& s1, MED<T>& s2) {
  117. MED<Item> s3(s1.GetCount()+s2.GetCount());
  118. int k = 0;
  119. for (int i = 0; i < s1.count; i++) {
  120. strcpy(s3[k].Name , s1[i].Name);
  121. strcpy(s3[k].myDate, s1[i].myDate);
  122. strcpy(s3[k].Section, s1[i].Section);
  123. s3[k].Count = s1[i].Count;
  124. k++;
  125. }
  126. int lo = 0;
  127. for (int i = 0; i < s2.GetCount(); i++) {
  128. for (int j = 0; j < k; j++) {
  129. if (strcmp(s3[j].Name, s2[i].Name) != 0) {
  130. lo++;
  131. }
  132. if (lo==k) {
  133. strcpy(s3[k].Name, s2[i].Name);
  134. strcpy(s3[k].myDate, s2[i].myDate);
  135. strcpy(s3[k].Section, s2[i].Section);
  136. s3[k].Count = s2[i].Count;
  137. k++;
  138. lo = 0;
  139. }
  140. }
  141. }
  142. s3.count = k;
  143. return s3;
  144. }
  145. void sort() {
  146. for (int curSize = this->count; curSize > 1; --curSize) {
  147. for (int i = 0; i < curSize - 1; ++i) {
  148. if (strcmp(this->M[i].Name, this->M[i + 1].Name) > 0)
  149. swap(this->M[i], this->M[i + 1]);
  150. }
  151. }
  152. }
  153. void sortD() {
  154. for (int curSize = this->count; curSize > 1; --curSize) {
  155. for (int i = 0; i < curSize - 1; ++i) {
  156. if (strcmp(this->M[i].Name, this->M[i + 1].Name) < 0)
  157. swap(this->M[i], this->M[i + 1]);
  158. }
  159. }
  160. }
  161. void find(const char* name) {
  162. for (int i = 0; i < this->count; ++i)
  163. if (strcmp(this->M[i].Name, name) == 0)
  164. cout << this->M[i];
  165. }
  166. };
  167.  
  168.  
  169. \\\\\\\\\\\\\\\\\\\\\\\\\\\
  170. #include <fstream>
  171. #include <iostream>
  172. #include "func.h"
  173. #pragma warning(disable:4996)
  174.  
  175. using namespace std;
  176.  
  177. void main() {
  178. setlocale(LC_ALL, "RUS");
  179. ifstream in1("Ob1.txt");
  180. ifstream in2("Ob2.txt");
  181. ifstream in3("TOb1.txt");
  182. ifstream in4("TOb2.txt");
  183. int n,n1,n2, n3;
  184. in1 >> n;
  185. in2 >> n1;
  186. in1 >> n2;
  187. in2 >> n3;
  188. MED<Item> M1(n),M2(n1),M3(n+n1);
  189. MED<Price> K1(n2), K2(n3), K3(n2+n3);
  190. in1 >> M1;
  191. in2 >> M2;
  192. cout << M1;
  193. cout << M2;
  194. cout<< M1 + M2;
  195. M3 = (M1 + M2);
  196. cout << M3;
  197. //in3 >> K1;
  198. //in4 >> K2;
  199. /*ofstream out("out.txt");
  200. in1 >> M1;
  201. in2 >> M2;
  202. cout << M1;
  203. M1.sort();
  204. cout << M1;
  205. M1.sortD();
  206. cout << M1;
  207. cout << M2;*/
  208.  
  209. system("pause");
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement