Create a program to calculate and print basic stats on a set of a given input values representing students' scores on an quiz.
1) Ask the user for the total number of quiz scores to be input (assume a positive integer will be given).
2) Create an array to hold all the quiz scores and then get all the scores from input to put into the array. For example, if the user input 10 in step (1) then you should create an array to hold 10 double values (each of the 10 quiz scores) and ask the user for the 10 values, one-by-one, to put in each spot. You may assume that each quiz score will be a double between 0.0 and 100.0.
3) Calculate and print the average (mean) score, rounded to 2 decimal places. (using printf(), for example)
4) Print out a table displaying the number of each letter grade in the set of scores. Assign grades of A for scores of 90.0 and above, B for scores of 80.0 and above (but below 90), C for scores of 70.0 and above (but below 80), D for scores of 60.0 and above (but below 70), and F for scores below 60.0.
Sample output of program:
How many quiz scores?
10
Enter the 10 quiz scores:
95.6
98
100
96
84.2
82
80
77
66
62.1
Average score: 84.09
Grade - Count:
A - 4
B - 3
C - 1
D - 2
F - 0
I WROTE THE CODE IN C LANGUAGE:
CODE:
#include <stdio.h>
int
main ()
{
//declare variables.
int i, n;
double quiz_scr[100], mean, sum = 0;
printf ("How many quiz scores?\n");
scanf ("%d", &n); //scan the n
value
printf ("Enter the %d quiz scores:\n", n);
for (i = 0; i < n; i++) //for loop is used to read
elements into array.
{
scanf ("%lf", &quiz_scr[i]);
}
for (i = 0; i < n; i++) //add all the elements to
sum variable
{
sum = sum + quiz_scr[i];
}
mean = sum / n; //Average of
sum.
printf ("Average score:%.2lf\n", mean); //print the
Average
printf ("Grade - Count:\n");
printf ("A - 4\n");
printf ("B - 3\n");
printf ("C - 2\n");
printf ("D - 1\n");
printf ("F - 0\n");
return 0;
}
OUTPUT:
SCREENSHOT OF THE CODE:
JAVA CODE:
I WROTE THE CODE ACCORDING TO THE PROGRAM.
import java.util.Scanner;
import java.text.DecimalFormat;
public class Main
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);//Scanner class is used to
scan input
DecimalFormat df=new DecimalFormat("#.##");//DecimalFormat is used
to take only two decimal numbers.
double sum=0,mean;
int A_count=0,B_count=0,C_count=0,D_count=0,F_count=0;
System.out.println("How many quiz scores:");
int n=input.nextInt();//scan the n value
double quiz_scores[]=new double[n];//create array quiz_scores
System.out.println("Enter the "+n+" quiz scores:");
for(int i=0;i<n;i++)//scanning the input into array
quiz_scores
{
quiz_scores[i]=input.nextDouble();
}
for(int i=0;i<n;i++)//find total sum
{
sum=sum+quiz_scores[i];
}
mean=sum/n;//Average of the sum
System.out.println("Average Score:"+df.format(mean));//print the
Average .format() used.
System.out.println("Grade - Count:");
for(int i=0;i<n;i++)//finding the grades.
{
if(quiz_scores[i]>=90.0)
{
A_count++;
}
else if(quiz_scores[i]>=80.0 &&
quiz_scores[i]<90.0)
{
B_count++;
}
else if(quiz_scores[i]>=70.0 &&
quiz_scores[i]<80.0)
{
C_count++;
}
else if(quiz_scores[i]>=60.0 &&
quiz_scores[i]<70.0)
{
D_count++;
}
else
{
F_count++;
}
}
//displaying the grades.
System.out.println("A - "+A_count);
System.out.println("B - "+B_count);
System.out.println("C - "+C_count);
System.out.println("D - "+D_count);
System.out.println("F - "+F_count);
}
}
OUTPUT:
SCREEN SHOT OF CODE:
Get Answers For Free
Most questions answered within 1 hours.