This two-part lab deals with reading numerical data from a binary file named NBdata.bin. The main reason for using binary rather than text files is that they require less memory and are much faster. The program will read the integer data in binary form and calculate two related quantities: the odd geometric, and the even harmonic means. Important: (1) Although the text file is much longer, the program will only read a fixed number of records, N to provide variability for testing purposes. (2) It may be easier to read all N elements from the file and store them into an integer array since the program will need to access them later. (3) The file will contain only positive integers. (4) Prompt the user for this fixed number of elements N to read from the file. This number will be between 3 and 100. (Your program does not need to check the input). Use the format below. Enter N: [...] Part I: Open the binary file named NBdata.bin for readig. The file is stored internally. Prompt the user how many numbers (N) to read. Read all these N elements from the file and output the odd geometric mean from those elements. The odd mean will only use the numbers that are odd. For example if N = 5 and the file has the elements 12 3 4 8 1 then the program will only use the odd numbers 3 and 1. If there are no odd numbers the answer will be 0. (See formula in the attached file) Use the format below. 50 Points Odd G Mean = [...] Part II: Update the code from part II and also output the even harmonic mean of the N elements. This even means will only use the even numbers. For example, if N = 5 and the file has the elements 12 3 4 8 1 then the program will only use the even numbers 12, 4, and 8. If there are no even numbers the answer will be 0. (See the formula in the attached file) Use the format below. 50 Points Even H Mean = [...] Notes: (1) The […] should be replaced with the correct values based on the input entered by the user or respective output. (2) Although the file has only integers both mean values will likely be decimals so declare them as double variables. (3) Do not forget to close the file at the end of the program.
This two-part lab deals with reading numerical data from a binary file named NBdata.bin. The main reason for using binary rather than text files is that they require less memory and are much faster. The program will read the integer data in binary form and calculate two related quantities: the odd geometric, and the even harmonic means.
Important: (1) Although the text file is much longer, the program will only read a fixed number of records, N to provide variability for testing purposes. (2) It may be easier to read all N elements from the file and store them into an integer array since the program will need to access them later. (3) The file will contain only positive integers. (4) Prompt the user for this fixed number of elements N to read from the file. This number will be between 3 and 100. (Your program does not need to check the input). Use the format below.
Enter N: [...]
Part I: Open the binary file named NBdata.bin for readig. The file is stored internally. Prompt the user how many numbers (N) to read. Read all these N elements from the file and output the odd geometric mean from those elements. The odd mean will only use the numbers that are odd. For example if N = 5 and the file has the elements 12 3 4 8 1 then the program will only use the odd numbers 3 and 1. If there are no odd numbers the answer will be 0. (See formula in the attached file) Use the format below. 50 Points
Odd G Mean = [...]
Part II: Update the code from part II and also output the even harmonic mean of the N elements. This even means will only use the even numbers. For example, if N = 5 and the file has the elements 12 3 4 8 1 then the program will only use the even numbers 12, 4, and 8. If there are no even numbers the answer will be 0. (See the formula in the attached file) Use the format below. 50 Points
Even H Mean = [...]
Notes:
(1) The […] should be replaced with the correct values based on the input entered by the user or respective output.
(2) Although the file has only integers both mean values will likely be decimals so declare them as double variables.
(3) Do not forget to close the file at the end of the program.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images