Advertisement
Guest User

Untitled

a guest
Sep 29th, 2022
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <list>
  4.  
  5. using namespace std;
  6.  
  7. struct patient : public error_code {
  8. patient() {
  9. }
  10.  
  11. patient(string firstName, string secondName, string gender,
  12. string age, string address, string tNumber, string date) {
  13. this->firstName = firstName;
  14. this->secondName = secondName;
  15. this->gender = gender;
  16. this->age = age;
  17. this->address = address;
  18. this->tNumber = tNumber;
  19. this->date = date;
  20.  
  21. }
  22.  
  23. private:
  24. string firstName;
  25. string secondName;
  26. string gender;
  27. string age;
  28. string address;
  29. string tNumber;
  30. string date;
  31.  
  32. public:
  33. string getFirstName() {
  34. return firstName;
  35. }
  36. string getSecondName() {
  37. return secondName;
  38. }
  39. string getGender() {
  40. return gender;
  41. }
  42. string getAge() {
  43. return age;
  44. }
  45.  
  46. /*int searchYoungAges(patient *pt) {
  47. for (int i = 0; i < 100; i++) {
  48. if (pt[i].age < 18) {
  49. return i;
  50. }
  51. }
  52. return 0;
  53. }
  54. */
  55.  
  56. void printInformation(patient *pt) {
  57. for (int i = 0; i < 5; i++) {
  58. cout << "Имя: " << pt[i].firstName << endl;
  59. cout << "Фамилия: " << pt[i].secondName << endl;
  60. cout << "Пол: " << pt[i].gender << endl;
  61. cout << "Возраст: " << pt[i].age << endl;
  62. cout << "Адрес: " << pt[i].address << endl;
  63. cout << "Номер телефона: " << pt[i].tNumber << endl;
  64. cout << "Дата последнего обращения: " << pt[i].date << endl;
  65. cout << "\n" << endl;
  66. }
  67. }
  68. };
  69.  
  70.  
  71.  
  72. int main() {
  73.  
  74. cout << "Введите название файла для чтения: ";
  75. string filenameinput;
  76. cin >> filenameinput;
  77. ifstream input;
  78. input.open(filenameinput + ".txt");
  79. //ifstream input(filenameinput + ".txt");
  80.  
  81. if (!input.is_open()) {
  82. cout << "Ошибка при открытии файла чтения!" << endl;
  83. return -1;
  84. }
  85. else {
  86. cout << "Файл чтения открылся" << endl;
  87. }
  88.  
  89. cout << "Введите название файла для записи: ";
  90. string filenameoutput;
  91. cin >> filenameoutput;
  92. ofstream output;
  93. output.open(filenameoutput + ".txt");
  94. //ofstream output(filenameoutput + ".txt");
  95.  
  96. if (!input.is_open()) {
  97. cout << "Ошибка при открытии файла записи!" << endl;
  98. return -1;
  99. }
  100. else {
  101. cout << "Файл записи открылся" << endl;
  102. }
  103.  
  104. string strOfLine;
  105. struct patient arr[50];
  106. string arr2[256];
  107. int i = 0;
  108. int i2 = 0;
  109. string strOfPatient;
  110.  
  111. while (!input.eof()) {
  112. strOfLine = "";
  113.  
  114. getline(input, strOfLine);
  115. strOfPatient += strOfLine + "\n";
  116.  
  117. if (strOfLine != "") {
  118. arr2[i2] = strOfLine;
  119. i2++;
  120. }
  121.  
  122. if (i2 == 6) {
  123. getline(input, strOfLine);
  124. strOfPatient += strOfLine + "\n";
  125. arr2[i2] = strOfLine;
  126.  
  127.  
  128. arr2[i] = strOfLine;
  129. i2 = 0;
  130. arr[i] = { arr2[0], arr2[1], arr2[2], arr2[3],
  131. arr2[4], arr2[5], arr2[6] };
  132.  
  133. arr2[0] = "";
  134. arr2[1] = "";
  135. arr2[2] = "";
  136. arr2[3] = "";
  137. arr2[4] = "";
  138. arr2[5] = "";
  139. arr2[6] = "";
  140.  
  141.  
  142. strOfPatient = "";
  143. i++;
  144. }
  145. }
  146. input.close();
  147.  
  148.  
  149. int userChoice;
  150.  
  151. string firstNameUser;
  152. string secondNameUser;
  153. string genderUser;
  154. string ageUser;
  155. string addressUser;
  156. string tNumberUser;
  157. string dateUser;
  158.  
  159.  
  160. while (i < 50) {
  161.  
  162. cout << "Хотите добавить информацию о новом пациенте? (1-да/0-нет)" << endl;
  163. cin >> userChoice;
  164.  
  165. if (userChoice == 1) {
  166. cout << "Введите имя пациента : ";
  167. cin >> firstNameUser;
  168.  
  169. cout << "Введите фамилию пациента : ";
  170. cin >> secondNameUser;
  171.  
  172. cout << "Введите пол пациента : ";
  173. cin >> genderUser;
  174.  
  175. cout << "Введите возраст пациента : ";
  176. cin >> ageUser;
  177.  
  178. cout << "Введите адрес пациента : ";
  179. cin >> addressUser;
  180.  
  181. cout << "Введите контактный номер телефона пациента : ";
  182. cin >> tNumberUser;
  183.  
  184. cout << "Введите последнюю дату обращения пациента в центр : ";
  185. cin >> ageUser;
  186.  
  187. arr[i] = { firstNameUser, secondNameUser, genderUser,
  188. ageUser, addressUser, tNumberUser, ageUser };
  189. if (stoi(arr[i].getAge()) < 18) {
  190. output << firstNameUser;
  191. output << " ";
  192. output << secondNameUser;
  193. output << " ";
  194. output << genderUser;
  195. output << " ";
  196. output << ageUser;
  197. output << " ";
  198. output << tNumberUser;
  199. output << " ";
  200. output << ageUser;
  201. }
  202. i++;
  203.  
  204. }
  205. else {
  206. break;
  207. }
  208. }
  209. output.close();
  210. }
  211.  
  212.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement