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

Program 4.1. Write a program to determine the percentage of A, B, C, and F score

ID: 3822833 • Letter: P

Question

Program 4.1. Write a program to determine the percentage of A, B, C, and F scores assigned in a class Your program should input the grades into an array of scores. The maximum class size is 100 students Prompt the user to input scores. After inputting the scores into the score array, go through the array and compute the number of A, B, C, and NC scores and display the percentage of each to the user. Program Requirement: 1. Score range: A: 90-100 B: 80-89 C: 70-79 NC: 0- 69 2. You must use an array in your solution. 3. Scores are integer values and percentages should be real numbers (float) with 2 digits of precision after the decimal point. 4. There may be fewer than 100 scores. You can decide how to determine the number of scores (options to consider are: asking the user for the number of scores, prompting the user if they have more scores to enter, and asking the user to specify an invalid number (a terminator value) when they are done entering scores) Extra credit: Sort the scores from highest to lowest and display the scores in descending order. Display the scores and the letter grades. Only scores between 0 and 100 are valid. When the user enters a score, check to see if it is valid. If not, tell the user that the score is invalid and continually prompt user to enter a correct score until a valid one has been entered. Sample input: 85, 99, 50, 78, 94, 92, 82 (provided by user-you can decide how to format the input) Sample output (You can decide how to format the output)

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(int argc,char **argv)
{
int score[100];
int grade[4];
int choice;
int i=0;
do
{
    if(i==100)
    {
      printf("You have reached to maximum student records"); //bounds checking
      break;
    }
    while(1)
    {
     printf("Enter the score of %d student: ",i);
     scanf("%d",&score[i]);
     if(score[i]>100)
     {
       printf("Please enter the score between 1 to 100 "); //check for range
       continue;
     }
     else
       break;
    }
    i++;
    printf("Do you want to continue: press 1 for yes and 0 to exit. ");
    scanf("%d",&choice);
}while(choice !=0);

int n=i; //total elements in an array

memset(grade,0,sizeof(grade));

for(int j=0;j<i;j++)
{
    if(score[j]<=100 && score[j]>=90)
       grade[0]=grade[0]+1;

    if(score[j]<=89 && score[j]>=80)
       grade[1]=grade[1]+1;

    if(score[j]<=79 && score[j]>=70)
       grade[2]=grade[2]+1;

    if(score[j]<=69 && score[j]>=0)
       grade[3]=grade[3]+1;  
}

printf("Percentage of A's:%.2f%% ",(float)(((float)grade[0]/(float)i)*100));
printf("Percentage of B's:%.2f%% ",(float)(((float)grade[1]/(float)i)*100));
printf("Percentage of C's:%.2f%% ",(float)(((float)grade[2]/(float)i)*100));
printf("Percentage of NC's:%.2f%% ",(float)(((float)grade[3]/(float)i)*100));

//sorting an array in decreasing array
    for (int i = 0; i < n; ++i)

    {

        for (int j = i + 1; j < n; ++j)

        {

            if (score[i] < score[j])

            {

                int a = score[i];

                score[i] = score[j];

                score[j] = a;

            }

        }
     }

   printf("Score Grade ");
   for(int i=0;i<n;i++)
   {
     printf("%d ",score[i]);
     if(score[i]<=100 && score[i]>=90)
       printf("%c ",'A');

    if(score[i]<=89 && score[i]>=80)
       printf("%c ",'B');

    if(score[i]<=79 && score[i]>=70)
       printf("%c ",'C');

    if(score[i]<=69 && score[i]>=0)
       printf("%s ","NC");       
   }

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote