Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS CODE CALCULATES THE MEAN MEDIAN AND MODE OF DATA GIVEN BY USER IT IS WRITTEN IN C++ . MODIFY IT SO THAT IT SENDS

THIS CODE CALCULATES THE MEAN MEDIAN AND MODE OF DATA GIVEN BY USER IT IS WRITTEN IN C++ . MODIFY IT SO THAT IT SENDS AN ERROR MESSAGE IF THE USER ENTERS ANYTHING OTHER THAN A NUMBER AND ASKS THEM TO RE-ENTER ANOTHER NUMBER IN ITS PLACE. THE CODE ASKS THE USER FOR NUMBERS IN MAIN() AND ASKS WITH THE HELP OF A FOR LOOP

#include #include

using namespace std;

class statistical { protected: double *dataArray; int size; public: statistical(double a[], int s) { dataArray = new double[s]; for (int i = 0; i

virtual void print() = 0; };

class Mean : public statistical {

public:

Mean(double a[]=0, int s=0) :statistical(a, s) {} double mean() { double Sum = dataArray[0]; for (int i = 1; i < size; ++i) { Sum += dataArray[i]; } return Sum / size; }

void print() { cout << mean(); } };

class Median : public statistical { public: Median(double a[], int s) :statistical(a, s) {} void print() { // Allocate an array of the same size and sort it. double* Sorted = new double[size]; for (int i = 0; i < size; ++i) { Sorted[i] = dataArray[i]; }

for (int i = size - 1; i > 0; --i) { for (int j = 0; j < i; ++j) { if (Sorted[j] > Sorted[j + 1]) { double Temp = Sorted[j]; Sorted[j] = Sorted[j + 1]; Sorted[j + 1] = Temp; } } } // Middle or average of middle values in the sorted array. double Median = 0.0; if ((size % 2) == 0) { Median = (Sorted[size / 2] + Sorted[(size / 2) - 1]) / 2.0; } else { Median = Sorted[size / 2]; } delete[] Sorted; cout << Median; } };

class Mode : public statistical { public: Mode(double a[], int s) :statistical(a, s) {} void print() { int* ipRepetition = new int[size]; for (int i = 0; i < size; ++i) { ipRepetition[i] = 0; int j = 0; //bool bFound = false; while ((j < i) && (dataArray[i] != dataArray[j])) { ++j; } ++(ipRepetition[j]); } int iMaxRepeat = 0; int flag = 0; for (int i = 0; i < size; ++i) { if (ipRepetition[i] < ipRepetition[iMaxRepeat]) { iMaxRepeat = i; flag = 1; } } if(flag == 1) cout << dataArray[iMaxRepeat]; else cout << "0"; delete[] ipRepetition; } };

int main() {

int s; cout<>s; cout<>d[i]; }

Mean mean(d, s); cout << endl << "Mean is = "; mean.print(); Mode mode(d, s); cout << endl << "Mode is = "; mode.print(); Median median(d, s); cout<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago