mashlukashova

Untitled

Mar 22nd, 2019
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. const int kolichestvo = 2;
  8. const int D = 3;
  9. const int n = 2;
  10.  
  11. struct ZNAK {
  12. char name[20];
  13. char surname[30];
  14. string znak;
  15. int date[D];
  16. };
  17. void meny(int &n);
  18.  
  19. void fank2(int *A);
  20.  
  21. void outFData (char file_name[], const int kolichestvo);
  22.  
  23. int inFData (char file_name[], const int kolichestvo);
  24.  
  25. void search(ZNAK *m, const int kolichestvo);
  26.  
  27. void fillstruct(ZNAK *m, const int kolichestvo, const int D);
  28.  
  29. void showstruct(ZNAK *m, const int kolichestvo, const int D);
  30.  
  31. int main(){
  32. setlocale(LC_ALL, "rus");
  33. char file_name[20];
  34. cout<<"Enter file name:"<<endl;
  35. cin.getline(file_name, 20);
  36. int choice = 0;
  37. ZNAK m[kolichestvo];
  38. while (choice != 4) {
  39.  
  40. meny(choice);
  41. if (choice == 1) {
  42. inFData(file_name, kolichestvo);
  43.  
  44.  
  45. }
  46.  
  47.  
  48. if (choice == 3) {
  49. outFData(file_name, kolichestvo);
  50. }
  51. if (choice == 2) {
  52. search(m, kolichestvo);
  53. system ("pause");
  54. }
  55. if (choice == 4) break;
  56. }
  57. cout << "Завершение программы...";
  58. }
  59.  
  60.  
  61.  
  62. void meny(int &n) {
  63. system("cls");
  64. cout << setw(15) << "****Меню****"<<endl<<endl;
  65. cout << setw(3) << "1) Ввести данные" << endl;
  66. cout << setw(3) << "2) найти человека " << endl;
  67. cout << setw(3) << "3) Вывести данные" << endl;
  68. cout << setw(3) << "4) Выход" << endl;
  69. cin >> n;
  70. }
  71.  
  72.  
  73.  
  74. int inFData (char file_name[], const int kolichestvo)
  75. {
  76. ofstream file(file_name, ios::binary | ios::out);
  77. ZNAK m[kolichestvo];
  78. for (int i = 0; i < kolichestvo; i++)
  79. {
  80. cout << "input name and surname: ";
  81. cin >> m[i].name;
  82.  
  83. cin >> m[i].surname;
  84.  
  85. cout << "input Zodiac sign: ";
  86. cin >> m[i].znak;
  87.  
  88.  
  89. cout << "input date: ";
  90. fank2(m[i].date);
  91.  
  92. file.write(reinterpret_cast<char*> (&m), sizeof(ZNAK));
  93. }
  94. cout<<"File is made"<<endl;
  95. file.close();
  96. return 0;
  97. }
  98.  
  99.  
  100.  
  101.  
  102. void fank2(int *A) {
  103. for (int i=0; i < 3; i++) {
  104. cin >> A[i];
  105.  
  106. }
  107. }
  108.  
  109. void outFData (char file_name[], int kolichestvo)
  110. {
  111. ifstream file(file_name, ios::binary | ios::in);
  112. ZNAK m[kolichestvo];
  113. int i=1;
  114. while (true)
  115. {
  116. file.read(reinterpret_cast<char*> (&m), sizeof(ZNAK));
  117. if (file.eof())
  118. break;
  119.  
  120. cout << m[i].name << " ";
  121. cout << m[i].surname << " "<<endl;
  122. cout << m[i].znak << endl;
  123. for (int j = 0; j < 3; j++) {
  124. cout << m[i].date[j] << " ";
  125. }
  126. cout << endl;
  127. i++;
  128. }
  129. file.close();
  130. }
  131.  
  132. void search(char file_name[], ZNAK *m, const int kolichestvo){
  133. // ifstream file(file_name, ios::binary | ios::in);
  134.  
  135. char surname1[20];
  136.  
  137. for ( int l = 0; l < 20; l++ )
  138. surname1[l]=NULL;
  139.  
  140. cout<<"Enter needed surname: ";
  141. cin >> surname1;
  142.  
  143. bool r = false;
  144.  
  145. for ( int k = 0; k < kolichestvo; k++ )
  146. {
  147. bool b = true;
  148. int l = 0;
  149.  
  150. while ( surname1[l] != NULL)
  151. {
  152. if (surname1[l] != m[k].surname[l]) b = false; l++;
  153. }
  154. if (surname1[l] != m[k].surname[l]) b = false;
  155.  
  156. if ( b == true )
  157. {
  158. cout << m[k].name << " " << m[k].surname << endl << m[k].znak << endl;
  159. for (int j = 0; j < 3; j++){
  160.  
  161. cout << m[k].date[j] << " ";
  162. }
  163. cout << endl;
  164. cout<<"--------------------------------------------------"<<endl;
  165. r = true;
  166. }
  167. }
  168. if ( r == false ) cout<<"No match person"<<endl;
  169.  
  170. system("pause");
  171.  
  172. }
RAW Paste Data