Advertisement
niks32

test1.3

Jan 24th, 2023
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.11 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. void findAndEditById ();
  10.  
  11. struct STUDENT_FOR_TEST
  12. {
  13.     char     FirstName[51];  // Имя
  14.     char     SecondName[51]; // Отчество
  15.     char     LastName[51];   // Фалимлие
  16.     bdate BirthDay;
  17.     //int bdate[3]; //{y, m, d} Дата рождения
  18. };
  19.  
  20. STUDENT_FOR_TEST testStudentsPool[] = {
  21.     {"Иван", "Иванович", "Иванов", RSL_SCTR_BDATE(1990, 6, 15)},
  22.     {"Дмитрий", "Дмитриевич", "Дмитров",  RSL_SCTR_BDATE(1989, 9, 19)},
  23.     {"Дмитрий", "Дмитриевич", "Дмитров", RSL_SCTR_BDATE(1989, 9, 19)},
  24.     {"Инакентий", "Корнеевич", "Иванов", RSL_SCTR_BDATE(1999, 1, 13)},
  25. };
  26.  
  27.  
  28. void workOnDstudent_dbt()
  29. {
  30.     int stat = 0;
  31.     char isOpenFileStudent = 0;
  32.  
  33.     if ( !FileSTUDENT )
  34.     {
  35.         isOpenFileStudent = 1;
  36.         stat = iOpenSTUDENT( 1 );
  37.     }
  38.  
  39.     /*if ( !stat )
  40.     {
  41.         insertStudent( &stat ); //Добавление студентов
  42.         findPopularLastName(); //поиск самой частой фамилии
  43.         findAndEditById ();
  44.     }*/
  45.  
  46.     findAndEditById ();
  47.  
  48.     // А после работы - закрыть
  49.     if ( FileSTUDENT && isOpenFileStudent )
  50.     {
  51.        bfClose( &FileSTUDENT );
  52.     }
  53. }
  54.  
  55.  
  56. void insertStudent ( int *stat )
  57. {
  58.     for (int i=0; i< (sizeof(testStudentsPool) / sizeof(testStudentsPool[0])); i++)
  59.     {  
  60.         if(FindSTUDENT_LASTNAME_FIRSTNAME_SECONDNAME(testStudentsPool[i].LastName, testStudentsPool[i].FirstName, testStudentsPool[i].SecondName, NULL)) //поиск записи (будущего дубля)
  61.         {
  62.             STUDENT *recBuf = (STUDENT*)FileSTUDENT->RecBuf;
  63.  
  64.             bdate BirthDay = testStudentsPool[i].BirthDay;
  65.  
  66.             memset( recBuf, 0, sizeof(STUDENT) );
  67.             // если бы в TStudent были бы атрибуты типа db_lmoney, необходимо
  68.             // было бы этим атрибутам присвоить значение DB_LMONEY_ZERO
  69.  
  70.             strcpy(recBuf->FirstName, testStudentsPool[i].FirstName );
  71.             strcpy(recBuf->SecondName, testStudentsPool[i].SecondName );
  72.             strcpy(recBuf->LastName, testStudentsPool[i].LastName );
  73.             recBuf->Birthday = BirthDay;
  74.  
  75.             // Обратите внимание, StudentID остался равным 0
  76.             *stat = bfOp(FileSTUDENT, Binsert);
  77.         }
  78.     }
  79. }
  80.  
  81. int countLastName (char *LastName)
  82. {
  83.     int counter = 0;
  84.     STUDENT *recBuf = (STUDENT*)FileSTUDENT->RecBuf;
  85.     SKF_STUDENT_LASTNAMEFIRSTNAMESECONDNAME(LastName, NULL, NULL);
  86.  
  87.     for( int st=bfGet(FileSTUDENT, BgetF); !st; st=bfGet(FileSTUDENT, BgetN ) )
  88.     {
  89.             counter = counter + 1;
  90.     }
  91.     return counter;
  92. }
  93.  
  94. void findPopularLastName()
  95. {
  96.     int countPopularLastName = 0;
  97.     char PopularLastName[51];
  98.  
  99.     set<string> LastNameList;
  100.    
  101.     STUDENT *recBuf = (STUDENT*)FileSTUDENT->RecBuf;
  102.     SKF_STUDENT_LASTNAMEFIRSTNAMESECONDNAME(NULL, NULL, NULL);
  103.  
  104.     for( int st=bfGet(FileSTUDENT, BgetF); !st; st=bfGet(FileSTUDENT, BgetN ) )
  105.     {
  106.         LastNameList.insert(string(recBuf->LastName));
  107.     }
  108.    
  109.     for (auto it = LastNameList.begin(); it != LastNameList.end(); ++it)
  110.     {
  111.         char tLastName[51];
  112.         strcpy(tLastName, it->c_str());
  113.        
  114.         int tCount = countLastName(tLastName);
  115.         if (countPopularLastName < tCount)
  116.         {
  117.             countPopularLastName = tCount;
  118.             strcpy(PopularLastName, it->c_str());
  119.         }
  120.     }
  121.     //выводим самое популярное
  122.     meswin(PopularLastName);
  123. }
  124.  
  125. void findAndEditById ()
  126. {
  127.     int32 ID = 0;
  128.     if ( invwin("Введите ID", FT_LONG, &ID, 0, 8) != ESC )
  129.     {
  130.         STUDENT buf;
  131.         memset( &buf, 0, sizeof( STUDENT ));
  132.  
  133.         if(!FindSTUDENT(ID, &buf))
  134.         {
  135.             char tFio[153];
  136.             strcpy(tFio, buf.FirstName);
  137.             strcat(tFio, " ");
  138.             strcat(tFio, buf.SecondName);
  139.             strcat(tFio, " ");
  140.             strcat(tFio, buf.LastName);
  141.  
  142.             meswin(tFio);
  143.             bdate tBdate;
  144.             Tomorrow(&buf.Birthday, &tBdate);
  145.  
  146.             int size = 0;
  147.             TRsbFreePtr<char> BDateVal(valtostr(&tBdate, 10, 0, FT_DATE, &size, ON));
  148.             sprintf( tFio, (char*)BDateVal);
  149.             meswin(tFio);
  150.         }
  151.         else
  152.         {
  153.             meswin("Студент с заданным ID не найден");
  154.         }
  155.     }
  156. }
  157.  
  158.  
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement