Advertisement
elenaalex

Untitled

Jan 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #defin#define _CRT_SECURE_NO_WARNINGS
  2. #define N 20
  3. #include<stdio.h>
  4. #include<string.h>
  5. #include<stdlib.h>
  6. struct date
  7. {
  8. int day, month, year;
  9. };
  10. struct lecturer
  11. {
  12. char *name;
  13. struct date birthday;
  14. int num_of_courses;
  15. char **courses;
  16. };
  17. void Course_Lectures(struct lecturer *arr1, char name[N], int size)
  18. {
  19. int i, j;
  20. int i_course, j_course;
  21. for (i = 0; i < size; i++)
  22. {
  23. for (j = 0; j < arr1[i].num_of_courses; j++)
  24. {
  25. if (strcmp(name, arr1[i].courses[j]) == 0)
  26. {
  27. puts(arr1[i].name);
  28. }
  29. }
  30. }
  31.  
  32. }
  33. void common(struct lecturer *arr1, char name1[N], char name2[N], int size)
  34. {
  35. int i, j;
  36. int i_name, j_name;
  37. for (i = 0; i < size; i++)
  38. {
  39. if (strcmp(name1, arr1[i].name) == 0)
  40. {
  41. i_name = i;
  42. }
  43. if (strcmp(name2, arr1[i].name) == 0)
  44. {
  45. j_name = i;
  46. }
  47. }
  48. for (i = 0; i < arr1[i_name].num_of_courses; i++)
  49. {
  50. for (j = 0; j < arr1[j_name].num_of_courses; j++)
  51. if ((strcmp(arr1[i_name].courses[i], arr1[j_name].courses[j])) == 0)
  52. printf(arr1[i_name].courses[i]);
  53. }
  54. }
  55. void old(struct date old, struct lecturer *arr1, int size)
  56. {
  57. int i, j;
  58. for (i = 0; i < size; i++)
  59. {
  60. if (arr1[i].birthday.year < old.year)
  61. {
  62. puts(arr1[i].name);
  63. }
  64. else if (arr1[i].birthday.year = old.year)
  65. {
  66. if (arr1[i].birthday.month < old.month)
  67. {
  68. if (arr1[i].birthday.day <= old.day)
  69. {
  70. puts(arr1[i].name);
  71. }
  72. }
  73. }
  74. }
  75. }
  76. int main()
  77. {
  78. struct lecturer *lecturers = NULL;
  79. int size, i, j;
  80. struct date old1;
  81. char name[N], name1[N], name2[N], NameCourse[N];
  82. printf("enter please the number of the lectrures :\n ");
  83. scanf("%d", &size);
  84. lecturers = (struct lecturer*)malloc(size * sizeof(struct lecturer));
  85. if (lecturers == NULL)
  86. {
  87. printf("error \n");
  88. return 0;
  89. }
  90. for (i = 0; i < size; i++)
  91. {
  92. printf("enter the name of the prof:\n");
  93. scanf("%s", name);
  94. lecturers[i].name = (char*)malloc((strlen(name) + 1) * sizeof(char));
  95. if (lecturers[i].name == NULL)
  96. {
  97. printf("memory error \n");
  98. // Oh look memory leak. Free your things!
  99. return 0;
  100. }
  101. for (j = 0; j < strlen(name); j++)
  102. {
  103. lecturers[i].name[j] = name[j];
  104. }
  105. lecturers[i].name[j] = '\0';
  106.  
  107. printf("please enter the birthday of the prof :\n");
  108. scanf("%d%d%d", &lecturers[i].birthday.day, &lecturers[i].birthday.month, &lecturers[i].birthday.year);
  109. printf("enter the number of courses of the prof :\n");
  110. scanf("%d", &lecturers[i].num_of_courses);
  111. lecturers[i].courses = (char**)malloc(lecturers[i].num_of_courses * sizeof(char*));
  112. for (j = 0; j<lecturers[i].num_of_courses; j++)
  113. {
  114. lecturers[i].courses[j] = (char*)malloc(N * sizeof(char));
  115. if (lecturers[i].courses[j] == NULL)
  116. {
  117. printf("memory error \n");
  118. // Oh look memory leak. Free your things!
  119. return 0;
  120. }
  121. printf("enter the name of the course :\n");
  122. scanf("%s", lecturers[i].courses[j]);
  123. }
  124. }
  125.  
  126. printf("enter the name of the course :\n");
  127. scanf("%s", NameCourse);
  128. Course_Lectures(lecturers, name, size);
  129. printf("enter names of two profs\n");
  130. scanf("%s", name1);
  131. scanf("%s", name2);
  132. common(lecturers, name1, name2, size);
  133. printf("enter the date after which the prof was born");
  134. scanf("%d%d%d", &old1.day, &old1.month, &old1.year);
  135. old(old1, lecturers, size);
  136. free(lecturers);
  137. for (i = 0; i < size; i++)
  138. {
  139. for (j = 0; j<lecturers[i].num_of_courses; j++)
  140. free(lecturers[i].courses[j]);
  141. }
  142. for (i = 0; i < size; i++)
  143. free(lecturers[i].courses);
  144. return 0;
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement