Write a program using c++ that: includes a function that reads integers consisting of students’ test scores in the range of 0-200 from a file into a one-dimensional array of size 30 includes a function to calculate the mean (add all the scores and divide by the number of scores) includes a function to calculate the median (sort the scores and then find the score in the middle—if there is an odd number of scores, the median is the middle score; otherwise, it is the average of the two middle scores) includes a function to calculate the mode (most frequently occurring score) includes a function to calculate the standard deviation includes a function to determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, 175-200 and output each score range followed by the number of students within that range includes a function to print everything to an output file   Clearly identify all output. Do not use global variables. Your main function should consist primarily of function calls.   Use the following data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189   Here is the code so far: //main.cpp #include //header files for cin/cout functions #include //header file for ifstream  #include //header file for sort using namespace std; //function that reads integers from a file  //into a one-dimensional array of size 30 void readArray(int arr[30],int n){  cout<<"The size of array is : "<>x) //if the file is open     {         arr[n] = x;          n++;     }     File.close();     //calling function     readArray(arr,n);     calculateMean(arr,n);     calculateMedian(arr,n);          return 0; } //end of main function

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 44SA
icon
Related questions
Question

I was asked to repost the question to get the other parts solved:

Write a program using c++ that:

  1. includes a function that reads integers consisting of students’ test scores in the range of 0-200 from a file into a one-dimensional array of size 30
  2. includes a function to calculate the mean (add all the scores and divide by the number of scores)
  3. includes a function to calculate the median (sort the scores and then find the score in the middle—if there is an odd number of scores, the median is the middle score; otherwise, it is the average of the two middle scores)
  4. includes a function to calculate the mode (most frequently occurring score)
  5. includes a function to calculate the standard deviation
  6. includes a function to determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, 175-200 and output each score range followed by the number of students within that range
  7. includes a function to print everything to an output file

 

Clearly identify all output. Do not use global variables. Your main function should consist primarily of function calls.

 

Use the following data:

76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189

 

Here is the code so far:

//main.cpp

#include<iostream> //header files for cin/cout functions
#include<fstream> //header file for ifstream 
#include <algorithm> //header file for sort

using namespace std;

//function that reads integers from a file 
//into a one-dimensional array of size 30
void readArray(int arr[30],int n){
 cout<<"The size of array is : "<<n<<endl;
 cout<<"Element of Array is :"<<endl;
 for(int i=0;i<n;i++)
    {
        cout << arr[i] << " ";
    }  
}

//function to calculate and print the mean
void calculateMean(int arr[30],int n){
 int sum=0;
 for(int i=0;i<n;i++)
    {
        sum=sum+arr[i];
    } 
 cout<<"\n\nMean is:"<<(sum/n)<<endl; 
}

//function to calculate and print the median
void calculateMedian(int arr[30], int n) 

 float median;
    // First we sort the array 
    sort(arr, arr + n); 
    cout<<"\nSorted Array is"<<endl;
    for(int i=0;i<n;i++)
    {
        cout << arr[i] << " ";
    }  
  
    // check for even case 
    if (n % 2 != 0) 
         median=arr[n / 2]; 
  
    median=(arr[(n - 1) / 2] + arr[n / 2]) / 2.0; 
    cout<<"\n\nMedian is :"<<median<<endl;

//start of main function
int main()
{    
    int n = 0,x; 
    int arr[30];
    
    ifstream File;
    File.open("file.dat");
    if(!File.is_open()) //if the file is not open output
    {
        cout<<"It failed"<<endl;
        return 0;
    }

    while(File>>x) //if the file is open
    {
        arr[n] = x; 
        n++;
    }
    File.close();
    //calling function
    readArray(arr,n);
    calculateMean(arr,n);
    calculateMedian(arr,n);
    
    return 0;
} //end of main function

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning