Write a program that can be used to gather statistical data about the number of
ID: 3621430 • Letter: W
Question
Write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should perform the following steps:A) Ask the user how many students were surveyed. An array of integers with this many elements should then be dynamically allocated.
B) Allow the user to enter the number of movies each student saw into the array.
C) Calculate and display the average, median, and mode of the values entered. (use the functions you wrote in problems 8 and 9 to calculate the median and mode.)
Explanation / Answer
First you need to define your variables: You will need to define a pointer to an array of integers, since the array is to be dynamically allocated You will also need an integer variable to store the number of entries I am not sure what language you are programming in (I am most familiar with C), but you will need to prompt the user for the number of entries and store their input in the integer variable you defined above. You then will dynamically allocate the memory for the array. In C this is done using the malloc function and the size of an integer * the number of entries. After this is complete, check to see that the memory has been allocated. Next, you need to allow the user to enter the contents of the array. This can be done using a loop, if you are using C, a for loop would be a good choice. As long as the index of the array is less than the number of entries obtain a value for that element of the array. After this is completed, you will need to use another loop to sum all of the values of the array and then divide this value by the number of entries to obtain an average. This can be done in a function. Judging by the problem statement, you should already have the functions to calculate the median and mode.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.