fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <ctime>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. struct Contact {
  11. string lastName;
  12. string firstName;
  13. string patronymic;
  14. string birthDate;
  15. string address;
  16. string phone;
  17. string workplace;
  18. string position;
  19. };
  20.  
  21.  
  22. // Функция для автоматического формирования поздравления НЕ РАБОТАЕТ, ГАДОСТЬ
  23. string generateBirthdayGreeting(const Contact& contact) {
  24. time_t timer;
  25. time(&timer);
  26. tm *year = localtime(&timer);
  27. string current_date = to_string(1900 + year->tm_year) + "-" + to_string(1 + year->tm_mon) + "-" + to_string(year->tm_mday);
  28.  
  29. if (contact.birthDate.substr(5) == current_date.substr(5))
  30. {
  31. return "Уважаемый(ая) " + contact.firstName + " " + contact.patronymic + "! \nС Днем Рождения!\n";
  32. }
  33. else {
  34. return 0;
  35. }
  36. }
  37.  
  38.  
  39.  
  40. // Вывод списка контактов (сортировка по фамилии)
  41. void printSortedContacts(const vector<Contact>& contacts) {
  42. vector<pair<string, string>> sortedContacts;
  43. for (const auto& contact : contacts) {
  44. sortedContacts.push_back({ contact.lastName, contact.phone });
  45. }
  46. sort(sortedContacts.begin(), sortedContacts.end());
  47.  
  48. cout << "Список контактов (фамилия - телефон):" << endl;
  49. for (const auto& item : sortedContacts) {
  50. cout << item.first << " - " << item.second << endl;
  51. }
  52. }
  53.  
  54. // Поиск контактов по фамилии
  55. vector<Contact> searchByLastName(const vector<Contact>& contacts, const string& lastName) {
  56. vector<Contact> result;
  57. for (const auto& contact : contacts) {
  58. if (contact.lastName == lastName) {
  59. result.push_back(contact);
  60. }
  61. }
  62. return result;
  63. }
  64.  
  65.  
  66. // Функция для поиска контактов по адресу
  67. vector<Contact> searchByAddress(const vector<Contact>& contacts, const string& address) {
  68. vector<Contact> result;
  69. for (const auto& contact : contacts) {
  70. if (contact.address == address) {
  71. result.push_back(contact);
  72. }
  73. }
  74. return result;
  75. }
  76.  
  77.  
  78. int main() {
  79. vector<Contact> contacts;
  80.  
  81.  
  82. // Вывод поздравлений с днем рождения
  83. for (const auto& contact : contacts) {
  84. string greeting = generateBirthdayGreeting(contact);
  85. if (!greeting.empty()) {
  86. cout << greeting << endl;
  87. }
  88. }
  89.  
  90. // Поиск по фамилии
  91. string searchLastName;
  92. cout << "Введите фамилию для поиска: ";
  93. cin >> searchLastName;
  94. vector<Contact> foundContacts = searchByLastName(contacts, searchLastName);
  95. for (const auto& contact : foundContacts) {
  96. cout << contact.lastName << " " << contact.firstName << " " << contact.patronymic << ", " << contact.birthDate << ", "
  97. << contact.address << ", " << contact.phone << ", " << contact.workplace << ", " << contact.position << endl;
  98. }
  99.  
  100.  
  101.  
  102. // Поиск по адресу
  103. string searchAddress;
  104. cout << "Введите адрес для поиска: ";
  105. cin.ignore();
  106. getline(cin, searchAddress);
  107. vector<Contact> foundByAddress = searchByAddress(contacts, searchAddress);
  108. for (const auto& contact : foundByAddress)
  109. {
  110. cout << contact.lastName << " " << contact.firstName << " " << contact.patronymic << ", " << contact.birthDate << ", "
  111. << contact.address << ", " << contact.phone << ", " << contact.workplace << ", " << contact.position << endl;
  112.  
  113. }
  114.  
  115.  
  116. // Вывод отсортированного списка
  117. printSortedContacts(contacts);
  118.  
  119. return 0;
  120. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Введите фамилию для поиска: Введите адрес для поиска: Список контактов (фамилия - телефон):