1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Morgarella [4.7K]
3 years ago
6

This program involves working with a set of discrete data (grades) and determining their average (arithmetic mean), median, and

mode. These operations are explained below.1. The average of the grades is the sum of all grades divided by the number of the grades.2. The median is the value located in middle of all grades. The grades should be ordered first. If the set contains an even number of values, the median is the average of the two middle values.3. The mode is the value that occurs most often or with the great frequency.4. The standard deviation shows how much variation exists from the average. It is calculated using the following equation: Where x1, x2, ..., xN represent the grades and µ represents the mean (average).Write a C++ program that handles any number of grades and performs the data analysis operations outlined above. Consider the following requirements.a. Read the input data from user. The program must not assume a fixed length of data; it should determine the length dynamically.b. Display the result on a standard display monitor.c. Use functions for each specific operations; for instance,double getAverage(int *grades, int size)double getMedian(int *grades, int size)int getMode(int *grades, int size)double getSd(int *grades, int size)d. If the grades have no mode, the getMode function should return -1. If the grades have more than one mode, the function should return anyone of them.e. Do not accept negative numbers for input.
Computers and Technology
1 answer:
Inga [223]3 years ago
3 0

Answer:

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

// function declarations

double getAverage(int* grades, int size);

double getMedian(int* grades, int size);

int getMode(int* grades, int size);

double getSd(int* grades, int size);

int main()

{

// Declaring variables

int size, val;

// setting the precision to two decimal places

std::cout << std::setprecision(2) << std::fixed;

// Getting the input entered by the user

cout << "How many grades you wnat to enter :";

cin >> size;

// Creating array dynamically

int* grades = new int[size];

/* Getting the inputs entered by the user

* and populate those values into array

*/

for (int i = 0; i < size;)

{

while (true)

{

cout << "Enter the grade#" << i + 1 << ":";

cin >> val;

if (val < 0)

{

cout << "** Invalid.Must be greater than zero. **" << endl;

continue;

}

else

{

grades[i] = val;

i++;

break;

}

}

}

// calling the functions

double avg = getAverage(grades, size);

double median = getMedian(grades, size);

int mode = getMode(grades, size);

double sd = getSd(grades, size);

cout << "Average :" << avg << endl;

cout << "Median :" << median << endl;

cout << "Mode :" << mode << endl;

cout << "Standard Deviation :" << sd << endl;

return 0;

}

// This function calculates the average of grades

double getAverage(int* grades, int size)

{

double sum = 0.0;

// calculating the sum of res[] array elements

for (int i = 0; i < size; i++)

{

// calculating the sum

sum += grades[i];

}

// calculating the average

double avg = sum / size;

return avg;

}

// This function calculates the median of grades

double getMedian(int* grades, int size)

{

// This Logic will Sort the Array of elements in Ascending order

int temp;

int middle;

double median;

for (int i = 0; i < size; i++)

{

for (int j = i + 1; j < size; j++)

{

if (grades[i] > grades[j])

{

temp = grades[i];

grades[i] = grades[j];

grades[j] = temp;

}

}

}

if (size % 2 == 0)

{

middle = size / 2;

median = (float)(grades[middle - 1] + grades[middle]) / 2.0;

}

else

{

middle = (size + 1) / 2;

median = grades[middle];

}

return median;

}

// This function calculates the mode of grades

int getMode(int* grades, int size)

{

int counter1 = 0, counter2, modevalue;

for (int i = 0; i < size; i++)

{

counter2 = 0;

for (int j = i; j < size; j++)

{

if (*(grades + i) == *(grades + j))

{

counter2++;

}

if (counter2 > counter1)

{

counter1 = counter2;

modevalue = *(grades + i);

}

}

}

if (counter1 > 1)

return modevalue;

else

return -1;

}

// This function calculates the standard deviation of grades

double getSd(int* grades, int size)

{

int sum_of_squares = 0, standard_deviation;

double variance;

double avg = getAverage(grades, size);

/* This loop Calculating the sum of

* square of eeach element in the array

*/

for (int i = 0; i < size; i++)

{

/* Calculating the sum of square of

* each element in the array

*/

sum_of_squares += pow((grades[i] - avg), 2);

}

// calculating the variance of an array

variance = ((double)sum_of_squares / (size - 1));

// calculating the standard deviation of an array

standard_deviation = sqrt(variance);

return standard_deviation;

}

Explanation:

You might be interested in
________ results when leisure time and available tools allow us to engage in creative acts.
natta225 [31]
Cognitive surplus results when leisure time and available tools allow us to engage in creative acts. It is a term that was introduced by Clay Shirky which pertains to the synthesis of the excess of people's energy, time and creativity leading to productivity sharing and creation.
4 0
2 years ago
Discuss FOUR challenges that have an impact on domestic tourism
shutvik [7]
Crime rate
unemployment
fluctuations
suspension of terrorism
5 0
3 years ago
Which commas is used to combine two or more cells together into one cell
AURORKA [14]
The command is Merge & Center
This command could be easily found in the toolbar of your excel.
If you execute this command in two different cells, those cells will be merged into one larger cell and the content in that cells will be placed exactly in the middle of the combined cell (measures according to combined cells' length)
5 0
3 years ago
Which selection below lists two operating systems that include BitLocker? A. Windows XP Professional and Windows 7 Professional
Leona [35]
It will be the windows 8 professional
3 0
3 years ago
Everybody at a company is assigned a unique 9 digit ID. How many unique IDs exist?
Brut [27]
If you include all zeroes, then it should be 1,000,000,000. Otherwise it’s 999,999,999.

Think of how between 0-9 theres 10 numbers, and use that logic towards 000000000-999999999
3 0
3 years ago
Other questions:
  • Shawn wants to work on a presentation. He pushes the power buttons for the computer and the monitor, but the computer fails to s
    10·1 answer
  • Emotional intelligence is a new term to describe personal traits ?
    12·1 answer
  • Explain the history of computing of mechanical era
    14·2 answers
  • Select the correct answer
    14·1 answer
  • What does lurch mean
    14·2 answers
  • Ok so I usually don’t do this but I just need an answer , on Instagram a notification popped up while I was watching someone’s s
    9·2 answers
  • Aside from human user types, there are non human user groups. Known as account types, __________ are implemented by the system t
    10·1 answer
  • What is wrong with the following code?
    11·1 answer
  • What is the working principle of computer?​
    10·1 answer
  • Select the correct answer.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!