Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Module 1 Recommended Implementation Details In this first part of the signature assignment, develop code to write and read a binary file. An array of

Module 1 Recommended Implementation Details
In this first part of the signature assignment, develop code to write and read a binary file. An array of random numbers will be created, and the number of elements and values of each elementwill be written into a binary file. Then, to ensure that all is working well, the array is deleted, a new one is created, and the binary file is read. The first value is the number of elements to read,
which value should control a loop. Then, each value is read and stored in an array element.
Write a function named createArray that creates a dynamic array of 1000 integers. The main function must supply an argument for the length of the array. Use a constant defined with the value of 1000 in the calling code. It is best to define the constant outside the main function.
In createArray, initialize the array with random numbers between 0 and 999 inclusive.Return a pointer to the dynamically created array to the calling code in main.
Write a second function named writeBinary that takes as a parameter a pointer to an integer array and a second parameter, which is the arrays length. Open a binary output file named binary.dat as output and write to it an integer indicating the array's length (the value of the parameter). Then, in a loop, write each element in the array to the file and close the file. Be sureto use a reinterpret_cast to convert the location of each integer to a constant character pointer. Write a third function named readBinary that opens the binary file binary.dat file for input. Its only function parameter should reference an integer in the main function that will store
the length of the returned arraythe length must be read from the file, not passed as a parameter. Read the first value from the binary file, which is an integer representing the length of the new array to create; use the address of the reference parameter as the target of a reinterpret_cast. Next, create a new dynamic integer array using the length value for the size. In a loop, read each number from the binary file and save the value in the array. Return the
pointer to the array from the function.
In the main function, call createArray, passing the array's length (use the defined
constant). This function will return a pointer to the array, which should be saved in a local variable. Call the writeBinary function, passing the pointer to the array as the first argumentand the length as a second argument. After writeBinary returns, delete the array created in the first function and set its pointer to nullptr.
Define a local integer variable for an arrays length (do not use the defined constant) and an integer pointer for the array itself. Call the readBinary function, passing a reference to the variable for the array length. The function will return a pointer to a new array, which should be saved, and the length variable will be updated. Write a loop to iterate over each value in the array and print out its value separated by a space. Delete the dynamic array and terminate the program.
Use these function headers:
int* createArray(int length)
int* readBinary(int& length)
void writeBinary(int* values, int length)
Example output:
3838867779157933353864926494213622769059763926...
...
3085932781975556727744450325997283412127382421

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

Are assessments of candidate attractiveness relevant? Discuss.

Answered: 1 week ago