Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS C PROGRAM USED TO WORK BUT THERE IS A BUG OR TWO THAT I CANT FIX. Problem Statement :In a class of 90 students,

THIS C PROGRAM USED TO WORK BUT THERE IS A BUG OR TWO THAT I CANT FIX.

Problem Statement:In a class of 90 students, the score of any student is between 60 and 100 on an exam. It is assumed that none of students scored less than 60. Use random number generator to assign score to each student in class. Write four c functions: one for random function for any range; second for computing average of one dimensional array; third for computing the median of one dimensional array; fourth for computing the standard deviation of one dimensional array; and finallycalls to these four functions to compute average, median and std deviation

#include #include #include #include #define SIZE 5 /* define constant varaible with value */ /* function PROTOTYPES */ void rand_func( int size, int beginrange, int endrange, int array[]); double average(int n, int studscore[]); int median(int n, int studscore[]); double stddeviation(int n, int studscore[], double average); int main() { printf("Program to compute avearge, median, std deviation of %d stduent scores generated ",SIZE); int beginrange = 60; int endrange = 100; int studscore[SIZE]={0}; /* call rand_func() function to generate studscore array values */ rand_func(SIZE,beginrange,endrange,studscore); printf("the studscore[0] is %d ",studscore[0]); printf("the studscore[1] is %d ",studscore[1]); printf("the studscore[2] is %d ",studscore[2]); printf("the studscore[3] is %d ",studscore[3]); printf("the studscore[4] is %d ",studscore[4]); printf(" "); // call average() function to compute average of studscore array values double ave_value = average(SIZE, studscore); printf(" the class average of %d student scores is = %f ", SIZE ,ave_value); // call median function to determine median of studscore array values int med_value = median(SIZE,studscore); printf(" the class median score of %d student scores is = %d ", SIZE ,med_value); //call stddeviation() function to compute standard deviation of studscore array values double stddev =stddeviation(SIZE, studscore,ave_value); printf(" the standard deviation of %d student scores is = %f ", SIZE ,stddev); return 0; }

// Function rand_func() to generate random numbers of size value void rand_func( int size, int beginrange, int endrange, int array[]) { /* Step#1-a) Generate seed value for rand() function using time(NULL) function */ /* C-code for generating seed for random number generator function rand()*/ /* srand() function is called only once in a C program at the top before calling rand() function */ srand( time(NULL) ); /* Step#1-b) Use rand() function to generate n random number between beginrange and endrange */ /* and store in array named array[j], with j from j=0 to j < n */ /* C-code for generating and storing random numbers in stdscore[] variable */ for ( int j = 0; j < size; j++) { /* use for loop through n times the next block of statements */ /* generate random number between beginrange and endrange and store it in array[j] */ array[j] = (1 + rand() % (endrange - beginrange) ) + beginrange ; } }

// Function average() to compute average of studscore array of values double average(int n, int studscore[]) { /* Step#3-a) sum (total) of student scores stored in studscore[] array is given by: */ /* sum = sum of all student score; we use for loop through n = 90 times the block of statements sum = sum + studscore[j] */ double sum = 0; /* define variable to hold the sum of student score */ for ( int j = 0; j < n; j++) { /* use for loop through n = size times the next block of statements */ /* add sum to studscore[j] to get new sum */ sum = sum + studscore[j]; /* this can also be written using += symbol as sum+=studscore[j]; */ } /* Step#3-b) Compute class average of student scores */ // double average_value=0; // average_value = sum/n; /* print the average of student score */ // printf("The class average of %d student scores is = %f ", n, (float) sum/n); return (float) sum/n; }

// Function median() to determine median of studscore array of values) int median(int n, int studscore[]) { int temp; /* C code to find numbers in array in an ascending order */ /* Take each array element array[j] and compare it with all array element to find the smallest */ /* and switch the smallest element with a[j] */ for (int j=0; j < n; j++) { for (int k=j+1; k < n; k++) { if(studscore[j] > studscore[k]) { temp = studscore[k]; studscore[k] = studscore[j]; studscore[j] = temp; } } } for(int j=0; j printf("The array element [%d] in ascending order is %d ",j,studscore[j]); } printf(" "); /* To find the median of class score */ // median = studscore[n/2]; // printf("The median of class scores is = %d ",studscore[n/2]); return studscore[n/2]; }

{ double sum = 0; double deviation=0; for (int j = 0; j < n; ++j) { deviation = (float) studscore[j] - average; sum += deviation*deviation; } double stddev = sqrt(sum/(n-1)); // printf("The standard deviation of student class scores = %f ",stddev); return stddev; }

OUTPUT: ====

the studscore[0] is 87

the studscore[1] is 100

the studscore[2] is 78

the studscore[3] is 99

the studscore[4] is 80

the class average of 5 student scores is = 88.800000

The array element [0] in ascending order is 78

The array element [1] in ascending order is 80

The array element [2] in ascending order is 87

The array element [3] in ascending order is 99

The array element [4] in ascending order is 100

the class median score of 5 student scores is = 87

the standard deviation of 5 student scores is = 10.329569

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Multimedia Database Systems

Authors: V.S. Subrahmanian

1st Edition

1558604669, 978-1558604667

More Books

Students also viewed these Databases questions

Question

Describe the economic model that is proposed for the operation.

Answered: 1 week ago

Question

The paleolithic age human life, short write up ?

Answered: 1 week ago