/*********************************************** * Section : 15 * Machine No. : N * Roll No. : 19CS100XY * Name : Aritra Hazra * Assignment No : 2 * Description : Subject Marks in English Words & Absolute and Relative Grading ***********************************************/ #include int main () { int roll, attend, marks, backlog, type, errorFlag = 0; /* initialized using default absolute cut-offs */ int exCut = 90, aCut = 80, bCut = 70, cCut = 60, dCut = 50, pCut = 40; /* entering student roll-number and attendance */ printf("++ Enter Student Roll Number: "); scanf("%d", &roll); printf("++ Enter the Attendance Percentage: "); scanf("%d", &attend); /* check for poor attendance and dis-qualification */ if ( (attend < 0) || (attend > 100) ) printf("-- Error: Mistake in Attendance Record!\n"); else if (attend < 80) printf("-- The Grade of %d is: F (Shortage in Attendance!)\n", roll); else { /* attendance lie within range [80-100] */ /* entering subject marks */ printf("++ Enter Subject Marks (out of 100): "); scanf("%d", &marks); if (marks > 100) printf("-- Error: Mistake in Marks Record!\n"); else { /* marks given within range [0-100] */ printf("++ Is this marks for Supplementary / Backlog Examination? (Type '0' if NOT): "); scanf("%d", &backlog); /* option for relative grading */ printf("++ Do you want Relative Grading? (Type '0' if NOT): "); scanf("%d", &type); if (type) { /* setting cut-off marks for relative grading */ printf("++ Set Cut-off Parameters:\n"); printf("\t++ Cut-off for EX = "); scanf("%d", &exCut); printf("\t++ Cut-off for A = "); scanf("%d", &aCut); printf("\t++ Cut-off for B = "); scanf("%d", &bCut); printf("\t++ Cut-off for C = "); scanf("%d", &cCut); printf("\t++ Cut-off for D = "); scanf("%d", &dCut); printf("\t++ Cut-off for P = "); scanf("%d", &pCut); /* checking for any error in setting cut-offs during relative grading */ if (exCut > 100) { printf("-- Error: Cut-off for 'EX' is beyond Maximum Marks Limit!\n"); errorFlag = 1; } if (aCut >= exCut) { printf("-- Error: Cut-off for 'A' is not less than Cut-off for 'EX'!\n"); errorFlag = 1; } if (bCut >= aCut) { printf("-- Error: Cut-off for 'B' is not less than Cut-off for 'A'!\n"); errorFlag = 1; } if (cCut >= bCut) { printf("-- Error: Cut-off for 'C' is not less than Cut-off for 'B'!\n"); errorFlag = 1; } if (dCut >= cCut) { printf("-- Error: Cut-off for 'D' is not less than Cut-off for 'C'!\n"); errorFlag = 1; } if (pCut >= dCut) { printf("-- Error: Cut-off for 'P' is not less than Cut-off for 'D'!\n"); errorFlag = 1; } if (pCut < 0) { printf("-- Error: Cut-off for 'EX' is beyond Minimum Marks Limit!\n"); errorFlag = 1; } } /* printing grade if there is no error in the input */ if (!errorFlag) { printf("-- The Subject Marks of %d is: ", roll); /* generating the marks in English word format */ if (marks == 0) // if marks is 0 printf("Zero"); else if (marks == 100) /* if marks is 100 */ printf("Hundred"); else if (marks/10 == 1){ /* marks within 10-19 */ switch (marks%10){ /* word generation for 10-19 */ case 0: printf("Ten"); break; case 1: printf("Eleven"); break; case 2: printf("Twelve"); break; case 3: printf("Thirteen"); break; case 4: printf("Forteen"); break; case 5: printf("Fifteen"); break; case 6: printf("Sixteen"); break; case 7: printf("Seventeen"); break; case 8: printf("Eighteen"); break; case 9: printf("Nineteen"); break; } } else { /* marks other than 0, 100, 10-19 */ switch (marks/10){ /* word generation for decimal part */ case 2: printf("Twenty "); break; case 3: printf("Thirty "); break; case 4: printf("Forty "); break; case 5: printf("Fifty "); break; case 6: printf("Sixty "); break; case 7: printf("Seventy "); break; case 8: printf("Eighty "); break; case 9: printf("Ninety "); break; default: /* do nothing */ break; } switch (marks%10) { /* word generation for unitary part */ case 0: printf("\b"); break; case 1: printf("One"); break; case 2: printf("Two"); break; case 3: printf("Three"); break; case 4: printf("Four"); break; case 5: printf("Five"); break; case 6: printf("Six"); break; case 7: printf("Seven"); break; case 8: printf("Eight"); break; case 9: printf("Nine"); break; } } if (!type) printf("\n-- The Absolute Grade of %d is: ", roll); else printf("\n-- The Relative Grade of %d is: ", roll); /* provision for normal as well as backlog grades (one less than normal) */ if (marks >= exCut) (!backlog)? printf("EX\n") : printf("A\n"); else if (marks >= aCut) (!backlog)? printf("A\n") : printf("B\n"); else if (marks >= bCut) (!backlog)? printf("B\n") : printf("C\n"); else if (marks >= cCut) (!backlog)? printf("C\n") : printf("D\n"); else if (marks >= dCut) (!backlog)? printf("D\n") : printf("P\n"); else if (marks >= pCut) (!backlog)? printf("P\n") : printf("F\n"); else printf("F\n"); } } } return 0; }