Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program to get input of a data set of 14 double values (grades) from

ID: 3939124 • Letter: W

Question

Write a C++ program to get input of a data set of 14 double values (grades) from the standard input device (the keyboard), then calculate and report the sum and the mean of the data set, then the individual DEVIATION of each individual input with respect to the mean, the variance of the dataset, and finally the standard deviation of the data set. This problem requires you to integerate multiple things together: arrays, loops, functions. More specifically, you want to use loops to deal with input, save them to array, or calculate sum and individual deviation, and display results etc. in separate functions. A sample run. Please let me know how many grades you would like to input? 14 Input them one by one: 89 95 72 83 99 54 86 75 92 73 79 75 82 73. Enter a grade: 89 Enter a grade: 95 Enter a grade: 72 Enter a grade: 83 Enter a grade: 99 Enter a grade: 54 Enter a grade: 86 Enter a grade: 75 Enter a grade: 92 Enter a grade: 73 Enter a grade: 79 Enter a grade: 75 Enter a grade: 82 Enter a grade: 73 The sum is: a number here. The mean is: 80.5 GRADE INDIVIDUAL DEVIATION 89 8.5 95 14.5 72 -8.5 83 2.5 99 18.5 54 -26.5 86 5.5 75 -5.5 92 11.5 73 -7.5 79 -1.5 75 -5.5 82 1.5 73 -7.5 The variance is: 124.679 standard deviation: 11.166

Explanation / Answer

// C++ code

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <stdlib.h>   
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iomanip> // std::setprecision

using namespace std;


int main()
{
int totalGrades,grade;
cout << "How many grades you would like to input? ";
cin >> totalGrades;

double grades[totalGrades];

double sum = 0;
double mean = 0;
double std_deviation = 0;
double variance = 0;

for (int i = 0; i < totalGrades; ++i)
{
cout << "Enter grade: ";
cin >> grade;

grades[i] = grade;
sum = sum + grade;
}

mean = sum/totalGrades;
cout << " The sum is: " << sum << endl;
cout << "The mean is: " << mean << endl;

cout << " GRADE INDIVIDUAL DEVIATION ";
for (int i = 0; i < totalGrades; ++i)
{
cout << grades[i] << " " << (grades[i]-mean) << endl;
}

/* Compute variance and standard deviation */
for (int i = 0; i < totalGrades; i++)
{
variance = variance + pow((grades[i] - mean), 2);
}

variance = variance/totalGrades;
std_deviation = sqrt(variance);

cout << " The Variance is: " << variance << endl;
cout << "The Standard deviation is: " << std_deviation << endl;
}

/*
output:

How many grades you would like to input? 14
Enter grade: 89
Enter grade: 95
Enter grade: 72
Enter grade: 83
Enter grade: 99
Enter grade: 54
Enter grade: 86
Enter grade: 75
Enter grade: 92
Enter grade: 73
Enter grade: 79
Enter grade: 75
Enter grade: 82
Enter grade: 73

The sum is: 1127
The mean is: 80.5

GRADE INDIVIDUAL DEVIATION
89 8.5
95 14.5
72 -8.5
83 2.5
99 18.5
54 -26.5
86 5.5
75 -5.5
92 11.5
73 -7.5
79 -1.5
75 -5.5
82 1.5
73 -7.5

The Variance is: 124.679
The Standard deviation is: 11.166

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote