daily pastebin goal
25%
SHARE
TWEET

điểm phần tăng dần 3/3

0945928233 Jun 14th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define N 100
  4.  
  5. typedef struct
  6. {
  7.     float diem1 , diem2 , diem3 ;
  8.    
  9. }diemsinhvien ;
  10.  
  11. typedef struct
  12. {
  13.     int masv ;
  14.     char tensv [N] ;
  15.     diemsinhvien diem ;
  16.    
  17. }sinhvien ;
  18.  
  19. FILE *f ;
  20. sinhvien sv ;
  21. int const size=sizeof(sinhvien);
  22. void themmoi ( )
  23. {
  24.     int them ;
  25.     scanf ( "%d\n" , &them ) ;
  26.     int sosv = 1 ;                         //  0 thì dúng hon co mà thích d? 1 //
  27.     f = fopen ( "B17DCAT089.bin", "rb" );
  28.         while ( fread ( &sv , size , 1 , f ) == 1 )
  29.             sosv++;
  30.     fclose (f) ;
  31.     int i;
  32.     f = fopen ( "B17DCAT089.bin" , "ab" ) ;
  33.     for ( i = sosv ; i < sosv + them  ; i++ )
  34.     {
  35.         sv.masv = i ;
  36.         gets ( sv.tensv ) ;
  37.         scanf ("%f%f%f\n" , &sv.diem.diem1 , &sv.diem.diem2 , &sv.diem.diem3 ) ;
  38.         fwrite ( &sv , size , 1 ,f) ;
  39.     }
  40.     fclose (f) ;
  41.     printf ( "%d\n" , them ) ;
  42. }
  43.  
  44. void capnhat (  )
  45. {
  46.     sinhvien svsua ;
  47.     scanf ( "%d\n" , &svsua.masv ) ;
  48.     gets ( svsua.tensv ) ;
  49.     scanf ( "%f %f %f" , &svsua.diem.diem1 , &svsua.diem.diem2 , &svsua.diem.diem3 ) ;
  50.     f = fopen ( "B17DCAT089.bin" , "rb+") ;
  51.     rewind (f) ;
  52.     while ( fread ( &sv , size , 1 , f ) == 1)
  53.     {
  54.         if ( sv.masv == svsua.masv )
  55.         {
  56.             fseek ( f , - size , SEEK_CUR );
  57.             fwrite ( &svsua , size , 1 , f ) ;
  58.             break ;
  59.         }
  60.     }
  61.     fclose (f) ;
  62.     printf ( "%d" , svsua.masv ) ;
  63. }
  64.  
  65. void dssv ()
  66. {
  67.     f = fopen ( "B17DCAT089.bin"  , "rb" ) ;
  68.     rewind ( f ) ;
  69.     while ( fread ( &sv , size , 1 ,f ) == 1)
  70.     {
  71.        
  72.         if ( sv.diem.diem1 < sv.diem.diem2 && sv.diem.diem2 < sv.diem.diem3 )
  73.         {
  74.             printf ( "%d %s " , sv.masv , sv.tensv )  ;
  75.             printf ( "%.1f %.1f %.1f \n"  , sv.diem.diem1 , sv.diem.diem2 , sv.diem.diem3 ) ;
  76.         }
  77.        
  78.     }
  79.     fclose ( f ) ;
  80.    
  81. }
  82. int main ()
  83. {
  84.     int chucnang ;
  85.     scanf ( "%d" , &chucnang ) ;
  86.     switch ( chucnang )
  87.     {
  88.         case 1 : themmoi () ;
  89.         break ;
  90.         case 2 : capnhat () ;
  91.         break ;
  92.         case 3 : dssv ();
  93.         default : break;
  94.     }
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top