Question: CS 1050 Pre-lab9 ********** CODE MUST BE IN C ************** Directions: Complete the following pre-lab assignment before the upcoming lab. It will help you in
CS 1050 Pre-lab9
**********CODE MUST BE IN C ************** Directions: Complete the following pre-lab assignment before the upcoming lab. It will help you in completing the lab assignment. If you have any questions or have problem in completing the pre-lab ask TAs for help during TA office hours or schedule an appointment. Purpose: 1. Use and extend the concepts learned from the previous labs. 2. Use pointer notation. NOTE: The only time you should use array notation in this prelab (and in the lab) is when you are creating the pointer to store a list of numbers. That is, this should be the only time you use array notation:
#define MAX 50 int array[MAX]; int *pointer = array;
Also This prelab is the same as last weeks pre-lab, except you are now getting the size of the array
from the function get_size (which has no return type) and finding the max of the values inside of the pointer.
Description: Implement following functions for the prelab assignment. void get_size(int *): This function takes in an integer pointer from main, but does not have a return type. The function will read in the size of the pointer, but you will not type return size; or something similar. Since the variable being taken into the parameters of the function is a pointer, it is being passed by reference so anything that happens to the variable in get_size also happens to it in main which is different from how we normally pass a variable (pass by value). That is, when you are calling get_size the code should look something like this: int size; get_size(&size); By including the & before the size variable, we are referencing the location that size is stored at. I.e. we are pointing to that location in memory. To reiterate, the above code will pass size by reference which means anything that we do to size in get_size will happen to it where the function is called, which in this case is main. int check_size(int): This function takes an integer number and checks if the number is between 1-50 or not. If it is, it returns 1, otherwise returns 0. void initialize_pointerArray(int *, int ): This function takes an integer pointer and the input size and stores random numbers using the integer pointer. The random numbers range from the value 1 to 10 only. void print_pointerArray(int *, int): This function takes an integer pointer and the input size and prints out random numbers using the integer pointer. int find_max(int *, int): This function takes in an integer pointer and the input size and returns the largest value stored in the pointer. main(): First read the input size from the user by calling get_size, performing an error check using the check_size function. Call functions initialize_array and print_array to store and print the random numbers. Then, call find_max to find the largest value stored in the pointer. Display the results as shown in the sample output below. Sample output Characters in bold are input from the user. $ ./a.out Enter the size of the input: -12 Invalid input enter the size of the array again: 123 Invalid input enter the size of the array again: 0 Invalid input enter the size of the array again: 6 Input array 1 5 9 10 3 1 The largest value in the pointer is: 10 $ ./a.out Enter the size of the input: -1 Invalid input enter the size of the array again: 0 Invalid input enter the size of the array again: 0 Invalid input enter the size of the array again: 0 Invalid input enter the size of the array again: 101 Invalid input enter the size of the array again: 8 Input array 5 5 5 3 9 1 0 1 The largest value in the pointer is: 9 $ ./a.out Enter the size of the input: 3 Input array 5 4 7 The largest value in the pointer is: 9
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
