CECS 275  Program 3

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (5 votes)

Problem:

You are to create a C++ class for performing some basic statistics on a data set of integers. The data set must have at least one element and up to 100,000,000. The statistics to be computed are

  • mean of the data set,
  • minimum value of the data set,
  • maximum value of the data set,
  • sample variance of the data set,
  • sample standard deviation of the data set,
  • and the median value of the data set.

 

All data of the data set must be held in memory in an array. The array size is to be entered from the keyboard as the program runs. The program must check that the value entered falls between 1 and 100,000,000, inclusive. The program must read the name of the file containing the data set from the keyboard. And the program must ask the user if they want the data set printed as table. If yes then the data is printed in rows of 10 with width 8. Any other response is assumed as “no” and the data set prints in one column with width 8.

 

If the user selects to output in table format, print a row of 80 ‘=’ before the first row and after the last row.

 

The DataSet class produces output only in PrintAll(bool table) and LoadData(std::ifstream &in);. See the class declaration on the last page of this document.

 

 

 

 

 

 

 

 

 

 

 

 

 

Sample run in table format.

 

This program calculates several basic statistics for a data set of integers of any size > 0 && 100,000,000

Enter file name:data.txt

Enter an integer number at least as big as the data set:89789

Do you want to print the data set in a table(Y/N):y

 

 

Data set size = 28

 

================================================================================

9      12      20      22      23      23      30      34      34      37

39      45      45      51      54      65      67      67      67      74

78      78      88      91      95      98      99     100

================================================================================

 

mean = 55.1786

min = 9

max = 100

sample variance = 828.7447

sample standard deviation = 28.7879

median = 52.5000

Output complete

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Sample run in column format.

 

This program calculates several basic statistics for a data set of integers of any size > 0 && 100,000,000

Enter file name:data.txt

Enter an integer number at least as big as the data set:67

Do you want to print the data set in a table(Y/N):n

 

 

Data set size = 28

 

9

12

20

22

23

23

30

34

34

37

39

45

45

51

54

65

67

67

67

74

78

78

88

91

95

98

99

100

 

 

mean = 55.1786

min = 9

max = 100

sample variance = 828.7447

sample standard deviation = 28.7879

median = 52.5000

Output complete

 

The DataSet class declaration. You my not change anything about or add anything to it.

 

/***************************************************************

* class DataSet performs basic statistics on a data set of     *

* integers. The data set size must be at least 1 but not more  *

* than 100,000,000. The only screen output is done in          *

* LoadData(std::ifstream &in); (if an error occurs loading     *

* PrintAll(bool table).                                        *

***************************************************************/

class DataSet {

int           *dataset;     //holds the data

int           size;         //size of data in the set

int           limit;        //size of the array

 

public:

double mean();              //returns the mean of dataset

int min();                  //returns the minimum value of dataset

int max();                  //returns the maximum value of dataset

double standev();           //returns the standard deviation of dataset

double median();            //returns the median value of dataset

double variance();          //returns the variance of dataset

int getSize();              //returns the size of dataset

DataSet(int s);             //constructs the dataset array

//PrintAll prints the dataset in either a table=true

//or one column if table =false

void PrintAll(bool table);

 

/* LoadData checks if the file “in” is open and attempts to

load the dataset from the input file. If the file is not

open print “file not open”. If the file contains more data the

limit entered, stop attempting to read and return.

*/

void LoadData(std::ifstream &in);

void sort();

};