Question: Part 1 (0%) The three source files provided for this workshop are process_data.h -- fully implemented, do not modify process_data.cpp -- partially implemented, w9_p1.cpp --

Part 1 (0%)

The three source files provided for this workshop are

  • process_data.h -- fully implemented, do not modify
  • process_data.cpp -- partially implemented,
  • w9_p1.cpp -- already implemented, do not modify

A data file provided for this workshop is

  • data_int.dat -- First 4 bytes (int size) in the file contains the total number of data items. The remaining bytes in the file contain the data-item values, where each data-item is of 4 byte (int size).

The computeAvgFactor and computeVarVactor functions, implemented in process_data.cpp, compute the average-factor and variance-factor from the data supplied in the first parameter. These functions are described as comments in the process_data.cpp file, read carefully and understand. These functions are fully implemented, do not change them.

The ProcessData constructor function, in the file process_data.cpp receives a filename as std::string, opens the file in binary mode and reads the total number of data items (first 4 bytes) followed by the data-item values. Detailed description is included as comment in process_data.cpp, read carefully and understand.

Your first task for part 1 of this workshop is to complete the definition of the constructor in class ProcessData to load the data from the binary file whose name is received as a parameter. See above info about the structure of the file. Do not modify existing code in this function, only add what is missing.

Your second task is to write definition of the operator() function in process_data.cpp. Prototype of this function is in the header file process_data.h. The first parameter of this function receives target-filename to which the data is to be written in binary format. The second parameter is a double reference variable for holding computed average value. The third parameter is double reference variable for holding computed variance value.

  • You compute the average value by calling computeAvgFactor with the following parameters: data, total_items as the size of the array, and again total_items as divisor. The fourth argument is going to be a variable in which the computed average value is to be stored.
  • You compute variance value by calling computeVarFactor with first, second and third arguments same as before, i.e., in the case of computeAvgFactor. The fourth argument is the average value computed by computeAvgFactor and fifth argument is the variable in which the computed variance is to be stored.
  • You open the target data file and write the data (total_items, and data) in the format of the input data file data_int.dat.

w9_p1 Module (supplied)

The tester module has been supplied. Do not modify the existing code!

When doing the workshop, you are encouraged to own tests, focusing on a single implemented feature at the time, until you get all functionality in place.

Sample Output

When the program is started with the command (the input file is provided):

ws data_int.dat data_int_target.dat 

the output should look like the one from the sample_output.txt file.

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 Programming Questions!