Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help with this c++ program - Pointers - Pointers returned by functions - Pointers passed to functions You will find the instruction file

i need help with this c++ program
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
- Pointers - Pointers returned by functions - Pointers passed to functions You will find the instruction file along with any additional files on blackboard. In this category of lab activity students are expected to write a complete program during the lab and submit the compiling program on blackboard before the end of the lab session. The instructor will give a brief description of the assignment and provides limited help throughout the lab. Students can use the textbook, class notes or sample programs to complete the assignment, but are PROHIBITED from collaborating with one another. You are asked to write the functions whose prototypes and descriptions are given below: int * makeList ( string, int) ; This function receives the name of a file and the number of values in that file. It will locally and dynamically allocate an array of integers and populates it via the data in the file. Notice the number of values will be the size of this local and dynamic array. It will return the populated dynamic array. int * maxValuePtr ( int [1, int) ; This function receives an integer array, along with its size. It will return a pointer to the element of the array with the maximum value. void displayArray ( int *, int); This function receives an integer pointer/array, along with its size. It will simply display its elements on the screen. Here is the list of tasks to do in exact order they appear below: - Prompt the user for the name of the file. The file uploaded for your convenience is called SP23 Lab6.txt. - Prompt the user for numbers of values stored in this file. The uploaded input file contains 400 integers. - Call the function makeList to read the input file and dynamically allocate and populate a local integer array by the values read from this file. This function returns the populated dynamic array. Is this a safe return? - Pass this dynamic array to your maxValueptr function and have it return a pointer to its largest value. Store this maximum value in a proper variable. Is this a safe pointer return? Discuss this with the instructor. Make sure you understand the point we are making here. - Zero out all the values of this newly allocated array. - Our plan is to use this new array as a tally array for the values in the file. So go ahead and tally the values. Remember the tally process: read the element, use it as an index in the tally array, and update the count which is the content of the index matching the value to be counted. - In order to find the most frequent value, pass your tally array to the maxvalueptr function. Notice what we get out of this specific function is a pointer to the location that contains the highest value. Since the underlying array is a tally array, we need to know the index, but what we get out of this function is the address. See how you can use address arithmetic to get the index of an array element out of its address. Display both the actual most frequent value along with its number of occurrences on the screen. NOTE THAT YOU MUST IMPLEMENT THIS TASK EXACTLY HOW IT IS DESCRIBED HERE TO BE GRANTED CREDIT. - Let's take advantage of our work so far in this assignment and carry out finding the minimum value of our data via using the tally array. See if you find the following process reasonable attempt to find the minimum value: Set up a loop to start iterating from the beginning of the tally array, the first nonzero element resides in the index which is exactly the minimum value, Right? Report your finding on the screen. - Next, prompt the user for a value in the range min-max inclusive. You must validate user's input. - Our plan for this section is to make a list (an array) of all the values that are less than or equal to the user's input. But we would like to make sure that the size of the array is EXACTLY the size of the values that match the above condition. One way of doing this is to use our tally array to get the count of such values, next we need to dynamically allocate an array of that size. You must be careful about determining the size of such data, as if we have duplicates of the target value, we need to take that number of duplicates into account. - To populate this array we can either use the tally array OR use the original array. The content of this array must be all the values less that or equal to the value inputted by the user. Important Note: if we use the tally array, the list would be a sorted one, and if we use the original array, it won't be. Using the original array is the simpler way, but using the tally array is more efficient. You are free to choose either. - Display your interaction with the user and then the content of the dynamic arrays and your findings. The sample run given here excludes the content of tally array for sake of brevity. It also contains both versions of the last dynamic array, the one based on the tally array and then one based on the original array. Remember you should use only one. The example is for you to see how they are the same and also different in their order. Here is a sample run of this code for your reference: Please enter the name of the input file: 5P23_Lab6.txt Enter the nuber of vatues stored in this file: 400 The max value in the file is: 249 The Tatly Resutt: 7. Omitted for brevity The most frequent value is: 13 The number of its occurrences is: 6 The mininum value on the list is: 10 Please enter a value in the range 10-249: 40 The array populated using the tally array: The array populated using the original array: - Make sure you submit a program that compiles. An incomplete program that compiles could possibly carn partial points, a non-compiling program will be considered void. - This is an individual work, you may ask the instructor for some help. However you should not interact with fellow students

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

Students also viewed these Databases questions

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago

Question

=+ c. a company president deciding whether to open a new factory

Answered: 1 week ago