fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX 100
  5.  
  6. typedef struct {
  7. char surname[50];
  8. char name[50];
  9. char patronymic[50];
  10. char birth_date[11]; // формат "YYYY-MM-DD"
  11. char address[100];
  12. char phone[20];
  13. char faculty[50];
  14. int course;
  15. } Student;
  16.  
  17. // Функция установки данных
  18. void set_student(Student *s, const char *surname, const char *name, const char *patronymic,
  19. const char *birth_date, const char *address, const char *phone,
  20. const char *faculty, int course) {
  21. strcpy(s->surname, surname);
  22. strcpy(s->name, name);
  23. strcpy(s->patronymic, patronymic);
  24. strcpy(s->birth_date, birth_date);
  25. strcpy(s->address, address);
  26. strcpy(s->phone, phone);
  27. strcpy(s->faculty, faculty);
  28. s->course = course;
  29. }
  30.  
  31. void show_student(const Student *s) {
  32. printf("ФИО: %s %s %s\n", s->surname, s->name, s->patronymic);
  33. printf("Дата рождения: %s\n", s->birth_date);
  34. printf("Адрес: %s\n", s->address);
  35. printf("Телефон: %s\n", s->phone);
  36. printf("Факультет: %s\n", s->faculty);
  37. printf("Курс: %d\n", s->course);
  38. printf("-------------------------------------\n");
  39. }
  40.  
  41. int get_birth_year(const Student *s) {
  42. int year;
  43. sscanf(s->birth_date, "%d", &year); // Считываем только год
  44. return year;
  45. }
  46.  
  47.  
  48. void print_by_faculty(const Student students[], int n, const char *faculty) {
  49. printf("\nСтуденты факультета %s:\n", faculty);
  50. for (int i = 0; i < n; i++) {
  51. if (strcmp(students[i].faculty, faculty) == 0) {
  52. show_student(&students[i]);
  53. }
  54. }
  55. }
  56.  
  57.  
  58. void print_by_faculty_and_course(const Student students[], int n) {
  59. printf("\nСтуденты по факультетам и курсам:\n");
  60. for (int i = 0; i < n; i++) {
  61. printf("Факультет: %s, Курс: %d\n", students[i].faculty, students[i].course);
  62. show_student(&students[i]);
  63. }
  64. }
  65.  
  66.  
  67. void print_born_after_year(const Student students[], int n, int year) {
  68. printf("\nСтуденты, родившиеся после %d года:\n", year);
  69. for (int i = 0; i < n; i++) {
  70. if (get_birth_year(&students[i]) > year) {
  71. show_student(&students[i]);
  72. }
  73. }
  74. }
  75.  
  76. int main() {
  77. Student students[MAX];
  78. int n = 3; // Количество студентов (для примера)
  79.  
  80. set_student(&students[0], "Иванов", "Иван", "Иванович", "2002-05-14", "г. Москва", "+71234567890", "Физика", 2);
  81. set_student(&students[1], "Петров", "Петр", "Петрович", "2001-03-22", "г. Санкт-Петербург", "+79876543210", "Информатика", 3);
  82. set_student(&students[2], "Сидоров", "Сидор", "Сидорович", "2003-12-01", "г. Казань", "+79991112233", "Физика", 1);
  83.  
  84. print_by_faculty(students, n, "Физика");
  85. print_by_faculty_and_course(students, n);
  86. print_born_after_year(students, n, 2003);
  87.  
  88. return 0;
  89. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Студенты факультета Физика:
ФИО: Иванов Иван Иванович
Дата рождения: 2002-05-14
Адрес: г. Москва
Телефон: +71234567890
Факультет: Физика
Курс: 2
-------------------------------------
ФИО: Сидоров Сидор Сидорович
Дата рождения: 2003-12-01
Адрес: г. Казань
Телефон: +79991112233
Факультет: Физика
Курс: 1
-------------------------------------

Студенты по факультетам и курсам:
Факультет: Физика, Курс: 2
ФИО: Иванов Иван Иванович
Дата рождения: 2002-05-14
Адрес: г. Москва
Телефон: +71234567890
Факультет: Физика
Курс: 2
-------------------------------------
Факультет: Информатика, Курс: 3
ФИО: Петров Петр Петрович
Дата рождения: 2001-03-22
Адрес: г. Санкт-Петербург
Телефон: +79876543210
Факультет: Информатика
Курс: 3
-------------------------------------
Факультет: Физика, Курс: 1
ФИО: Сидоров Сидор Сидорович
Дата рождения: 2003-12-01
Адрес: г. Казань
Телефон: +79991112233
Факультет: Физика
Курс: 1
-------------------------------------

Студенты, родившиеся после 2003 года: