Created
November 20, 2012 23:36
-
-
Save anonymous/4122026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include<stdio.h> | |
#include<stdlib.h> | |
#define NUM_OF_LABS 1 //Make sure to change these back to 8 & 3 | |
#define NUM_OF_EXAMS 1 | |
#define labWeightScore .4f | |
#define examWeightScore .4f | |
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 calcPercent(float *); | |
void calcLetter(float, char *); | |
void calcExams(float *); | |
void calcLabs(float *); | |
void calcFinal(float *); | |
void enterStudents(STUD [], TEMP[]); | |
void sortByName(void); | |
void sortByGPA(STUD theClass[], int); | |
void writeToScreen(); | |
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 calcPercent(float * ptr_perGrade) | |
{ | |
float labs = 0; | |
float exams = 0; | |
float final = 0; | |
calcLabs(&labs); | |
calcExams(&exams); | |
calcFinal(&final); | |
*ptr_perGrade = labs + exams + final; | |
fflush(stdin); //Extra fflush for getting rid of line return error. | |
} | |
void calcLabs(float * ptr_labs) //Calculate labs scores and averages. | |
{ | |
int labCnt = 0; | |
float labScore = 0; | |
float currentLab = 0; | |
while (labCnt < NUM_OF_LABS) | |
{ | |
labCnt++; | |
printf("Enter score for lab %d: ", labCnt); | |
scanf("%f", ¤tLab); | |
labScore = labScore + currentLab; | |
} | |
labScore = labScore / labCnt; | |
*ptr_labs = labScore * .40f; //calculate weighted average. | |
} | |
void calcExams(float * ptr_exams) | |
{ | |
int examCnt = 0; | |
float examScore = 0; | |
float currentExam = 0; | |
while (examCnt < NUM_OF_EXAMS) | |
{ | |
examCnt++; | |
printf("Enter score for exam %d: ", examCnt); | |
scanf("%f", ¤tExam); | |
examScore += currentExam; | |
} | |
examScore = examScore / NUM_OF_EXAMS; | |
*ptr_exams = examScore * examWeightScore; //calculate weighted average. | |
} | |
void calcFinal(float * ptr_final) | |
{ | |
float finalScore; | |
printf("Enter score for Final exam: "); | |
scanf("%f", &finalScore); | |
*ptr_final = finalScore * .2f; //calculate weighted average. | |
} | |
void calcLetter(float * ptr_perGrade, char * ptr_letGrade) //Calculate Letter grade | |
{ | |
if (*ptr_perGrade >= 94 && *ptr_perGrade <= 100) | |
{ | |
*ptr_letGrade = 'A'; | |
} | |
else | |
{ | |
if (*ptr_perGrade >= 85 && *ptr_perGrade <= 93) | |
{ | |
*ptr_letGrade = 'B'; | |
} | |
else | |
{ | |
if (*ptr_perGrade >= 75 && *ptr_perGrade <= 84) | |
{ | |
*ptr_letGrade = 'C'; | |
} | |
else | |
{ | |
if (*ptr_perGrade > 65 && *ptr_perGrade <= 74) | |
{ | |
*ptr_letGrade = 'D'; | |
} | |
else | |
{ | |
if (*ptr_perGrade < 65) | |
{ | |
*ptr_letGrade = 'F'; | |
} | |
} | |
} | |
} | |
} | |
} | |
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 sortByName() | |
{ | |
if () | |
{ | |
} | |
} | |
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; | |
} | |
} | |
void writeToScreen() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment