hamaXD

Final 58 ตอนที่ 2 ข้อ2

Dec 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. typedef struct{
  5.     int d,m,y;//day,month,year
  6. }date;
  7.  
  8. /*
  9. struct a{
  10.     int d,m,y;
  11. }date;*/
  12.  
  13. typedef struct{
  14.     char name[20];
  15.     date start;
  16.     float salary;
  17. }employee;
  18.  
  19. void input(employee e[],int n){
  20.     int i=0;
  21.     while(i<n){
  22.         printf("NAME#%d :",i+1);
  23.         scanf("%s",e[i].name);  fflush(stdin);
  24.         printf("START#%d :",i+1);
  25.         scanf("%d/%d/%d",&e[i].start.d,&e[i].start.m,&e[i].start.y);
  26.     //  fflush(stdin);
  27.         printf("SALARY#%d :",i+1);
  28.         scanf("%f",&e[i].salary);
  29.         i++;
  30.     }  
  31. }
  32.  
  33. employee incsalary(employee e,float p){
  34.     e.salary = e.salary+((e.salary*p)/100);
  35.     return e;
  36. }
  37.  
  38. employee findemp(employee e[ ], int n){
  39.     employee max = e[0];
  40.     int i=0;
  41.     while(i<n){
  42.         if(e[i].start.y<max.start.y){
  43.             max = e[i];
  44.         }
  45.         else if(e[i].start.y==max.start.y){
  46.             if(e[i].start.m<max.start.m){
  47.                 max=e[i];
  48.             }
  49.             else if(e[i].start.m==max.start.m){
  50.                 if(e[i].start.d<max.start.d){
  51.                     max=e[i];
  52.                 }
  53.             }
  54.         }
  55.         i++;
  56.     }
  57.     printf("\n%s %d/%d/%d %f\n",max.name,max.start.d,max.start.m,max.start.y,max.salary);
  58.     return max; // nott foget
  59. }
  60.  
  61. employee display(employee e[ ], int n){
  62.    
  63.    
  64. }
  65. int main(){
  66.     //test
  67.    
  68.     int n=2;
  69.     float p=3.5;
  70.     employee data[n],max;
  71.     input(data,n);
  72.     int i=0;
  73.     while(i<n){
  74.         data[i]=incsalary(data[i],p);
  75.     i++;
  76.     }
  77.     display(data,n);
  78.     max=findemp(data,n);
  79.     //printf("%s %d/%d/%d %f\n",max.name,max.start.d,max.start.m,max.start.y,max.salary);
  80.    
  81.    
  82.     return 0;
  83. }
Add Comment
Please, Sign In to add comment