Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program In C? No arrays! You are the official score keeper for the \"C\" Bowling

ID: 3654354 • Letter: P

Question

Program In C? No arrays!

You are the official score keeper for the "C" Bowling Association (CBA). You should write a program that will:

a. Input date of game (three integers yyyy/mm/dd).

b. Input bowler's first and last name initial (two separate characters) and three scores (three integer of 0-300 ranges).

c. Calculate average for that bowler.

d. Assign stars to that bowler based on the following scale: o Avg >= 200 o Avg 170 to 199 o Avg 125 to 169 o Avg 100 to 124 o Avg < 100 4 stars 3 stars 2 stars 1 star no star

e. Output the bowlers name, avg, and number of stars earned.

f. Your program must be able to process any number of bowlers.

g. Discover which bowler had the highest average and print out his/her name, average and number of stars. (Assume there is only one bowler who had the highest average)

h. Calculate and output the average of all the bowlers and the date of game. Implement all functionalities in your main() function and name this file as b.1.c.

Explanation / Answer

#include #include #include #include typedef struct { char szName[30]; int iResults[3]; float fAverage; int iStars; } Bowler; Bowler* get_bowler(const char *cszName, const int iOne, const int iTwo, const int iThree) { Bowler *b = (Bowler *)calloc(1, sizeof(Bowler)); int iLen = cszName == NULL ? 0 : strlen(cszName); int i = 0; int iSum = 0; if (iLen) { iLen = iLen < (int)sizeof(b->szName) ? iLen : sizeof(b->szName) - 1; strncpy(b->szName, cszName, iLen); } b->iResults[0] = iOne; b->iResults[1] = iTwo; b->iResults[2] = iThree; for (;i iResults) / sizeof(int); i++) { iSum += b->iResults[i]; } b->fAverage = iSum / 3.0f; if (b->fAverage >= 200.0f) b->iStars = 4; else if (b->fAverage >= 170.0f) b->iStars = 3; else if (b->fAverage >= 125.0f) b->iStars = 2; else if (b->fAverage >= 100.0f) b->iStars = 1; else b->iStars = 0; return b; } Bowler **read_bowler(int *iBowler) { FILE *f = fopen("bowler.txt", "rt"); int i = 0; char szName[30]; Bowler **b = NULL; int iOne, iTwo, iThree; fscanf(f, "%d ", iBowler); b = (Bowler **)calloc(*iBowler, sizeof(Bowler *)); for (i = 0; i < *iBowler; ++i) { fgets(szName, sizeof(szName), f); szName[strlen(szName) -1] = 0; fscanf(f, "%d %d %d ", &iOne, &iTwo, &iThree); b[i] = get_bowler(szName, iOne, iTwo, iThree); } fclose(f); return b; } int main() { int iBowler = 0; Bowler **b = read_bowler(&iBowler); fprintf(stdout, "%-30.30s %-6.6s %s ", "Bowler", "Avg", "Stars"); fprintf(stdout, "------------------------------ ------ ----- "); for (int i = 0; i szName, b[i]->fAverage, b[i]->iStars); free(b[i]); } free(b); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote