# How to create a program that calculates exam grades

The following assignment sample gives a breakdown of the processes and procedures involved in creating a program that calculates pre-finals grades. Go through it to have an idea of the kind of solutions our experts deliver to students who take academic help from us.

List of functions to be used/completed as appropriate in the program:

voidinputScores(float scores[], int *ptrArrayLength); Function to input scores

scores[] à Array of scores

ptrArrayLength: Pointer to number of scores or array elements

voidoutputScores(float scores[], intarrayLength); Function to display scores

scores[] à Array of scores

arrayLength: Number of scores (NOT pointer)

floatcalculateAverage(float scores[], intnumScores); Function to calculate score average

scores[] à Array of scores

numScores: Number of scores

voidsortScoresAscendingOrder(float scores[], intarrayLength); Function to sort scores in descending order

scores[] à Array of scores

arrayLength: Number of scores or array elements

floatcalculatePreFinalsGrade(float testAvg, float quizAvg, float progAssignAvg); Function to calculate class

average

testAvg: Test average

quizAvg: Quiz average

progAssignAvg: Programming Assignment Average

The program’s input prompts and output statements must match the sample execution below. To print a floating pointnumber with only two decimal places use the placeholder "%.2f" :

printf("The cost is %.2f ", 15.345);

Sample Execution 1:

ls10@ra> ./prog7_final.out

Enter 4 Test Scores below

Print Score 1: 96

Print Score 2: 88

Print Score 3: 75

Print Score 4: 85

Enter 10 Quiz Scores below

Print Score 1: 10

Print Score 2: 9

Print Score 3: 9

Print Score 4: 10

Print Score 5: 6

Print Score 6: 2

Print Score 7: 9

Print Score 8: 7

Print Score 9: 8

Print Score 10: 10

Enter 7 Programming Assignment Scores below

Print Score 1: 100

Print Score 2: 100

Print Score 3: 75

Print Score 4: 100

Print Score 5: 90

Print Score 6: 100

Print Score 7: 95

4 Test Scores you entered are shown below

Score 1: 96.00

Score 2: 88.00

Score 3: 75.00

Score 4: 85.00

Page 3 of 5

10 Quiz Scores you entered are shown below

Score 1: 10.00

Score 2: 9.00

Score 3: 9.00

Score 4: 10.00

Score 5: 6.00

Score 6: 2.00

Score 7: 9.00

Score 8: 7.00

Score 9: 8.00

Score 10: 10.00

7 Programming Assignment Scores you entered are shown below

Score 1: 100.00

Score 2: 100.00

Score 3: 75.00

Score 4: 100.00

Score 5: 90.00

Score 6: 100.00

Score 7: 95.00

Your Top 8 Quiz Scores to be used are:

Score 1: 10.00

Score 2: 10.00

Score 3: 10.00

Score 4: 9.00

Score 5: 9.00

Score 6: 9.00

Score 7: 8.00

Score 8: 7.00

Your Top 7 Programming Assignment Scores to be used are:

Score 1: 100.00

Score 2: 100.00

Score 3: 100.00

Score 4: 100.00

Score 5: 95.00

Score 6: 90.00

Your Prog Assignment Average is: 97.50

Sample Execution 2:

ls10@ra> ./prog7_final.out

Have you failed to turn in any assignments, enter Y for Yes and N for No? Y

My code for program 5:

#include

#include

float calculateCharges(float);

main()

{

float car1, car2, car3;

float charge1, charge2, charge3;

float totalHours = 0.0;

float totalCharges = 0.0;

printf("Enter the hours for car 1: ");

scanf("%f", &car1);

totalHours = totalHours + car1;

charge1 = calculateCharges(car1);

totalCharges = totalCharges + charge1;

printf("Enter the hours for car 2: ");

scanf("%f", &car2);

totalHours = totalHours + car2;

charge2 = calculateCharges(car2);

totalCharges = totalCharges + charge2;

printf("Enter the hours for car 3: ");

scanf("%f", &car3);

totalHours = totalHours + car3;

charge3 = calculateCharges(car3);

totalCharges = totalCharges + charge3;

printf("\n");

printf("Car\t\tHours\t\tCharge\n");

printf("1\t\t%.1f\t\t%.2f\n", car1, charge1);

printf("2\t\t%.1f\t\t%.2f\n", car2, charge2);

printf("3\t\t%.1f\t\t%.2f\n", car3, charge3);

printf("TOTAL\t\t%.1f\t\t%.2f\n", totalHours, totalCharges);

}

float calculateCharges(float h)

{

const float MINIMUM_CHARGE = 2.0;

const float MAXIMUM_CHARGE = 10.00;

/* the garage charges 2.00 for any amount of

time up to 3 hours */

if (h<=3)

return MINIMUM_CHARGE;

/* determine how many hours past 3 hours */

h = h - 3;

/* 0.50 for each hour (or part of an hour) past 3 hours */

float additionalAmount = ceil(h) * 0.50;

float charge = MINIMUM_CHARGE + additionalAmount;

if (charge > MAXIMUM_CHARGE)

return MAXIMUM_CHARGE;

else

return charge;

}

Solution

#include

#include

voidcheckMissingAssignments();

voidinputScores(float scores[], int *ptrArrayLength);

voidoutputScores(float scores[], intarrayLength);

floatcalculateAverage(float scores[], intnumScores);

voidsortScoresAscendingOrder(float scores[], intarrayLength);

floatcalculatePreFinalsGrade(float testAvg, float quizAvg, float progAssignAvg);

main()

{

/* Declare and initialize variables */

intnumTests = 4, numQuizzes = 10, numProgAssignments = 7;

intnumDropQuizzes = 2, numDropProgAssignments = 1;

floattestAvg = 0.0, quizAvg = 0.0, progAssignAvg = 0.0, classAvg = 0.0;

floattestScores, quizScores, progAssignScores;

/* Declare and initialize pointer variables ptrQuizzes and ptrProgAssignments */

int *ptrTests = &numTests;

/* Check for missing assignments */

checkMissingAssignments();

printf("\nEnter 4 Test Scores below\n");

inputScores(testScores, ptrTests);

printf("\nEnter 10 Quiz Scores below\n");

/* Write function call to read quiz scores */

/* Read Programming Assignment Scores */

/* Display message and write function call to read prog assignment scores */

/* Print Original Scores */

/* Display Test scores */

printf("\n4 Test Scores you entered are shown below\n");

outputScores(testScores, numTests);

/* Display Quiz Scores */

printf("\n10 Quiz Scores you entered are shown below\n");

outputScores(quizScores, numQuizzes);

/* Display message and write function call to display Programming Assignment Scores */

/* Sort Scores in Descending order: Needed to drop lowest scores */

/* Sort Quiz scores in descending order */

sortScoresAscendingOrder(quizScores, numQuizzes);

/* Drop lowest 2 quiz scores */

printf("\nYour Top 8 Quiz Scores to be used are:\n");

outputScores(quizScores, numQuizzes-numDropQuizzes);

/* Sort Prog Assignment scores in descending order */

/* Write function call to drop lowest 1 programming assignment score */

printf("\nYour Top 7 Programming Assignment Scores to be used are:\n");

/* Calculate Averages */

/* Calculate Test Average of 4 Tests */

testAvg = calculateAverage(testScores, numTests);

printf("\nYour Test Average is: %.2f\n", testAvg);

/* Calcluate Quiz Average of Top 8 Quiz Scores */

quizAvg = calculateAverage(quizScores, numQuizzes-numDropQuizzes);

/* Multiply quiz average by 10 to convert average to the scale of 100 */

quizAvg = quizAvg * 10;

printf("Your Quiz Average is: %.2f\n", quizAvg);

/* Calcluate Average of Top 7 Programming Assignment Scores */

progAssignAvg = calculateAverage(progAssignScores, numProgAssignments-numDropProgAssignments);

printf("Your Prog Assignment Average is: %.2f\n", progAssignAvg);

printf("\n");

}

/* Function to check missing assignments */

voidcheckMissingAssignments()

{

charcheckSubmissions = '\0';

printf("Have you failed to turn in any assignments, enter Y for Yes and N for No? ");

scanf("%c", &checkSubmissions);

if(checkSubmissions == 'Y')

{

// exit(0);

}

}

/* Function to read scores into an array*/

voidinputScores(float scores[], int *ptrArrayLength)

{

int i;

/* complete the function */

//scanf("%d",scores[])

}

/* Function to print scores using array*/

voidoutputScores(float scores[], intarrayLength)

{

int i;

for (i=0; i

{

printf("Score %d: %.2f\n", i+1, scores[i]);

}

}

/* Calculate average*/

floatcalculateAverage(float scores[], intnumScores)

{

int i;

float sum = 0.0, avg = 0.0;

/* complete the function */

avg = sum/numScores;

returnavg;

}

/* Sort array in ascending order */

voidsortScoresAscendingOrder(float scores[], intarrayLength)

{

int i = 0, j=0;

floatfTemp = 0.0;

for (i = 0; i

{

for (j = 0; j < arrayLength-i-1; j++)

{

if (scores[j] < scores[j+1])

{

fTemp = scores[j];

scores[j] = scores[j+1];

scores[j+1] = fTemp;

}

}

}

}

/* Pre-finals Average */

floatcalculatePreFinalsGrade(float testAvg, float quizAvg, float progAssignAvg)

{

if (testAvg< 60 || progAssignAvg< 60)

{