public
anonymous / structStud.c
Last active

  • Download Gist
structStud.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
typedef struct
{
char fname[10];
char lname[15];
float perGrade;
char letGrade;
}STUD;
typedef struct
{
char fname[10];
char lname[15];
float perGrade;
char letGrade;
}TEMP;
void enterStudents(STUD [], TEMP[]);
void sortByGPA(STUD theClass[], int);
 
main()
{
STUD theClass[30];
int scount = 0 ;
int choice;
 
printf("What would you like to do?\n");
printf("1. Enter Students?\n");
printf("2. Sort by name?\n");
printf("3. Sort by GPA?\n");
printf("0. Exit\n");
scanf("%d",&choice);
 
switch(choice)//choices
{
case 1:enterStudents(theClass, &scount);
break;
case 2:sortByName();
break;
case 3:sortByGPA(theClass);
break;
case 0:
break;
default:printf("Invalid input!\n\n");//default choice
 
}
 
return(0);
}
 
void enterStudents(STUD theClass[], int *ptr_scount )
{
printf("\n Enter the last name or 0 to exit: ");
scanf("%14[^\n]s", theClass[*ptr_scount].lname);
fflush(stdin);
 
while(theClass[*ptr_scount].lname[0]!='0')
{
printf("\n Enter the first name or 0 to exit: ");
scanf("%9[^\n]s", theClass[*ptr_scount].fname);
fflush(stdin);
 
calcPercent(&theClass[*ptr_scount].perGrade);
calcLetter(&theClass[*ptr_scount].perGrade,
&theClass[*ptr_scount].letGrade);
 
(*ptr_scount)++;
printf("\n Enter the last name or 0 to exit: ");
scanf("%14[^\n]s", theClass[*ptr_scount].lname);
fflush(stdin);
}
}
void sortByGPA(STUD theClass[])
{
int i = 0;
 
if(theClass[i].perGrade > theClass[i+1].perGrade )
{
TEMP = theClass[i];
theClass[i] = theClass[i+1];
theClass[i+1] = TEMP;
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.