Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- struct student {
- int code;
- char name[60];
- float gpa;
- char status[15];
- };
- struct student stds[4],max;
- void showStudent(struct student stds[],int n);
- void setStatus(struct student stds[],int n);
- struct student maxGPA( struct student arrST[]);
- float avgGPA(struct student arrST[]);
- int countCritical(struct student arrST[]);
- int main(){
- int i=0,n;
- printf("Enter your num student :");
- scanf("%d",&n);
- // n=4;
- printf("Enter new data\n");
- while (i<n){
- printf("Student%d\n",i+1);
- printf("Code: ");
- scanf("%d",&stds[i].code);fflush(stdin);
- printf("Name: ");
- gets(stds[i].name);
- printf("GPA: ");
- scanf("%f",&stds[i].gpa);
- i++;
- }
- setStatus(stds,n);
- showStudent(stds,n);
- return 0;
- }
- void showStudent( struct student stds[],int n){
- int i=0,c;
- float avg;
- max=maxGPA(stds);
- avg=avgGPA(stds);
- c=countCritical(stds);
- printf("\nAll students\n");
- while(i<n){
- printf("%d %s\tGPA= %.2f\nStatus: %s\n",stds[i].code,stds[i].name,stds[i].gpa,stds[i].status);
- i++;
- }
- printf("\nStudent Hit is %d %s\tGPA:%.2f\nStatus: %s\n",max.code,max.name,max.gpa,max.status);
- printf("\navgGPA Student is %.2f\n",avg);
- printf("\nCritical Student is %d\n",c);
- }
- void setStatus(struct student stds[],int n){
- int i=0;
- while (i<n){
- if(stds[i].gpa>=3.5){
- strcpy(stds[i].status ,"Excellent");
- }
- else if((stds[i].gpa<=3.49)&&(stds[i].gpa>=2.00)){
- strcpy(stds[i].status ,"Pass");
- }
- else if((stds[i].gpa<=1.99)&&(stds[i].gpa>=1.50)){
- strcpy(stds[i].status ,"Critical");
- }
- else if(stds[i].gpa<1.50){
- strcpy(stds[i].status ,"Fail");
- }
- i++;
- }
- }
- struct student maxGPA( struct student arrST[]){
- int i=0;
- int maxGpa, index = 0;
- while(i<4){
- maxGpa=arrST[0].gpa;
- if(maxGpa < arrST[i].gpa){
- maxGpa = arrST[i].gpa;
- index = i;
- }
- i++;
- }
- return arrST[index];
- }
- float avgGPA(struct student arrST[]){
- int i=0;
- float avg=0;
- while(i<4){
- avg=avg+arrST[i].gpa;
- i++;
- }
- avg=avg/4;
- return avg;
- }
- int countCritical(struct student arrST[]){
- int i=0,c=0;
- while (i<4){
- if((stds[i].gpa<=1.99)&&(stds[i].gpa>=1.50)){
- c++;
- }
- i++;
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement