A set of data (test scores), can be summarized by a frequency distribution chart
ID: 675550 • Letter: A
Question
A set of data (test scores), can be summarized by a frequency distribution chart. For example, if the list of test scores is:
90 85 100 50 50 85 60 70 55 55 80 95 70 60 95
80 100 75 70 95 90 90 70 95 50 65 85 95 100 65
then the frequency distribution chart looks like the one below:
value frequency
------ ------------
100 3
95 5
90 3
85 3
80 2
75 1
70 4
65 2
60 2
55 2
50 3
a) Write a C program to input the scores above and print out the scores, five per line. Note that you should initialize the array at declaration time and also use size 1000 for the array size.
b) Sort the test scores into ascending order and output the scores, five per line.
c) Calculate and print out the frequency distribution chart as shown above.
d) Output the percentage of passing and failing test scores to the nearest tenth. Scores below 60 are failing.
e) Calculate and print out the mean of the test scores to the nearest tenth.
f) Print out the mode of the test scores.
g) The median of a list of numbers if that element such that when the numbers are arranged in ascending or descending order, half the elements lie above it and half below. This can happen only when there are an odd numbers of elements in the list. If the array contains an even number of items, the median is the average of the two numbers in the middle (to the nearest tenth). Your program should output the median of the test scores given to the nearest tenth. (Note: Your program should determine on its own whether there is an odd or even number of test scores).
Points to Remember:
Make sure you are creating a C program and not a C++ program
Each section of the assignment should be designed within its own function, passing parameters as necessary.
Please make sure to do all the parts (a-g) of the assignment
Explanation / Answer
Solution for parts a,b,c,d, and f
#include <stdio.h>
#include<stdlib.h>
void printTestScores(int scores[], int noOfScores);
void sort(int scores[], int noOfScores);
void printFrequencyTable(int testScores[], int noOfScores);
void printPassingFailingGrades(int scores[], int noOfScores);
int greatestFrequencyScore = 0;
int main(void) {
//a) Write a C program to input the scores above and print out the scores, five per line. Note that you should initialize the array at declaration time and also use size 1000 for the array size.
int noOfScores = 0;
int scores[1000];
//read scores from user
printf("Enter test scores (Enter a negative value to quit): ");
int num;
while(num >= 0) {
scanf("%d", &num);
if(num >= 0)
scores[noOfScores++] = num;
}
printf(" Test scores entered by user ");
printTestScores(scores, noOfScores);
//b) Sort the test scores into ascending order and output the scores, five per line.
sort(scores, noOfScores);
printf(" Sorted test scores ");
printTestScores(scores, noOfScores);
//c) Calculate and print out the frequency distribution chart as shown above.
printFrequencyTable(scores, noOfScores);
//d) Output the percentage of passing and failing test scores to the nearest tenth. Scores below 60 are failing.
printPassingFailingGrades(scores, noOfScores);
//f) Print out the mode of the test scores.
}
void printTestScores(int scores[], int noOfScores) {
int i;
for (i = 0; i < noOfScores; i++)
{
printf("%d ",scores[i]);
if((i+1) % 5 == 0)
printf(" ");
}
printf(" ");
}
void sort(int scores[], int noOfScores) {
int i = 0, j = 0;
int temp;
for (i = 0; i < noOfScores; i++) {
for (j = 0; j < noOfScores-1; j++) {
if(scores[j+1] < scores[j]) {
temp = scores[j];
scores[j] = scores[j+1];
scores[j+1] = temp;
}
}
}
}
void printFrequencyTable(int testScores[], int noOfScores) {
int i , j;
int frequency[noOfScores];
int scores[noOfScores]; //this is max limit
int index = 0;
for (i = 0; i < noOfScores; i++)
{
frequency[i] = 0;
scores[i] = 0;
//printf testScores [i], frequency ;
}
for (i = 0; i < noOfScores; i++)
{
for (j = 0; j < index; j++) {
if(testScores[i] == scores[j]) {
frequency[j] = frequency[j]+1;
break;
}
}
//first time
if(j == index) {
frequency[index] = frequency[index]+1;
scores[index] = testScores[i];
index++;
}
}
greatestFrequencyScore = 0;
printf(" Value Frequency ");
printf(" ------ ---------- ");
int freq = 0;
for (j = index-1; j >=0; j--) {
printf("%d %d ",scores[j], frequency[j]);
if(frequency[j] > freq ) {
freq = frequency[j];
greatestFrequencyScore = scores[j];
}
}
printf(" ");
printf(" ");
}
void printPassingFailingGrades(int scores[], int noOfScores)
{
double passingscores = 0;
double failingscores = 0;
int i;
for (i = 0; i <= noOfScores - 1; i++) {
if (scores[i] >= 60)
passingscores++;
else if (scores[i] < 60)
failingscores++;
}
double perPass = (passingscores * 100 / noOfScores);
double perFail = (failingscores * 100 / noOfScores);
printf ("Percentage of passing scores = %d (rounded) ", (int)round(perPass));
printf ("Percentage of failing scores = %d (rounded) ", (int)round(perFail));
printf(" ");
}
//mode is calculated in frequency table generation
void printMode() {
printf ("Mode of test scores = %d ", greatestFrequencyScore);
}
-------output-----------------
Enter test scores (Enter a negative value to quit):
90 85 100 50 50 85 60 70 55 55 80 95 70 60 95
80 100 75 70 95 90 90 70 95 50 65 85 95 100 65
-1
Test scores entered by user
90 85 100 50 50
85 60 70 55 55
80 95 70 60 95
80 100 75 70 95
90 90 70 95 50
65 85 95 100 65
Sorted test scores
50 50 50 55 55
60 60 65 65 70
70 70 70 75 80
80 85 85 85 90
90 90 95 95 95
95 95 100 100 100
Value Frequency
------ ----------
100 3
95 5
90 3
85 3
80 2
75 1
70 4
65 2
60 2
55 2
50 3
Percentage of passing scores = 83 (rounded)
Percentage of failing scores = 17 (rounded)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.