Advertisement
niks32

test1.2

Jan 24th, 2023
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.35 KB | None | 0 0
  1. #include "fmbf.h"
  2. #include "fmin.h"
  3. #include <set>
  4. #include <string>
  5.  
  6. //прототипы
  7. void insertStudent ( int *stat );
  8. void findPopularLastName();
  9.  
  10. struct STUDENT_FOR_TEST
  11. {
  12.     char     FirstName[51];  // Имя
  13.     char     SecondName[51]; // Отчество
  14.     char     LastName[51];   // Фалимлие
  15.     bdate BirthDay;
  16.     //int bdate[3]; //{y, m, d} Дата рождения
  17. };
  18.  
  19. STUDENT_FOR_TEST testStudentsPool[] = {
  20.     {"Иван", "Иванович", "Иванов", RSL_SCTR_BDATE(1990, 6, 15)},
  21.     {"Дмитрий", "Дмитриевич", "Дмитров",  RSL_SCTR_BDATE(1989, 9, 19)},
  22.     {"Дмитрий", "Дмитриевич", "Дмитров", RSL_SCTR_BDATE(1989, 9, 19)},
  23.     {"Инакентий", "Корнеевич", "Иванов", RSL_SCTR_BDATE(1999, 1, 13)},
  24. };
  25.  
  26.  
  27. void workOnDstudent_dbt()
  28. {
  29.     int stat = 0;
  30.     char isOpenFileStudent = 0;
  31.  
  32.     if ( !FileSTUDENT )
  33.     {
  34.         isOpenFileStudent = 1;
  35.         stat = iOpenSTUDENT( 1 );
  36.     }
  37.  
  38.     if ( !stat )
  39.     {
  40.         insertStudent( &stat ); //Добавление студентов
  41.         findPopularLastName(); //поиск самой частой фамилии
  42.     }
  43.  
  44.    
  45.     // А после работы - закрыть
  46.     if ( FileSTUDENT && isOpenFileStudent )
  47.     {
  48.        bfClose( &FileSTUDENT );
  49.     }
  50. }
  51.  
  52.  
  53. void insertStudent ( int *stat )
  54. {
  55.     for (int i=0; i< (sizeof(testStudentsPool) / sizeof(testStudentsPool[0])); i++)
  56.     {  
  57.         if(FindSTUDENT_LASTNAME_FIRSTNAME_SECONDNAME(testStudentsPool[i].LastName, testStudentsPool[i].FirstName, testStudentsPool[i].SecondName, NULL)) //поиск записи (будущего дубля)
  58.         {
  59.             STUDENT *recBuf = (STUDENT*)FileSTUDENT->RecBuf;
  60.  
  61.             bdate BirthDay = testStudentsPool[i].BirthDay;
  62.  
  63.             memset( recBuf, 0, sizeof(STUDENT) );
  64.             // если бы в TStudent были бы атрибуты типа db_lmoney, необходимо
  65.             // было бы этим атрибутам присвоить значение DB_LMONEY_ZERO
  66.  
  67.             strcpy(recBuf->FirstName, testStudentsPool[i].FirstName );
  68.             strcpy(recBuf->SecondName, testStudentsPool[i].SecondName );
  69.             strcpy(recBuf->LastName, testStudentsPool[i].LastName );
  70.             recBuf->Birthday = BirthDay;
  71.  
  72.             // Обратите внимание, StudentID остался равным 0
  73.             *stat = bfOp(FileSTUDENT, Binsert);
  74.         }
  75.     }
  76. }
  77.  
  78. int countLastName (char *LastName)
  79. {
  80.     int counter = 0;
  81.     STUDENT *recBuf = (STUDENT*)FileSTUDENT->RecBuf;
  82.     SKF_STUDENT_LASTNAMEFIRSTNAMESECONDNAME(LastName, NULL, NULL);
  83.  
  84.     for( int st=bfGet(FileSTUDENT, BgetF); !st; st=bfGet(FileSTUDENT, BgetN ) )
  85.     {
  86.             counter = counter + 1;
  87.     }
  88.     return counter;
  89. }
  90.  
  91. void findPopularLastName()
  92. {
  93.     int countPopularLastName = 0;
  94.     char PopularLastName[51];
  95.  
  96.     set<string> LastNameList;
  97.    
  98.     STUDENT *recBuf = (STUDENT*)FileSTUDENT->RecBuf;
  99.     SKF_STUDENT_LASTNAMEFIRSTNAMESECONDNAME(NULL, NULL, NULL);
  100.  
  101.     for( int st=bfGet(FileSTUDENT, BgetF); !st; st=bfGet(FileSTUDENT, BgetN ) )
  102.     {
  103.         LastNameList.insert(string(recBuf->LastName));
  104.     }
  105.    
  106.     for (auto it = LastNameList.begin(); it != LastNameList.end(); ++it)
  107.     {
  108.         char tLastName[51];
  109.         strcpy(tLastName, it->c_str());
  110.        
  111.         int tCount = countLastName(tLastName);
  112.         if (countPopularLastName < tCount)
  113.         {
  114.             countPopularLastName = tCount;
  115.             strcpy(PopularLastName, it->c_str());
  116.         }
  117.     }
  118.     //выводим самое популярное
  119.     meswin(PopularLastName);
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement