Question: C++ Skills Practiced (Learning Goals) Problem solving and debugging. Function decomposition. C++ arrays. Sorting. Filestreams. Documentation of program. A data file contains a series of

C++ Skills Practiced (Learning Goals)

Problem solving and debugging.

Function decomposition.

C++ arrays.

Sorting.

Filestreams.

Documentation of program.

A data file contains a series of integer values (positive, negative, and zero). The maximum number of values in the file that are greater than or equal to 0 will be 30. Please note, there may be more than 30 numbers in the file. Each value will be separated by at least one blank space and the last value in the file will be followed by a linefeed.

Create a C++ program (using functions to modularize the code) that will

interactively prompt the user for the name of the input file and read it

open the file for reading, using a C++ filestream

read the integer values from the file

count and sum the negative values, compute the average if possible

store the other values (>=0) in an array, counting them as they are read

interactively prompt the user for the name of the output file and read it

open the file for writing using a C++ filestream

write the following to the output file you created - leave at least one blank line between each set of outputs and clearly label all output

-if there were no negative values in the file, display an appropriate message

-if there were negative values in the file display

-the sum and count of the negative values

-the average of the negative values (set precision to 5 decimal places)

-if there were no values >= 0 in the file, display an appropriate message

-if there are values >= 0 stored in the array

-use bubblesort to arrange the values in the array into ascending order

-list the sorted values one per line, right justified, values may have up to 7 digits

-display the number of values stored in the array, the average of the values, the variance and the standard deviation of the values (set precision to 5 decimal places)

-list all the values in the array that are prime (one per line, right justified) or an appropriate message if there are none

-list each nonprime numbers greater than 0 found in the array along with how many factors each has (arrange in 2 columns - right justified) or an appropriate message if there are none

Definitions and Formulas

A prime number is a positive, nonzero integer that has exactly 2 different factors.

if n=# values stored in the array and datai represents the ith value in the array,

average = (data1 + data2 + ... + datan) / n

variance = [(data1-average)2 + (data2-average)2 + ... + (datan-average)2] / (n-1)

standard_deviation = sqrt(variance)

Assumptions

The input file will not be empty. Each line in the file will be terminated by a linefeed (' ').

All values in the file will be integers and they will be separated by whitespace.

Maximum number of values in the file greater than or equal to 0 will be 30.

Maximum number of columns needed to display an integer will be 7.

All values in the file could be negative.

All values in the file could be greater than or equal to 0.

If the file contains values greater than or equal to 0, there will be at least 2 of them (so that variance can be computed).

Requirements

The program MUST make use of functions (at least 4 meaningful functions in addition to main).

The program MUST PASS PARAMETERS to communicate values. No global variables are allowed.

No goto statements may be used.

Program must make use of filestream variables to represent the input and output files. The input file may only be read one time.

The program must prompt for the name of the input file first. Then prompt for the name of the output file.

Data values read from the input file and factor counts must be displayed as integers. Averages, variance, and standard deviation must be displayed with 5 digits to the right of the decimal.

Program must include preprocessor directives for all header files used.

Program must use a static array (do not use a variable for the size of the array).

Test your program adequately!

Documentation When the program compiles and runs correctly, add the following documentation (comments) to your source file (.cpp file).

When a named constant and/or major variable is declared, provide a meaningful description of what it represents in the program.

For each function, clearly state what will be passed into the function and what will be passed out or returned by the function. Document important local variables Here is a sample session. DO NOT USE ALGORITHM, SSTREAM, LIMIT IN YOUR CODE. C++ Skills Practiced (Learning Goals) Problem solving and debugging. Function decomposition. C++

Sample terminal session: keys] data 17 35 B 12 4 0 23 428 34 144 keys) g aseign04. opp keys] -/a out Pl. enter the name of the input file: dat 4four the name of the output file: Pl. lts4f N keys] more results four Negative Number Data 49 -16.33333 Numbers 0 Data Positive in File 12 35 144 428 Average 85.37500 119 5.98214 3ti d 145.58840 Prime Numbers Nonprime Numbers and Factor Count. 12 35 144 15 428 data 42 keys] Please enter the name of the input file: data4four2 Pl. nter the name of the output file: results2 keys] lte2 Negative Number Data fil. gat. Numbers 0 Data Positive in File 42 Average: 19.50000 333. EE667 3ti d 6655 Numb Nonprime Numbers and Factor Count. 42

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!