constk

Lab_Structures

Feb 17th, 2020
174
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. const char top[] = "\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB";
  7. const char bottom[] = "\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC";
  8. const char line[] = "\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA";
  9.  
  10. typedef struct
  11. {
  12. char name[80];
  13. char secondName[80];
  14. char phoneNumber[12];
  15. int dateOfBirth[3];//день месяц год
  16. } NOTE;
  17.  
  18. void readNotes(NOTE*, int N);
  19. void showNotes(NOTE*, int N);
  20. void sortNotes(NOTE*, int N);
  21. void showNote(NOTE& note);
  22.  
  23.  
  24. int main() {
  25.  
  26. const int N = 8;
  27. NOTE note[N];
  28.  
  29. readNotes(note, N);
  30. showNotes(note, N);
  31.  
  32. sortNotes(note, N);
  33. printf("\nSorted notes\n");
  34. showNotes(note, N);
  35.  
  36. char secondName[80];
  37. bool personFound = false;
  38. printf("\nInput second name: ");
  39. scanf("%s", secondName);
  40. puts("");
  41.  
  42. for (int i = 0; i < N; i++)
  43. {
  44. if (!strcmp(note[i].secondName, secondName))
  45. {
  46. showNote(note[i]);
  47. personFound = true;
  48. puts("");
  49. }
  50. }
  51.  
  52. if (!personFound)
  53. puts("\nWhere is no such person.\n");
  54.  
  55. system("pause");
  56. return 0;
  57. }
  58.  
  59.  
  60. void readNotes(NOTE* note, int N)
  61. {
  62. for (int i = 0; i < N; i++)
  63. {
  64. printf("Note: %d\n", i + 1);
  65.  
  66. printf("\tInput name: ");
  67. scanf("%s", note[i].name);
  68.  
  69. printf("\tInput second name: ");
  70. scanf("%s", note[i].secondName);
  71.  
  72. printf("\tInput phone number: ");
  73. scanf("%s", note[i].phoneNumber);
  74.  
  75. printf("\tInput date of birth (d.m.y): ");
  76. scanf("%d.%d.%d", &note[i].dateOfBirth[0], &note[i].dateOfBirth[1], &note[i].dateOfBirth[2]);
  77.  
  78. printf("\n");
  79. }
  80. }
  81.  
  82. void showNotes(NOTE* note, int N)
  83. {
  84. printf("%s\n", top);
  85. printf("\xBA number \xBA name \xBA second name \xBA number \xBA date of birth \xBA\n");
  86. for (int i = 0; i < N; i++)
  87. {
  88. printf("%s\n", line);
  89. printf("\xBA%7d \xBA", i + 1);
  90. printf("%13s \xBA", note[i].name);
  91. printf("%14s \xBA", note[i].secondName);
  92. printf("%13s \xBA", note[i].phoneNumber);
  93. printf(" %02d.%02d.%04d \xBA\n", note[i].dateOfBirth[0], note[i].dateOfBirth[1], note[i].dateOfBirth[2]);
  94. }
  95. printf("%s\n", bottom);
  96. }
  97.  
  98. void sortNotes(NOTE* note, int N)
  99. {
  100. NOTE t;
  101. for (int i = 0; i < N; i++)
  102. {
  103. for (int j = 0; j < N - 1; j++)
  104. {
  105. if (strncmp(note[j].phoneNumber, note[j + 1].phoneNumber, 3) > 0)
  106. {
  107. t = note[j];
  108. note[j] = note[j + 1];
  109. note[j + 1] = t;
  110. }
  111. }
  112. }
  113.  
  114. }
  115.  
  116. void showNote(NOTE& note)
  117. {
  118. printf("Name: %s\n", note.name);
  119. printf("Second name: %s\n", note.secondName);
  120. printf("Phone number: %s\n", note.phoneNumber);
  121. printf("Date of birth: %02d.%02d.%04d\n", note.dateOfBirth[0], note.dateOfBirth[1], note.dateOfBirth[2]);
  122. }
RAW Paste Data