Advertisement
Guest User

14-17

a guest
May 25th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. class Znak {
  7.  
  8. public:
  9. char name[255] = {};
  10. char surname[255] = "";
  11. int zodiac;
  12. int birthday[3] = {};
  13.  
  14.  
  15. void Input() {
  16. cout << "Имя: ";
  17. cin.getline(name, 255);
  18.  
  19. cout << "Фамилия: ";
  20. cin.getline(surname, 255);
  21.  
  22. cout << "Номер знака зодиака: ";
  23. cin >> zodiac;
  24.  
  25. cout << "День рождения: " << endl;
  26. cout << "День: "; cin >> birthday[0];
  27. cout << "Месяц: "; cin >> birthday[1];
  28. cout << "Год: "; cin >> birthday[2];
  29. cin.ignore(255, '\n');
  30. }
  31.  
  32. void Output(char* str) {
  33. cout << str << endl;
  34. }
  35.  
  36. void Write(ofstream &out) {
  37. out << name << " " << surname << " " << zodiac << " " << birthday[0] << '.'
  38. << birthday[1] << '.'
  39. << birthday[2] << endl;
  40. }
  41.  
  42. void Read(ifstream &in, char* str) {
  43. in.getline(str, 255);
  44. }
  45.  
  46.  
  47.  
  48. };
  49.  
  50. void swap(Znak &f, Znak &s) {
  51.  
  52. if(&f == &s) {
  53. return;
  54. }
  55.  
  56. Znak tmp;
  57. memcpy(&tmp, &s, sizeof(Znak));
  58. memcpy(&s, &f, sizeof(Znak));
  59. memcpy(&f, &tmp, sizeof(Znak));
  60. }
  61.  
  62. void sort(Znak a[], const int N) {
  63.  
  64. for(int i = 0; i < N; i++) {
  65. int k = i;
  66.  
  67. for(int j = i + 1; j < N; j++) {
  68. if(a[j].zodiac < a[k].zodiac) {
  69. k = j;
  70. }
  71. }
  72.  
  73. swap(a[k], a[i]);
  74. }
  75. }
  76.  
  77. int main() {
  78. const int n = 8;
  79. Znak znak[n];
  80.  
  81. for(int i = 0; i < n; i++) {
  82. znak[i].Input();
  83. }
  84.  
  85. sort(znak, n);
  86.  
  87. ofstream out("/root/znaki.txt", ios::trunc | ios::out);
  88. for(int i = 0; i < n; i++) {
  89. znak[i].Write(out);
  90. }
  91.  
  92. ifstream in("/root/znaki.txt", ios::in);
  93. char str[255] = {};
  94. for(int i = 0; i < n; i++) {
  95. znak[i].Read(in, str);
  96. znak[i].Output(str);
  97. }
  98.  
  99. in.seekg(0);
  100. int m, c = 0;
  101. cout << "Введите номер месяца: ";
  102. cin >> m;
  103. for(int i = 0; i < n; i++) {
  104. znak[i].Read(in, str);
  105. if(znak[i].birthday[1] == m) {
  106. znak[i].Output(str);
  107. c++;
  108.  
  109. }
  110. }
  111.  
  112. if(c == 0) {
  113. cout << "Человека, родившегося в этот месяц, нет";
  114. }
  115.  
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement