Skip to content

Instantly share code, notes, and snippets.

Created November 20, 2012 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4121983 to your computer and use it in GitHub Desktop.
Save anonymous/4121983 to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment