Question
NOTE: I have covered all the test cases .. Please let me know if you find any issue, i will try to fix it ASAP.
NOTE:
I have covered all the test cases .. Please let me know if you find any issue, i will try to fix it ASAP.
OUTPUT:
--------------
[root@localhost chegg]# ./a.out 0.0 Student achieved 0.00 which is a FAIL condition 100.0 Student achieved 100.00 which is a PASS condition 101 Invalid Input 65.99 Student achieved 65.99 which is a PASS condition 54.5 Student achieved 54.50 which is a PASS condition 54.4 Student achieved 54.40 which is a FAIL condition -23 Invalid Input A+ Student achieved 95.00 which is a PASS condition A Student achieved 85.00 which is a PASS condition B+ Student achieved 77.00 which is a PASS condition b Invalid Input B Student achieved 72.00 which is a PASS condition C+ Student achieved 67.00 which is a PASS condition C Student achieved 62.00 which is a PASS condition D+ Invalid Input D Student achieved 57.00 which is a PASS condition D Student achieved 57.00 which is a PASS condition F Student achieved 50.00 which is a FAIL condition I Special Situation : I (Incomplete) Q Special Situation : Q(Withdrawal after drop/refund date) AU Special Situation : AU (Audit) DNA Special Situation : DNA (Did not attend) I/P Special Situation : I/P (In Progress) Hello Invalid Input 80 70 65 80 60 Student achieved 71.00 which is a PASS condition 80 90 50 Student achieved 44.00 which is a FAIL condition -20 20 50 105 invalid input x Invalid Input X [root@localhost chegg]#
---------------------------------------------
Code:
------------
[root@localhost chegg]# cat grade.c #include
int grade(char *s) {
if (strcmp (s, "A+") == 0) return 95; else if (strcmp (s, "A") == 0) return 85; else if (strcmp (s, "B+") == 0) return 77; else if (strcmp (s, "B") == 0) return 72; else if (strcmp (s, "C+") == 0) return 67; else if (strcmp (s, "C") == 0) return 62; else if (strcmp (s, "D") == 0) return 57; else if (strcmp (s, "F") == 0) return 50; else return -1; } int checkOption (char *input) { if (strchr (input, '.') != NULL) return 1; else if (strchr (input, ' ') != NULL) return 2; else return 3; }
float getAvrage(char *str) { float total = 0.0; float no; char *tok = strtok(str, " "); while (tok) { no = atoi (tok); if (no< 0 || no >100) return -1; total = total + no; tok = strtok (NULL, " "); }
return total/5; }
int specialCase (char *str) { if (strcmp (str, "I") == 0) { printf ("Special Situation : I (Incomplete) "); return 1; } else if (strcmp (str, "Q") == 0) { printf ("Special Situation : Q(Withdrawal after drop/refund date) "); return 1; } else if (strcmp (str, "AU") == 0) { printf ("Special Situation : AU (Audit) "); return 1; } else if (strcmp (str, "DNA") == 0) { printf ("Special Situation : DNA (Did not attend) "); return 1; } else if (strcmp (str, "I/P") == 0) { printf ("Special Situation : I/P (In Progress) "); return 1; } return -1; }
int main() {
char input[50] = {'\0'}; int option = 0; float no = 0.0; char tmp;
while (1) { scanf ("%[^ ]s", input); //printf ("Input is %s ", input);
if (input[0] == 'X') { break; } option = checkOption (input); // printf (" option is %d ", option); if (option == 1) { no = atof(input); if (no<0.0 || no>100) { printf ("Invalid Input "); memset (input, '\0', sizeof (input)); fflush (stdin); scanf ("%c",&tmp); continue; } } else if (option == 2) { no = (float) getAvrage (input); if (no == -1) { printf ("invalid input "); memset (input, '\0', sizeof (input)); fflush (stdin); scanf ("%c",&tmp); continue; } // printf ("average %f ", no); } else if (option == 3) { no = (float) grade (input); if (no == -1) { if (specialCase(input) == 1) { memset (input, '\0', sizeof (input)); fflush (stdin); scanf ("%c",&tmp); continue; } else { printf ("Invalid Input "); memset (input, '\0', sizeof (input)); fflush (stdin); scanf ("%c",&tmp); continue; } } }
printf ("Student achieved %0.2f which is a ", no); if (no >= 54.50) printf ("PASS condition "); else printf ("FAIL condition ");
memset (input, '\0', sizeof (input)); fflush (stdin); scanf ("%c",&tmp); }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started