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
What is the difference between a workbook and a worksheet?
Snowcat [4.5K]
An Excel worksheet is a single spreadsheet that contains cells organized by rows and columns. A worksheet begins with row number one and column A. Each cell can contain a number, text or formula. A cell can also reference another cell in the same worksheet, the same workbook or a different workbook.
7 0
3 years ago
Read 2 more answers
Symbic Foods, a chain of fast food restaurants, has included a drop-down menu on its main Web site. With this drop-down menu, pe
sesenic [268]

Answer:

B. localization of a Web site

Explanation:

Localization of a Website or Website localization is the process and procedures of familiarize and adapting an existing website to native or local language and culture in the target market. It is the method of adapting a website into a special linguistic and cultural environment which is much more robust than just the simple translation of text.

5 0
2 years ago
OBJECTIVE QUESTIONS
oee [108]

Answer:

A modifier

Explanation:

because this modified a computer keyboard

8 0
2 years ago
In Microsoft Word you can access the _______ command from the "Mini toolbar." 
ValentinkaMS [17]
Hello, Good Works mate!

Answer: 
save as
*You can access the Save As command on the Mini Toolbar.
6 0
3 years ago
IT professionals have a responsibility to educate employees about the risks of hot spots. Which of the following are risks assoc
kodGreya [7K]

Answer:

third partying and computer hackers.

Explanation:

7 0
3 years ago
Other questions:
  • Rachel is on her way to an interview for the position of a project manager. She is trying to prepare for this interview by analy
    6·1 answer
  • Refer to the exhibit. A web designer calls to report that the web server web-s1.cisco is not reachable through a web browser. Th
    15·1 answer
  • Which protocol is used by the client for microsoft networks and file and printer sharing for microsoft networks to communicate w
    10·1 answer
  • Which language is the most popular language for writing apple os x?
    9·1 answer
  • Write a function called lucky_sevens that takes in one #parameter, a string variable named a_string. Your function #should retur
    15·1 answer
  • 1 Point
    14·1 answer
  • ____ occurs when two nodes simultaneously check a channel, determine that it is free, and begin to transmit.
    9·1 answer
  • Complete main() to read dates from input, one date per line. Each date's format must be as follows: March 1, 1990. Any date not
    10·1 answer
  • I need to send this in ASAP
    6·2 answers
  • Use the drop-down menus to describe the customize ribbon dialog box.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!