Advertisement
hamaXD

struct have fuc guess!!! but use it GOOD!!

Nov 24th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.    
  4. struct student {
  5.     int code;
  6.     char name[60];
  7.     float gpa;
  8.     char status[15];
  9. };
  10. struct student stds[4],max;
  11.  
  12.  
  13. void showStudent(struct student stds[],int n);
  14. void setStatus(struct student stds[],int n);
  15. struct student maxGPA( struct student arrST[]);
  16. float avgGPA(struct student arrST[]);
  17. int countCritical(struct student arrST[]);
  18.  
  19.  
  20. int main(){
  21.    
  22.  
  23.     int i=0,n;
  24.     printf("Enter your num student :");
  25.     scanf("%d",&n);
  26. //  n=4;
  27.     printf("Enter new data\n");
  28.    
  29.     while (i<n){
  30.         printf("Student%d\n",i+1);
  31.         printf("Code: ");
  32.         scanf("%d",&stds[i].code);fflush(stdin);
  33.         printf("Name: ");
  34.         gets(stds[i].name);
  35.         printf("GPA: ");
  36.         scanf("%f",&stds[i].gpa);
  37.         i++;
  38.     }
  39.     setStatus(stds,n);
  40.     showStudent(stds,n);
  41.    
  42.    
  43.     return 0;
  44. }
  45.  
  46. void showStudent( struct student stds[],int n){
  47.  
  48.     int i=0,c;
  49.     float avg;
  50.    
  51.     max=maxGPA(stds);
  52.     avg=avgGPA(stds);
  53.     c=countCritical(stds);
  54.     printf("\nAll students\n");
  55.     while(i<n){
  56.         printf("%d %s\tGPA= %.2f\nStatus: %s\n",stds[i].code,stds[i].name,stds[i].gpa,stds[i].status);
  57.         i++;
  58.     }
  59.     printf("\nStudent Hit is %d %s\tGPA:%.2f\nStatus: %s\n",max.code,max.name,max.gpa,max.status);
  60.     printf("\navgGPA Student is %.2f\n",avg);
  61.     printf("\nCritical Student is %d\n",c);
  62.    
  63. }
  64.  
  65. void setStatus(struct student stds[],int n){
  66.     int i=0;
  67.     while (i<n){
  68.         if(stds[i].gpa>=3.5){
  69.             strcpy(stds[i].status ,"Excellent");
  70.         }
  71.         else if((stds[i].gpa<=3.49)&&(stds[i].gpa>=2.00)){
  72.             strcpy(stds[i].status ,"Pass");
  73.         }
  74.         else if((stds[i].gpa<=1.99)&&(stds[i].gpa>=1.50)){
  75.             strcpy(stds[i].status ,"Critical");
  76.         }
  77.         else if(stds[i].gpa<1.50){
  78.             strcpy(stds[i].status ,"Fail");
  79.         }
  80.     i++;
  81.     }
  82. }
  83. struct student maxGPA( struct student arrST[]){
  84.     int i=0;
  85.     int maxGpa, index = 0;
  86.     while(i<4){
  87.         maxGpa=arrST[0].gpa;
  88.         if(maxGpa < arrST[i].gpa){
  89.             maxGpa  = arrST[i].gpa;
  90.             index = i;
  91.         }
  92.     i++;
  93.     }
  94.     return arrST[index];
  95. }
  96.  
  97. float avgGPA(struct student arrST[]){
  98.     int i=0;
  99.     float avg=0;
  100.     while(i<4){
  101.         avg=avg+arrST[i].gpa;
  102.     i++;
  103.     }
  104.     avg=avg/4;
  105.     return avg;
  106. }
  107.  
  108. int countCritical(struct student arrST[]){
  109.     int i=0,c=0;
  110.     while (i<4){
  111.         if((stds[i].gpa<=1.99)&&(stds[i].gpa>=1.50)){
  112.             c++;
  113.         }
  114.        
  115.     i++;
  116.     }
  117.     return c;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement